Skip to content

Commit

Permalink
POSIX compliance: (most) shell scripts converted to generic shell
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
geopic authored and awesomekling committed Nov 3, 2019
1 parent 2cc5f3a commit 704f48d
Show file tree
Hide file tree
Showing 43 changed files with 152 additions and 144 deletions.
48 changes: 24 additions & 24 deletions Kernel/build-gpt-image-grub.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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:-701} status=none || die "couldn't create disk image"
dd if=/dev/zero of=_disk_image bs=1M count="${DISK_SIZE:-701}" 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 gpt mkpart BIOSBOOT ext3 1MiB 8MiB mkpart OS ext2 8MiB 700MiB set 1 bios_grub || die "couldn't partition disk"
printf "creating partition table... "
parted -s "${dev}" mklabel gpt mkpart BIOSBOOT ext3 1MiB 8MiB mkpart OS ext2 8MiB 700MiB set 1 bios_grub || die "couldn't partition disk"
echo "done"

echo -n "destroying old filesystem... "
dd if=/dev/zero of=${dev}p2 bs=1M count=1 status=none || die "couldn't destroy old filesystem"
printf "destroying old filesystem... "
dd if=/dev/zero of="${dev}"p2 bs=1M count=1 status=none || die "couldn't destroy old filesystem"
echo "done"

echo -n "creating new filesystem... "
mke2fs -q ${dev}p2 || die "couldn't create filesystem"
printf "creating new filesystem... "
mke2fs -q "${dev}"p2 || die "couldn't create filesystem"
echo "done"

echo -n "mounting filesystem... "
printf "mounting filesystem... "
mkdir -p mnt
mount ${dev}p2 mnt/ || die "couldn't mount filesystem"
mount "${dev}"p2 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 part_gpt" ${dev}
$grub --boot-directory=mnt/boot --target=i386-pc --modules="ext2 part_msdos part_gpt ${dev}"

if [ -d mnt/boot/grub2 ]; then
cp grub_gpt.cfg mnt/boot/grub2/grub.cfg
Expand All @@ -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"
48 changes: 24 additions & 24 deletions Kernel/build-image-grub.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -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"
16 changes: 8 additions & 8 deletions Kernel/build-image-qemu.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#!/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

echo "setting up disk image..."
qemu-img create _disk_image ${DISK_SIZE:-500}m || die "couldn't create disk image"
chown $build_user:$build_group _disk_image || die "couldn't adjust permissions on disk image"
qemu-img create _disk_image "${DISK_SIZE:-500}"m || die "couldn't create disk image"
chown "$build_user":"$build_group" _disk_image || die "couldn't adjust permissions on disk image"
echo "done"

echo -n "creating new filesystem... "
printf "creating new filesystem... "
mke2fs -q -I 128 _disk_image || die "couldn't create filesystem"
echo "done"

echo -n "mounting filesystem... "
printf "mounting filesystem... "
mkdir -p mnt
mount _disk_image mnt/ || die "couldn't mount filesystem"
echo "done"

