d/zfsutils.zfs.init derivatives: shellcheck, fix header

Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12042
This commit is contained in:
наб 2021-05-16 16:18:30 +02:00 committed by Brian Behlendorf
parent 9627bdc697
commit adc851d9f8
5 changed files with 39 additions and 61 deletions

View File

@ -26,10 +26,8 @@
# #
# Released under the 2-clause BSD license. # Released under the 2-clause BSD license.
# #
# The original script that acted as a template for this script came from # This script is based on debian/zfsutils.zfs.init from the
# the Debian GNU/Linux kFreeBSD ZFS packages (which did not include a # Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# licensing stansa) in the commit dated Mar 24, 2011:
# https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a
# Source the common init script # Source the common init script
. @sysconfdir@/zfs/zfs-functions . @sysconfdir@/zfs/zfs-functions
@ -56,16 +54,13 @@ do_verbatim_import()
# Support function to get a list of all pools, separated with ';' # Support function to get a list of all pools, separated with ';'
find_pools() find_pools()
{ {
local CMD="$*"
local pools local pools
pools=$($CMD 2> /dev/null | \ pools=$("$@" 2> /dev/null | \
grep -E "pool:|^[a-zA-Z0-9]" | \ grep -E "pool:|^[a-zA-Z0-9]" | \
sed 's@.*: @@' | \ sed 's@.*: @@' | \
sort | \ sort | \
while read pool; do \ tr '\n' ';')
echo -n "$pool;"
done)
echo "${pools%%;}" # Return without the last ';'. echo "${pools%%;}" # Return without the last ';'.
} }
@ -80,7 +75,7 @@ do_import_all_visible()
[ -n "$init" ] && rm -f /etc/dfs/sharetab [ -n "$init" ] && rm -f /etc/dfs/sharetab
# Just simplify code later on. # Just simplify code later on.
if [ -n "$USE_DISK_BY_ID" -a "$USE_DISK_BY_ID" != 'yes' ] if [ -n "$USE_DISK_BY_ID" ] && [ "$USE_DISK_BY_ID" != 'yes' ]
then then
# It's something, but not 'yes' so it's no good to us. # It's something, but not 'yes' so it's no good to us.
unset USE_DISK_BY_ID unset USE_DISK_BY_ID
@ -153,7 +148,7 @@ do_import_all_visible()
# to something we can use later with the real import(s). We want to # to something we can use later with the real import(s). We want to
# make sure we find all by* dirs, BUT by-vdev should be first (if it # make sure we find all by* dirs, BUT by-vdev should be first (if it
# exists). # exists).
if [ -n "$USE_DISK_BY_ID" -a -z "$ZPOOL_IMPORT_PATH" ] if [ -n "$USE_DISK_BY_ID" ] && [ -z "$ZPOOL_IMPORT_PATH" ]
then then
local dirs local dirs
dirs="$(for dir in $(echo /dev/disk/by-*) dirs="$(for dir in $(echo /dev/disk/by-*)
@ -231,7 +226,7 @@ do_import_all_visible()
# using the cache file soon and that might succeed. # using the cache file soon and that might succeed.
[ ! -f "$ZPOOL_CACHE" ] && zfs_log_end_msg "$RET" [ ! -f "$ZPOOL_CACHE" ] && zfs_log_end_msg "$RET"
if [ "$r" -gt 0 -a -f "$ZPOOL_CACHE" ] if [ "$r" -gt 0 ] && [ -f "$ZPOOL_CACHE" ]
then then
# Failed to import without a cache file. Try WITH... # Failed to import without a cache file. Try WITH...
if [ -z "$init" ] && check_boolean "$VERBOSE_MOUNT" if [ -z "$init" ] && check_boolean "$VERBOSE_MOUNT"
@ -254,7 +249,7 @@ do_import_all_visible()
[ -n "$init" ] && zfs_log_end_msg "$RET" [ -n "$init" ] && zfs_log_end_msg "$RET"
IFS="$OLD_IFS" IFS="$OLD_IFS"
[ -n "$already_imported" -a -z "$available_pools" ] && return 0 [ -n "$already_imported" ] && [ -z "$available_pools" ] && return 0
return "$RET" return "$RET"
} }

View File

