Fix warnings from shellcheck shell linter
#!/bin/sh
-
-# global variables
-
-SMACK=n
-DEBUG=n
+set -eu
# -------------------------------------------
-log_info() { echo "$0[$$]: $@" >&2; }
-log_error() { echo "$0[$$]: ERROR $@" >&2; }
+log_info() { echo "$0[$$]: $*" >&2; }
+log_error() { echo "$0[$$]: ERROR $*" >&2; }
do_mount_fs() {
- log_info "mounting FS: $@"
+ log_info "mounting FS: $*"
[[ -e /proc/filesystems ]] && { grep -q "$1" /proc/filesystems || { log_error "Unknown filesystem"; return 1; } }
[[ -d "$2" ]] || mkdir -p "$2"
[[ -e /proc/mounts ]] && { grep -q -e "^$1 $2 $1" /proc/mounts && { log_info "$2 ($1) already mounted"; return 0; } }
@@ -26,10 +22,10 @@ bail_out() {
}
get_ostree_sysroot() {
- for opt in `cat /proc/cmdline`; do
- arg=`echo $opt | cut -d'=' -f1`
- if [ $arg == "ostree_root" ]; then
- echo $opt | cut -d'=' -f2-
+ for opt in $(cat /proc/cmdline); do
+ arg=$(echo "$opt" | cut -d'=' -f1)
+ if [ "$arg" == "ostree_root" ]; then
+ echo "$opt" | cut -d'=' -f2-
return
fi
done
@@ -38,7 +34,7 @@ get_ostree_sysroot() {
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/ostree
-log_info "starting initrd script"
+log_info "Starting OSTree initrd script"
do_mount_fs proc /proc
do_mount_fs sysfs /sys
@@ -50,8 +46,6 @@ do_mount_fs tmpfs /run
# check if smack is active (and if so, mount smackfs)
grep -q smackfs /proc/filesystems && {
- SMACK=y
-
do_mount_fs smackfs /sys/fs/smackfs
# adjust current label and network label
@@ -69,7 +63,7 @@ ostree-prepare-root /sysroot
cd /sysroot
for x in dev proc; do
log_info "Moving /$x to new rootfs"
- mount -o move /$x $x
+ mount -o move "/$x" "$x"
done
# switch to new rootfs
