commit: 72552b46f8b3e485f1eb54e2f8ccb35714f1730c
parent edeed4aa38edcb250230ba1e222dd2299d3a72ea
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 31 Mar 2022 18:28:03 +0200
init: fix issues found via shellcheck
Diffstat:
M | init | 47 | ++++++++++++++++++++++++++++------------------- |
1 file changed, 28 insertions(+), 19 deletions(-)
diff --git a/init b/init
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright 2017-2018 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
+# Copyright 2017-2022 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
# Distributed under the terms of the ISC license
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
@@ -8,21 +8,22 @@ export init=/sbin/init newroot=/newroot root=zroot/ROOT/gentoo sh=/bin/sh level=
rescueshell() {
export PS1='rsh:$(tty | cut -c6-):$PWD # '
- if which setsid $>/dev/null; then
- setsid $sh -i -0<$console 1>$console 2>&1
+ if command -v setsid >/dev/null; then
+ # shellcheck disable=SC2094
+ setsid "$sh" -i -0<"$console" 1>"$console" 2>&1
else
- $sh -i 0<$console 1>$console 2>&1
+ # shellcheck disable=SC2094
+ "$sh" -i 0<"$console" 1>"$console" 2>&1
fi
}
die() {
- echo -e "$@"
- echo -e "Dropping into a rescueshell..."
+ echo "Dropping into a rescueshell..."
rescueshell || exec $sh -i
}
getdev() {
- echo $(blkid | grep $1 | cut -d: -f1)
+ blkid | grep "$1" | cut -d: -f1
}
set -v
@@ -30,31 +31,39 @@ set -v
umask 0077
mount -t proc proc /proc
mount -t sysfs sysfs /sys
-if grep devtmpfs /proc/filesystems &>/dev/null; then
+if grep -q devtmpfs /proc/filesystems; then
mount -t devtmpfs devtmpfs /dev
else
mount -t tmpfs tmpfs /dev
fi
+# shellcheck disable=SC2013
for arg in $(cat /proc/cmdline); do
case $arg in
- rescue*) export rescue=1;;
- single) export level=2;;
- level*|init*|root*|crypt_root*|sh*|dev_hotplug*) export $arg;;
+ rescue*)
+ export rescue=1
+ ;;
+ single)
+ export level=2
+ ;;
+ level*|init*|root*|crypt_root*|sh*|dev_hotplug*)
+ # shellcheck disable=SC2163
+ export "$arg"
+ ;;
esac
done
+"$dev_hotplug" -s || die
-$dev_hotplug -s || die
-
-echo $(which $dev_hotplug) > /proc/sys/kernel/hotplug
+command -v "$dev_hotplug" > /proc/sys/kernel/hotplug
[ -h /dev/fd ] || ln -fs /proc/self/fd /dev/fd
[ -h /dev/stderr ] || ln -fs /proc/self/stderr /dev/stderr
[ -h /dev/stdin ] || ln -fs /proc/self/stdin /dev/stdin
[ -h /dev/stdout ] || ln -fs /proc/self/stdout /dev/stdout
-: ${console:=/dev/console}
-exec 0<$console 1>$console 2>&1
+: "${console:=/dev/console}"
+# shellcheck disable=SC2094
+exec 0<"$console" 1>"$console" 2>&1
#root=$(getdev $crypt_root)
#[ $root ] || root=/dev/sda2
@@ -68,8 +77,8 @@ cryptsetup open /dev/sda2 cryptrpool || die
zpool import -d /dev/mapper -d /dev -N rpool || die
-mount -t zfs -o rw,zfsutil $root $newroot || die
+mount -t zfs -o rw,zfsutil "$root" "$newroot" || die
-umount -l /{sys,dev,proc}
+for d in /proc /sys /dev; do umount -l "$d"; done
-exec switch_root $newroot ${init:-/sbin/init} $level || die
+exec switch_root "$newroot" "${init:-/sbin/init}" "$level" || die