more shellcheck fixes

This commit is contained in:
illiliti 2020-07-03 18:49:09 +03:00
parent ef1165de3c
commit dd01d03775
6 changed files with 56 additions and 22 deletions

View File

@ -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

View File

@ -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()
{

View File

@ -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

View File

@ -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
init
View File

@ -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 \

View File

@ -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" \
cp "${_dir}/${hook}/${hook}.${_file}" \
"${tmpdir}/usr/share/tinyramfs/hooks/${hook##*/}"
fi || panic
} || panic
done
break
done || panic "could not run $hook"
done || panic "could not run $hook hook"
}
copy_modules()