@ -23,10 +23,8 @@
# #
# Released under the 2-clause BSD license. # Released under the 2-clause BSD license.
# #
# The original script that acted as a template for this script came from # This script is based on debian/zfsutils.zfs.init from the
# the Debian GNU/Linux kFreeBSD ZFS packages (which did not include a # Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# licensing stansa) in the commit dated Mar 24, 2011:
# https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a
# Source the common init script # Source the common init script
. @sysconfdir@/zfs/zfs-functions . @sysconfdir@/zfs/zfs-functions
@ -34,9 +32,8 @@
# ---------------------------------------------------- # ----------------------------------------------------
chkroot() { chkroot() {
while read line; do while read -r _ mp _; do
set -- $line if [ "$mp" = "/" ]; then
if [ "$2" = "/" ]; then
return 0 return 0
fi fi
done < /proc/self/mounts done < /proc/self/mounts
@ -65,7 +62,7 @@ do_depend()
# Mount all datasets/filesystems # Mount all datasets/filesystems
do_mount() do_mount()
{ {
local verbose overlay i mntpt val local verbose overlay i mntpt
check_boolean "$VERBOSE_MOUNT" && verbose=v check_boolean "$VERBOSE_MOUNT" && verbose=v
check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O
@ -83,7 +80,7 @@ do_mount()
read_mtab "^/dev/(zd|zvol)" read_mtab "^/dev/(zd|zvol)"
read_fstab "^/dev/(zd|zvol)" read_fstab "^/dev/(zd|zvol)"
i=0; var=$(eval echo FSTAB_$i) i=0; var=$(eval echo "FSTAB_$i")
while [ -n "$(eval echo "$""$var")" ] while [ -n "$(eval echo "$""$var")" ]
do do
mntpt=$(eval echo "$""$var") mntpt=$(eval echo "$""$var")

View File

@ -22,10 +22,8 @@
# #
# Released under the 2-clause BSD license. # Released under the 2-clause BSD license.
# #
# The original script that acted as a template for this script came from # This script is based on debian/zfsutils.zfs.init from the
# the Debian GNU/Linux kFreeBSD ZFS packages (which did not include a # Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# licensing stansa) in the commit dated Mar 24, 2011:
# https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a
# Source the common init script # Source the common init script
. @sysconfdir@/zfs/zfs-functions . @sysconfdir@/zfs/zfs-functions

View File

@ -21,10 +21,8 @@
# #
# Released under the 2-clause BSD license. # Released under the 2-clause BSD license.
# #
# The original script that acted as a template for this script came from # This script is based on debian/zfsutils.zfs.init from the
# the Debian GNU/Linux kFreeBSD ZFS packages (which did not include a # Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# licensing stansa) in the commit dated Mar 24, 2011:
# https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a
# Source the common init script # Source the common init script
. @sysconfdir@/zfs/zfs-functions . @sysconfdir@/zfs/zfs-functions
@ -57,7 +55,7 @@ do_start()
do_stop() do_stop()
{ {
local pools RET local pools
check_module_loaded "zfs" || exit 0 check_module_loaded "zfs" || exit 0
zfs_action "Stopping ZFS Event Daemon" zfs_daemon_stop \ zfs_action "Stopping ZFS Event Daemon" zfs_daemon_stop \

View File

@ -5,10 +5,8 @@
# #
# Released under the 2-clause BSD license. # Released under the 2-clause BSD license.
# #
# The original script that acted as a template for this script came from # This script is based on debian/zfsutils.zfs.init from the
# the Debian GNU/Linux kFreeBSD ZFS packages (which did not include a # Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# licensing stansa) in the commit dated Mar 24, 2011:
# https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a
PATH=/sbin:/bin:/usr/bin:/usr/sbin PATH=/sbin:/bin:/usr/bin:/usr/sbin
@ -20,7 +18,7 @@ elif [ -L /etc/init.d/functions.sh ]; then
# Gentoo # Gentoo
. /etc/init.d/functions.sh . /etc/init.d/functions.sh
elif [ -f /lib/lsb/init-functions ]; then elif [ -f /lib/lsb/init-functions ]; then
# LSB, Debian GNU/Linux and derivatives # LSB, Debian, and derivatives
. /lib/lsb/init-functions . /lib/lsb/init-functions
fi fi
@ -63,7 +61,7 @@ elif type success > /dev/null 2>&1 ; then
echo echo
zfs_set_ifs "$TMP_IFS" zfs_set_ifs "$TMP_IFS"
} }
zfs_log_progress_msg() { echo -n $"$1"; } zfs_log_progress_msg() { echo -n "$""$1"; }
elif type einfo > /dev/null 2>&1 ; then elif type einfo > /dev/null 2>&1 ; then
# Gentoo functions # Gentoo functions
zfs_log_begin_msg() { ebegin "$1"; } zfs_log_begin_msg() { ebegin "$1"; }
@ -146,11 +144,11 @@ zfs_daemon_start()
start-stop-daemon --start --quiet --exec "$DAEMON_BIN" -- \ start-stop-daemon --start --quiet --exec "$DAEMON_BIN" -- \
$DAEMON_ARGS || return 2 $DAEMON_ARGS || return 2
# On Debian GNU/Linux, there's a 'sendsigs' script that will # On Debian, there's a 'sendsigs' script that will
# kill basically everything quite early and zed is stopped # kill basically everything quite early and zed is stopped
# much later than that. We don't want zed to be among them, # much later than that. We don't want zed to be among them,
# so add the zed pid to list of pids to ignore. # so add the zed pid to list of pids to ignore.
if [ -f "$PIDFILE" -a -d /run/sendsigs.omit.d ] if [ -f "$PIDFILE" ] && [ -d /run/sendsigs.omit.d ]
then then
ln -sf "$PIDFILE" /run/sendsigs.omit.d/zed ln -sf "$PIDFILE" /run/sendsigs.omit.d/zed
fi fi
@ -363,7 +361,7 @@ read_mtab()
fs=$(printf '%b\n' "$fs") fs=$(printf '%b\n' "$fs")
# Set the variable. # Set the variable.
eval export MTAB_$mntpnt=\"$fs\" eval export "MTAB_$mntpnt=\"$fs\""
fi fi
done < /proc/self/mounts done < /proc/self/mounts
} }
@ -376,7 +374,7 @@ in_mtab()
-e 's,-,,g' -e 's,\.,,g' -e 's, ,,g') -e 's,-,,g' -e 's,\.,,g' -e 's, ,,g')
local var local var
var="$(eval echo MTAB_$mntpnt)" var="$(eval echo "MTAB_$mntpnt")"
[ "$(eval echo "$""$var")" != "" ] [ "$(eval echo "$""$var")" != "" ]
return "$?" return "$?"
} }
@ -385,21 +383,21 @@ in_mtab()
read_fstab() read_fstab()
{ {
local match="$1" local match="$1"
local i var TMPFILE local i var
# Unset all FSTAB_* variables # Unset all FSTAB_* variables
unset $(env | grep ^FSTAB_ | sed 's,=.*,,') unset $(env | grep ^FSTAB_ | sed 's,=.*,,')
i=0 i=0
while read -r fs mntpnt fstype opts; do while read -r fs mntpnt fstype opts; do
echo "$fs" | egrep -qE '^#|^$' && continue echo "$fs" | grep -qE '^#|^$' && continue
echo "$mntpnt" | egrep -qE '^none|^swap' && continue echo "$mntpnt" | grep -qE '^none|^swap' && continue
echo "$fstype" | egrep -qE '^swap' && continue echo "$fstype" | grep -qE '^swap' && continue
if echo "$fs $mntpnt $fstype $opts" | grep -qE "$match"; then if echo "$fs $mntpnt $fstype $opts" | grep -qE "$match"; then
eval export FSTAB_dev_$i="$fs" eval export "FSTAB_dev_$i=$fs"
fs=$(printf '%b\n' "$fs" | sed 's,/,_,g') fs=$(printf '%b\n' "$fs" | sed 's,/,_,g')
eval export FSTAB_$i="$mntpnt" eval export "FSTAB_$i=$mntpnt"
i=$((i + 1)) i=$((i + 1))
fi fi
@ -410,7 +408,7 @@ in_fstab()
{ {
local var local var
var="$(eval echo FSTAB_$1)" var="$(eval echo "FSTAB_$1")"
[ "${var}" != "" ] [ "${var}" != "" ]
return $? return $?
} }
@ -418,19 +416,11 @@ in_fstab()
is_mounted() is_mounted()
{ {
local mntpt="$1" local mntpt="$1"
local line local mp
while read -r _ mp _; do
[ "$mp" = "$mntpt" ] && return 0
done < /proc/self/mounts
mount | \
while read line; do
if echo "$line" | grep -q " on $mntpt "; then
# returns:
# 0 on unsuccessful match
# 1 on a successful match
return 1 return 1
fi
done
# The negation will flip the subshell return result where the default
# return value is 0 when a match is not found.
return $(( !$? ))
} }