cleanup() {
if [ -d mnt ]; then
echo -n "unmounting filesystem... "
printf "unmounting filesystem... "
umount mnt || ( sleep 1 && sync && umount mnt )
rm -rf mnt
echo "done"
Expand Down
24 changes: 13 additions & 11 deletions Kernel/build-root-filesystem.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#!/bin/bash
#!/bin/sh

set -e

# HACK: Get rid of old "qs" binaries still lying around from before it was renamed.
rm -f ../Userland/qs

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

echo -n "creating initial filesystem structure... "
mkdir -p mnt/{bin,etc,proc,mnt,tmp}
printf "creating initial filesystem structure... "
for dir in bin etc proc mnt tmp; do
mkdir -p mnt/$dir
done
chmod 1777 mnt/tmp
echo "done"

echo -n "setting up device nodes... "
printf "setting up device nodes... "
mkdir -p mnt/dev
mkdir -p mnt/dev/pts
mknod -m 666 mnt/dev/fb0 b 29 0
Expand Down Expand Up @@ -49,26 +51,26 @@ ln -s /proc/self/fd/1 mnt/dev/stdout
ln -s /proc/self/fd/2 mnt/dev/stderr
echo "done"

echo -n "installing base system... "
printf "installing base system... "
cp -R ../Base/* mnt/
cp -R ../Root/* mnt/
cp kernel.map mnt/
echo "done"

echo -n "installing users... "
printf "installing users... "
mkdir -p mnt/home/anon
mkdir -p mnt/home/nona
cp ../ReadMe.md mnt/home/anon/
chown -R 100:100 mnt/home/anon
chown -R 200:200 mnt/home/nona
echo "done"

echo -n "installing userland... "
printf "installing userland... "
find ../Userland/ -type f -executable -exec cp {} mnt/bin/ \;
chmod 4755 mnt/bin/su
echo "done"

echo -n "installing applications... "
printf "installing applications... "
cp ../Applications/About/About mnt/bin/About
cp ../Applications/Downloader/Downloader mnt/bin/Downloader
cp ../Applications/FileManager/FileManager mnt/bin/FileManager
Expand Down Expand Up @@ -110,7 +112,7 @@ cp ../Servers/TelnetServer/TelnetServer mnt/bin/TelnetServer
cp ../Shell/Shell mnt/bin/Shell
echo "done"

echo -n "installing shortcuts... "
printf "installing shortcuts... "
ln -s Downloader mnt/bin/dl
ln -s FileManager mnt/bin/fm
ln -s HelloWorld mnt/bin/hw
Expand Down
4 changes: 2 additions & 2 deletions Kernel/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

mkdir -p ../Root/usr/include/Kernel/
cp *.h ../Root/usr/include/Kernel/
cp ./*.h ../Root/usr/include/Kernel/
2 changes: 1 addition & 1 deletion Kernel/makeall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
set -e

# Get user and group details for setting qemu disk image ownership
Expand Down
2 changes: 1 addition & 1 deletion Kernel/sync.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
#!/bin/sh

./build-image-qemu.sh
4 changes: 2 additions & 2 deletions Libraries/LibC/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

set -e
SERENITY_ROOT=../../
Expand All @@ -8,7 +8,7 @@ mkdir -p $SERENITY_ROOT/Root/usr/include/bits/
mkdir -p $SERENITY_ROOT/Root/usr/include/netinet/
mkdir -p $SERENITY_ROOT/Root/usr/include/arpa/
mkdir -p $SERENITY_ROOT/Root/usr/lib/
cp *.h $SERENITY_ROOT/Root/usr/include/
cp ./*.h $SERENITY_ROOT/Root/usr/include/
cp sys/*.h $SERENITY_ROOT/Root/usr/include/sys/
cp bits/*.h $SERENITY_ROOT/Root/usr/include/bits/
cp arpa/*.h $SERENITY_ROOT/Root/usr/include/arpa/
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibCore/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -e
SERENITY_ROOT=../../

mkdir -p $SERENITY_ROOT/Root/usr/include/LibCore/
cp *.h $SERENITY_ROOT/Root/usr/include/LibCore/
cp ./*.h $SERENITY_ROOT/Root/usr/include/LibCore/
cp libcore.a $SERENITY_ROOT/Root/usr/lib/
4 changes: 2 additions & 2 deletions Libraries/LibDraw/install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/bin/sh

set -e
SERENITY_ROOT=../../

mkdir -p $SERENITY_ROOT/Root/usr/include/LibDraw/
cp *.h $SERENITY_ROOT/Root/usr/include/LibDraw/
cp ./*.h $SERENITY_ROOT/Root/usr/include/LibDraw/
cp libdraw.a $SERENITY_ROOT/Root/usr/lib/
4 changes: 2 additions & 2 deletions Libraries/LibGUI/install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/bin/sh

set -e
SERENITY_ROOT=../../

mkdir -p $SERENITY_ROOT/Root/usr/include/LibGUI/
cp *.h $SERENITY_ROOT/Root/usr/include/LibGUI/
cp ./*.h $SERENITY_ROOT/Root/usr/include/LibGUI/
cp libgui.a $SERENITY_ROOT/Root/usr/lib/
Loading

0 comments on commit 704f48d

Please sign in to comment.