diff options
author | George Pickering <29524044+tedjenkins@users.noreply.github.com> | 2019-11-02 16:34:54 +0000 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-03 09:26:22 +0100 |
commit | 704f48d7f3a1a88047a64b4e2939878d6d4fafb8 (patch) | |
tree | 5fc1e15abb6a5e828217f12aa926b1ca9b35991f /Kernel/build-image-grub.sh | |
parent | 2cc5f3a93f84ad0004b99fa22d4b130dfb38e6ba (diff) | |
download | serenity-704f48d7f3a1a88047a64b4e2939878d6d4fafb8.zip |
POSIX compliance: (most) shell scripts converted to generic shell
Ports/.port_include.sh, Toolchain/BuildIt.sh, Toolchain/UseIt.sh
have been left largely untouched due to use of Bash-exclusive
functions and variables such as $BASH_SOURCE, pushd and popd.
Diffstat (limited to 'Kernel/build-image-grub.sh')
-rwxr-xr-x | Kernel/build-image-grub.sh | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/Kernel/build-image-grub.sh b/Kernel/build-image-grub.sh index dc4ca60966..7d79c17ff1 100755 --- a/Kernel/build-image-grub.sh +++ b/Kernel/build-image-grub.sh @@ -1,19 +1,19 @@ -#!/bin/bash +#!/bin/sh set -e die() { - echo "die: $@" + echo "die: $*" exit 1 } -if [ $(id -u) != 0 ]; then +if [ "$(id -u)" != 0 ]; then die "this script needs to run as root" fi -grub=$(which grub-install 2>/dev/null) || true -if [[ -z "$grub" ]]; then - grub=$(which grub2-install 2>/dev/null) || true +grub=$(command -v grub-install 2>/dev/null) || true +if [ -z "$grub" ]; then + grub=$(command -v grub2-install 2>/dev/null) || true fi if [ -z "$grub" ]; then echo "can't find a grub-install or grub2-install binary, oh no" @@ -22,58 +22,58 @@ fi echo "using grub-install at ${grub}" echo "setting up disk image..." -dd if=/dev/zero of=_disk_image bs=1M count=${DISK_SIZE:-500} status=none || die "couldn't create disk image" +dd if=/dev/zero of=_disk_image bs=1M count="${DISK_SIZE:-500}" status=none || die "couldn't create disk image" chown 1000:1000 _disk_image || die "couldn't adjust permissions on disk image" echo "done" -echo -n "creating loopback device... " +printf "creating loopback device... " dev=$(losetup --find --partscan --show _disk_image) -if [ -z $dev ]; then +if [ -z "$dev" ]; then die "couldn't mount loopback device" fi echo "loopback device is at ${dev}" cleanup() { if [ -d mnt ]; then - echo -n "unmounting filesystem... " + printf "unmounting filesystem... " umount mnt || ( sleep 1 && sync && umount mnt ) rm -rf mnt echo "done" fi - if [ -e ${dev} ]; then - echo -n "cleaning up loopback device... " - losetup -d ${dev} + if [ -e "${dev}" ]; then + printf "cleaning up loopback device... " + losetup -d "${dev}" echo "done" fi } trap cleanup EXIT -echo -n "creating partition table... " -parted -s ${dev} mklabel msdos mkpart primary ext2 32k 100% -a minimal set 1 boot on || die "couldn't partition disk" +printf "creating partition table... " +parted -s "${dev}" mklabel msdos mkpart primary ext2 32k 100% -a minimal set 1 boot on || die "couldn't partition disk" echo "done" -echo -n "destroying old filesystem... " -dd if=/dev/zero of=${dev}p1 bs=1M count=1 status=none || die "couldn't destroy old filesystem" +printf "destroying old filesystem... " +dd if=/dev/zero of="${dev}"p1 bs=1M count=1 status=none || die "couldn't destroy old filesystem" echo "done" -echo -n "creating new filesystem... " -mke2fs -q -I 128 ${dev}p1 || die "couldn't create filesystem" +printf "creating new filesystem... " +mke2fs -q -I 128 "${dev}"p1 || die "couldn't create filesystem" echo "done" -echo -n "mounting filesystem... " +printf "mounting filesystem... " mkdir -p mnt -mount ${dev}p1 mnt/ || die "couldn't mount filesystem" +mount "${dev}"p1 mnt/ || die "couldn't mount filesystem" echo "done" ./build-root-filesystem.sh -echo -n "creating /boot... " +printf "creating /boot... " mkdir -p mnt/boot echo "done" echo "installing grub using $grub..." -$grub --boot-directory=mnt/boot --target=i386-pc --modules="ext2 part_msdos" ${dev} +$grub --boot-directory=mnt/boot --target=i386-pc --modules="ext2 part_msdos ${dev}" if [ -d mnt/boot/grub2 ]; then cp grub.cfg mnt/boot/grub2/grub.cfg @@ -82,6 +82,6 @@ else fi echo "done" -echo -n "installing kernel in /boot... " +printf "installing kernel in /boot... " cp kernel mnt/boot echo "done" |