From dd01d03775970908be870435ec44c822c8645214 Mon Sep 17 00:00:00 2001 From: illiliti Date: Fri, 3 Jul 2020 18:49:09 +0300 Subject: [PATCH] more shellcheck fixes --- hooks/luks/luks | 9 +++++++-- hooks/luks/luks.init | 7 +++++++ hooks/lvm/lvm | 9 +++++++-- hooks/lvm/lvm.init | 9 ++++++++- init | 10 ++++++++++ tinyramfs | 34 +++++++++++++++++----------------- 6 files changed, 56 insertions(+), 22 deletions(-) diff --git a/hooks/luks/luks b/hooks/luks/luks index c9bd3d4..b6fe6dd 100644 --- a/hooks/luks/luks +++ b/hooks/luks/luks @@ -1,4 +1,11 @@ # vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# word splitting is safe by design +# shellcheck disable=2086 # # handle_luks() { @@ -18,8 +25,6 @@ # see https://bugs.archlinux.org/task/56771 [ -e /lib/libgcc_s.so.1 ] && copy_library /lib/libgcc_s.so.1 - # word splitting is safe by design - # shellcheck disable=2086 IFS=,; set -- $luks_opts; unset IFS set -C; for opt; do case "${opt%%=*}" in diff --git a/hooks/luks/luks.init b/hooks/luks/luks.init index 116def3..be494be 100644 --- a/hooks/luks/luks.init +++ b/hooks/luks/luks.init @@ -1,4 +1,11 @@ # vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# word splitting is safe by design +# shellcheck disable=2086,2068 # # unlock_luks() { diff --git a/hooks/lvm/lvm b/hooks/lvm/lvm index 63230a2..5d0cd75 100644 --- a/hooks/lvm/lvm +++ b/hooks/lvm/lvm @@ -1,4 +1,11 @@ # vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# word splitting is safe by design +# shellcheck disable=2086 # # handle_lvm() { @@ -26,8 +33,6 @@ use_lvmetad = 0 }" - # word splitting is safe by design - # shellcheck disable=2086 IFS=,; set -- $lvm_opts; unset IFS for opt; do case "$opt" in diff --git a/hooks/lvm/lvm.init b/hooks/lvm/lvm.init index 583d6f3..89300ef 100644 --- a/hooks/lvm/lvm.init +++ b/hooks/lvm/lvm.init @@ -1,4 +1,11 @@ # vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# word splitting is safe by design +# shellcheck disable=2086,2068 # # trigger_lvm() { @@ -10,7 +17,7 @@ for opt; do case "$opt" in discard=1) lvm_discard="--config=devices{issue_discards=1}" ;; - config=0) : > /etc/lvm/lvm.conf ;; + config=0) : > /etc/lvm/lvm.conf ;; group=*) lvm_group="${opt#*=}" ;; name=*) lvm_name="/${opt#*=}" ;; tag=*) lvm_tag="@${opt#*=}" ;; diff --git a/init b/init index f86f786..4cf3805 100755 --- a/init +++ b/init @@ -2,6 +2,8 @@ # # tiny init # +# false positive +# shellcheck disable=2154 print() { @@ -40,6 +42,8 @@ run_hook() type="$1"; hksdir=/usr/share/tinyramfs/hooks # run hooks if any + # false positive + # shellcheck disable=1090 for hook in $hooks; do [ -f "${hksdir}/${hook}/${hook}.${type}" ] || continue . "${hksdir}/${hook}/${hook}.${type}" @@ -48,6 +52,8 @@ run_hook() prepare_environment() { + # false positive + # shellcheck disable=1091 . /etc/tinyramfs/config export \ @@ -118,6 +124,8 @@ mount_root() "${rorw:--o ro}${root_opts:+,$root_opts}" \ "${root_type:+-t $root_type}" "$device" "/mnt/root" + # word splitting is safe by design + # shellcheck disable=2068 mount $@ || panic "failed to mount root" } @@ -138,6 +146,8 @@ boot_system() # POSIX exec has no -c flag to execute command with empty environment # use 'env -i' to prevent leaking exported variables + # word splitting is safe by design + # shellcheck disable=2068 exec env -i \ TERM=linux \ PATH=/bin:/sbin:/usr/bin:/usr/sbin \ diff --git a/tinyramfs b/tinyramfs index 9b80aa3..164a102 100755 --- a/tinyramfs +++ b/tinyramfs @@ -86,7 +86,7 @@ prepare_environment() # false positive # shellcheck disable=1090 - . "${config:-/etc/tinyramfs/config}" + . "${config:=/etc/tinyramfs/config}" : "${kernel:=$(uname -r)}" : "${moddir:=/lib/modules}" @@ -96,8 +96,8 @@ prepare_environment() mkdir -p "${tmpdir:=${TMPDIR:-/tmp}/tinyramfs.$$}" # false positive - # shellcheck disable=2015,2064 - [ "$debug" = 1 ] && set -x || trap "rm -rf $tmpdir" EXIT INT + # shellcheck disable=2015 + [ "$debug" = 1 ] && set -x || trap 'rm -rf $tmpdir' EXIT INT } prepare_initramfs() @@ -150,18 +150,18 @@ copy_binary() binary=$(command -v "$1") # check if binary exist and builtin + # false positive + # shellcheck disable=2086 case "$binary" in */*) ;; "") panic "$1 does not exist" ;; *) - # word splitting is safe by design - # shellcheck disable=2086 IFS=:; set -- $PATH; unset IFS # assume that `command -v` returned builtin command. # this behavior depends on shell implementation. - # to be independented we simply iterating over PATH + # to be independent we simply iterating over PATH # to find external alternative ( e.g kill => /bin/kill ) for _dir; do [ -x "${_dir}/${binary}" ] || ! continue @@ -249,25 +249,25 @@ copy_hook() { hook="$1" + # false positive + # shellcheck disable=1090 for _dir in "$hksdir" /etc/tinyramfs/hooks /usr/share/tinyramfs/hooks; do [ -f "${_dir}/${hook}/${hook}" ] || ! continue print "running $hook hook"; . "${_dir}/${hook}/${hook}" - if [ -f "${_dir}/${hook}/${hook}.init" ]; then - mkdir -p "${tmpdir}/usr/share/tinyramfs/hooks/${hook##*/}" - cp "${_dir}/${hook}/${hook}.init" \ - "${tmpdir}/usr/share/tinyramfs/hooks/${hook##*/}" - fi + for _file in init init.early; do + [ -f "${_dir}/${hook}/${hook}.${_file}" ] || continue - if [ -f "${_dir}/${hook}/${hook}.init.early" ]; then - mkdir -p "${tmpdir}/usr/share/tinyramfs/hooks/${hook##*/}" - cp "${_dir}/${hook}/${hook}.init.early" \ - "${tmpdir}/usr/share/tinyramfs/hooks/${hook##*/}" - fi || panic + { + mkdir -p "${tmpdir}/usr/share/tinyramfs/hooks/${hook##*/}" + cp "${_dir}/${hook}/${hook}.${_file}" \ + "${tmpdir}/usr/share/tinyramfs/hooks/${hook##*/}" + } || panic + done break - done || panic "could not run $hook" + done || panic "could not run $hook hook" } copy_modules()