diff options
author | Kash Pande <[email protected]> | 2018-02-21 20:54:54 -0500 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2018-02-23 12:57:41 -0800 |
commit | 41532e5a29a85de180f1bc6b6c605cedb44b0806 (patch) | |
tree | 3f010ec3c6d6bf9e87274b5a79773de01dd2eef8 /contrib/dracut/90zfs/zfs-lib.sh.in | |
parent | 7280d581973e923c6492b59803246a94347a47b8 (diff) |
Shellcheck cleanup for initrd scripts
Reviewed-by: Brian Behlendorf <[email protected]>
Co-authored-by: Kash Pande <[email protected]>
Co-authored-by: Matthew Thode <[email protected]>
Signed-off-by: Kash Pande <[email protected]>
Signed-off-by: Matthew Thode <[email protected]>
Closes #7214
Diffstat (limited to 'contrib/dracut/90zfs/zfs-lib.sh.in')
-rwxr-xr-x | contrib/dracut/90zfs/zfs-lib.sh.in | 143 |
1 files changed, 70 insertions, 73 deletions
diff --git a/contrib/dracut/90zfs/zfs-lib.sh.in b/contrib/dracut/90zfs/zfs-lib.sh.in index 82666afd0..23c07af9e 100755 --- a/contrib/dracut/90zfs/zfs-lib.sh.in +++ b/contrib/dracut/90zfs/zfs-lib.sh.in @@ -5,16 +5,16 @@ command -v getargbool >/dev/null || { # Compatibility with older Dracut versions. # With apologies to the Dracut developers. getargbool() { - local _b - unset _b - local _default + if ! [ -z "$_b" ]; then + unset _b + fi _default="$1"; shift _b=$(getarg "$@") - [ $? -ne 0 -a -z "$_b" ] && _b="$_default" + [ $? -ne 0 ] && [ -z "$_b" ] && _b="$_default" if [ -n "$_b" ]; then - [ $_b = "0" ] && return 1 - [ $_b = "no" ] && return 1 - [ $_b = "off" ] && return 1 + [ "$_b" = "0" ] && return 1 + [ "$_b" = "no" ] && return 1 + [ "$_b" = "off" ] && return 1 fi return 0 } @@ -26,82 +26,82 @@ NEWLINE=" ZPOOL_IMPORT_OPTS="" if getargbool 0 zfs_force -y zfs.force -y zfsforce ; then - warn "ZFS: Will force-import pools if necessary." - ZPOOL_IMPORT_OPTS="${ZPOOL_IMPORT_OPTS} -f" + warn "ZFS: Will force-import pools if necessary." + ZPOOL_IMPORT_OPTS="${ZPOOL_IMPORT_OPTS} -f" fi # find_bootfs # returns the first dataset with the bootfs attribute. find_bootfs() { - IFS="${NEWLINE}" - for dataset in $(zpool list -H -o bootfs); do - case "${dataset}" in - "" | "-") - continue - ;; - "no pools available") - IFS="${OLDIFS}" - return 1 - ;; - *) - IFS="${OLDIFS}" - echo "${dataset}" - return 0 - ;; - esac - done - - IFS="${OLDIFS}" - return 1 + IFS="${NEWLINE}" + for dataset in $(zpool list -H -o bootfs); do + case "${dataset}" in + "" | "-") + continue + ;; + "no pools available") + IFS="${OLDIFS}" + return 1 + ;; + *) + IFS="${OLDIFS}" + echo "${dataset}" + return 0 + ;; + esac + done + + IFS="${OLDIFS}" + return 1 } # import_pool POOL # imports the given zfs pool if it isn't imported already. import_pool() { - local pool="${1}" + pool="${1}" - if ! zpool list -H "${pool}" 2>&1 > /dev/null ; then - info "ZFS: Importing pool ${pool}..." - if ! zpool import -N ${ZPOOL_IMPORT_OPTS} "${pool}" ; then - warn "ZFS: Unable to import pool ${pool}" - return 1 - fi - fi + if ! zpool list -H "${pool}" > /dev/null 2>&1; then + info "ZFS: Importing pool ${pool}..." + if ! zpool import -N ${ZPOOL_IMPORT_OPTS} "${pool}" ; then + warn "ZFS: Unable to import pool ${pool}" + return 1 + fi + fi - return 0 + return 0 } # mount_dataset DATASET # mounts the given zfs dataset. mount_dataset() { - local dataset="${1}" - local mountpoint="$(zfs get -H -o value mountpoint "${dataset}")" + dataset="${1}" + mountpoint="$(zfs get -H -o value mountpoint "${dataset}")" - # We need zfsutil for non-legacy mounts and not for legacy mounts. - if [ "${mountpoint}" = "legacy" ] ; then - mount -t zfs "${dataset}" "${NEWROOT}" - else - mount -o zfsutil -t zfs "${dataset}" "${NEWROOT}" - fi + # We need zfsutil for non-legacy mounts and not for legacy mounts. + if [ "${mountpoint}" = "legacy" ] ; then + mount -t zfs "${dataset}" "${NEWROOT}" + else + mount -o zfsutil -t zfs "${dataset}" "${NEWROOT}" + fi - return $? + return $? } # export_all OPTS # exports all imported zfs pools. export_all() { - local opts="${@}" - local ret=0 - - IFS="${NEWLINE}" - for pool in `zpool list -H -o name` ; do - if zpool list -H "${pool}" 2>&1 > /dev/null ; then - zpool export "${pool}" ${opts} || ret=$? - fi - done - IFS="${OLDIFS}" - - return ${ret} + opts="${@}" + ret=0 + + IFS="${NEWLINE}" + for pool in $(zpool list -H -o name) ; do + if zpool list -H "${pool}" > /dev/null 2>&1; then + zpool export "${pool}" ${opts} || ret=$? + fi + done + IFS="${OLDIFS}" + + return ${ret} } # ask_for_password @@ -124,12 +124,9 @@ export_all() { # Turn off input echo before tty command is executed and turn on after. # It's useful when password is read from stdin. ask_for_password() { - local cmd; local prompt; local tries=3 - local ply_cmd; local ply_prompt; local ply_tries=3 - local tty_cmd; local tty_prompt; local tty_tries=3 - local ret - - while [ $# -gt 0 ]; do + ply_tries=3 + tty_tries=3 + while [ "$#" -gt 0 ]; do case "$1" in --cmd) ply_cmd="$2"; tty_cmd="$2"; shift;; --ply-cmd) ply_cmd="$2"; shift;; @@ -147,9 +144,9 @@ ask_for_password() { { flock -s 9; # Prompt for password with plymouth, if installed and running. - if type plymouth >/dev/null 2>&1 && plymouth --ping 2>/dev/null; then + if whereis plymouth >/dev/null 2>&1 && plymouth --ping 2>/dev/null; then plymouth ask-for-password \ - --prompt "$ply_prompt" --number-of-tries=$ply_tries \ + --prompt "$ply_prompt" --number-of-tries="$ply_tries" \ --command="$ply_cmd" ret=$? else @@ -158,17 +155,17 @@ ask_for_password() { stty -echo fi - local i=1 - while [ $i -le $tty_tries ]; do + i=1 + while [ "$i" -le "$tty_tries" ]; do [ -n "$tty_prompt" ] && \ - printf "$tty_prompt [$i/$tty_tries]:" >&2 + printf "%s [%i/%i]:" "$tty_prompt" "$i" "$tty_tries" >&2 eval "$tty_cmd" && ret=0 && break ret=$? - i=$(($i+1)) + i=$((i+1)) [ -n "$tty_prompt" ] && printf '\n' >&2 done - - [ "$tty_echo_off" = yes ] && stty $stty_orig + unset i + [ "$tty_echo_off" = yes ] && stty "$stty_orig" fi } 9>/.console_lock |