From a3322cb47ffc7e657d81706242b740c7a787db3a Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Mon, 5 Sep 2022 18:02:39 +0100 Subject: [PATCH] Make rc.d scripts shellcheck friendly. --- rc.d/rc.bwbar | 3 +++ rc.d/rc.proftpd | 12 ++++++++++-- rc.d/rc.rsyncd | 12 ++++++++++-- rc.d/rc.seeder | 9 +++++---- rc.d/rc.template | 10 +++++++--- rc.d/rc.tftpd | 10 ++++++++-- 6 files changed, 43 insertions(+), 13 deletions(-) diff --git a/rc.d/rc.bwbar b/rc.d/rc.bwbar index 364296f..7ca7897 100755 --- a/rc.d/rc.bwbar +++ b/rc.d/rc.bwbar @@ -4,6 +4,8 @@ # Darren 'Tadgy' Austin # Licensed under the terms of the GNU General Public License version 3. +# shellcheck disable=SC2016,SC1090 + BWBAR_EXEC="/opt/bin/bwbar" DAEMON_EXEC="/usr/bin/daemon" BWBAR_ARGS=('-f' '/run/bwbar.txt' '-l' '/run/bwbar-light.png' '-d' '/run/bwbar-dark.png' '${MONINTERFACE:-eth0}' '$(( ($(ethtool "${MONINTERFACE:-eth0}" | sed -nre "/Speed:/ s/[^[:digit:]]*([[:digit:]]+).*/\1/ p") / 100) * 90 ))') @@ -52,6 +54,7 @@ startdaemon() { return 2 } su - "${RUNUSER:-$(whoami)}" -c "${DAEMON_ENVIRONMENT:+declare ${DAEMON_ENVIRONMENT[*]};} \"$DAEMON_EXEC\" ${DAEMON_ARGS[*]} \"$BWBAR_EXEC\" ${BWBAR_ARGS[*]}" + # shellcheck disable=SC2181 if (( $? != 0 )); then error "error starting 'daemon'" return 2 diff --git a/rc.d/rc.proftpd b/rc.d/rc.proftpd index 129a371..874bda9 100755 --- a/rc.d/rc.proftpd +++ b/rc.d/rc.proftpd @@ -4,6 +4,8 @@ # Darren 'Tadgy' Austin # Licensed under the terms of the GNU General Public License version 3. +# shellcheck disable=SC2016,SC2034 + PROFTPD_EXEC="/usr/sbin/proftpd" PROFTPD_ARGS=() PROFTPD_PIDFILE="/run/proftpd.pid" @@ -24,6 +26,7 @@ LUMBERJACK_BASEDIR="/data/sites" # LUMBERJACK_BASEDIR="" # The base directory where lumberjack should write logs. Default: /data/sites. # SLAY_DELAY="" # Delay between the SIGTERM and SIGKILL on a 'stop'. Default: 2s. # RESTART_DELAY="" # Delay between stopping and starting on a 'restart'. Default: 2s. +# shellcheck disable=SC1090 [[ -e "/etc/default/${0##*rc.}" ]] && { source "/etc/default/${0##*rc.}" || return 1 2>/dev/null || exit 1; } # Now all possible variable changes are complete, expand out the embedded variables. @@ -46,6 +49,7 @@ checkconfigured() { } checkstatus() { + # shellcheck disable=SC2155 local RET=0 RUNPIDS="$({ pgrep -f "$PROFTPD_EXEC"; pgrep -F "$PROFTPD_PIDFILE" 2>/dev/null; } | sort -u )" if "$DAEMON_EXEC" --running -n "lumberjack-${0##*rc.}"; then printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${LUMBERJACK_EXEC##*/}" "running" @@ -53,9 +57,9 @@ checkstatus() { printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${LUMBERJACK_EXEC##*/}" "stopped" RET=1 fi - if [[ ! -z "$RUNPIDS" ]]; then + if [[ -n "$RUNPIDS" ]]; then printf "%s: %s: %s" "${BASH_SOURCE[0]##*/}" "${PROFTPD_EXEC##*/}" "running" - if [[ ! -z "$PROFTPD_PIDFILE" ]]; then + if [[ -n "$PROFTPD_PIDFILE" ]]; then if [[ ! -e "$PROFTPD_PIDFILE" ]]; then printf "%s" ", but .pid file does not exist" elif ! grep "\<$(<"$PROFTPD_PIDFILE")\>" <<<"$RUNPIDS" >/dev/null 2>&1; then @@ -75,12 +79,16 @@ startdaemon() { error "${PROFTPD_EXEC##*/}: not started - pre-start checks failed" return 2 } + # shellcheck disable=SC2048,SC2086 ${DAEMON_ENVIRONMENT:+declare ${DAEMON_ENVIRONMENT[*]};} "$DAEMON_EXEC" ${DAEMON_ARGS[*]} "$LUMBERJACK_EXEC" ${LUMBERJACK_ARGS[*]} + # shellcheck disable=SC2181 (( $? != 0 )) && { error "error starting '${DAEMON_EXEC##*/}'" return 2 } + # shellcheck disable=SC2048,SC2086 ${PROFTPD_ENVIRONMENT:+declare ${PROFTPD_ENVIRONMENT[*]};} "$PROFTPD_EXEC" ${PROFTPD_ARGS[*]} + # shellcheck disable=SC2181 if (( $? != 0 )); then error "error starting '${PROFTPD_EXEC##*/}'" return 2 diff --git a/rc.d/rc.rsyncd b/rc.d/rc.rsyncd index c13f457..02fc098 100755 --- a/rc.d/rc.rsyncd +++ b/rc.d/rc.rsyncd @@ -4,6 +4,8 @@ # Darren 'Tadgy' Austin # Licensed under the terms of the GNU General Public License version 3. +# shellcheck disable=SC2016,SC2034 + RSYNC_EXEC="/usr/bin/rsync" RSYNC_ARGS=('--daemon' '${RSYNC_CONF:---config=/etc/rsyncd/rsyncd.conf}') RSYNC_PIDFILE="/run/rsyncd.pid" @@ -25,6 +27,7 @@ LUMBERJACK_BASEDIR="/data/sites/slackware.uk" # LUMBERJACK_BASEDIR="" # The base directory where lumberjack should write logs. Default: /data/sites/slackware.uk. # SLAY_DELAY="" # Delay between the SIGTERM and SIGKILL on a 'stop'. Default: 2s. # RESTART_DELAY="" # Delay between stopping and starting on a 'restart'. Default: 2s. +# shellcheck disable=SC1090 [[ -e "/etc/default/${0##*rc.}" ]] && { source "/etc/default/${0##*rc.}" || return 1 2>/dev/null || exit 1; } # Now all possible variable changes are complete, expand out the embedded variables. @@ -48,6 +51,7 @@ checkconfigured() { } checkstatus() { + # shellcheck disable=SC2155 local RET=0 RUNPIDS="$({ pgrep -f "$RSYNC_EXEC"; pgrep -F "$RSYNC_PIDFILE" 2>/dev/null; } | sort -u )" if "$DAEMON_EXEC" --running -n "lumberjack-${0##*rc.}"; then printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${LUMBERJACK_EXEC##*/}" "running" @@ -55,9 +59,9 @@ checkstatus() { printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${LUMBERJACK_EXEC##*/}" "stopped" RET=1 fi - if [[ ! -z "$RUNPIDS" ]]; then + if [[ -n "$RUNPIDS" ]]; then printf "%s: %s: %s" "${BASH_SOURCE[0]##*/}" "${RSYNC_EXEC##*/}" "running" - if [[ ! -z "$RSYNC_PIDFILE" ]]; then + if [[ -n "$RSYNC_PIDFILE" ]]; then if [[ ! -e "$RSYNC_PIDFILE" ]]; then printf "%s" ", but .pid file does not exist" elif ! grep "\<$(<"$RSYNC_PIDFILE")\>" <<<"$RUNPIDS" >/dev/null 2>&1; then @@ -77,12 +81,16 @@ startdaemon() { error "${RSYNC_EXEC##*/}: not started - pre-start checks failed" return 2 } + # shellcheck disable=SC2048,SC2086 ${DAEMON_ENVIRONMENT:+declare ${DAEMON_ENVIRONMENT[*]};} "$DAEMON_EXEC" ${DAEMON_ARGS[*]} "$LUMBERJACK_EXEC" ${LUMBERJACK_ARGS[*]} + # shellcheck disable=SC2181 (( $? != 0 )) && { error "error starting '${DAEMON_EXEC##*/}'" return 2 } + # shellcheck disable=SC2048,SC2086 ${RSYNC_ENVIRONMENT:+declare ${RSYNC_ENVIRONMENT[*]};} "$RSYNC_EXEC" ${RSYNC_ARGS[*]} + # shellcheck disable=SC2181 if (( $? != 0 )); then error "error starting '${RSYNC_EXEC##*/}'" return 2 diff --git a/rc.d/rc.seeder b/rc.d/rc.seeder index 119b93e..466c461 100755 --- a/rc.d/rc.seeder +++ b/rc.d/rc.seeder @@ -4,6 +4,8 @@ # Darren 'Tadgy' Austin # Licensed under the terms of the GNU General Public License version 3. +# shellcheck disable=SC2016,SC2088 + SCREEN_EXEC="/usr/bin/screen" RTORRENTWRAPPER_EXEC='$HOME/bin/rtorrent-wrapper' DAEMON_EXEC="/usr/bin/daemon" @@ -17,6 +19,7 @@ RUNUSER="seeder" # SEEDS=() # The seeding sessions to start. Must be an array. # SLAY_DELAY="" # Delay between the SIGTERM and SIGKILL on a 'stop'. Default: 2s. # RESTART_DELAY="" # Delay between stopping and starting on a 'restart'. Default: 2s. +# shellcheck disable=SC1090 [[ -e "/etc/default/${0##*rc.}" ]] && { source "/etc/default/${0##*rc.}" || return 1 2>/dev/null || exit 1; } error() { @@ -35,7 +38,7 @@ checkconfigured() { checkstatus() { # $@ = Name(s) of a seeding session(s) to check. local SEED RET=0 - if [[ ! -z "$(su - "${RUNUSER:-seeder}" -c "\"$DAEMON_EXEC\" --list 2>/dev/null")" ]]; then + if [[ -n "$(su - "${RUNUSER:-seeder}" -c "\"$DAEMON_EXEC\" --list 2>/dev/null")" ]]; then for SEED in "$@"; do if su - "${RUNUSER:-seeder}" -c "\"$DAEMON_EXEC\" --running -n \"seeder-$SEED\""; then printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "seed '$SEED'" "running" @@ -129,7 +132,7 @@ case "$OPT" in 'start') if checkstatus "${@:-${SEEDS[@]}}" >/dev/null; then error "seeds already running" - printf " %s\\n" "Try: ${BASH_SOURCE[0]} status $@" >&2 + printf " %s\\n" "Try: ${BASH_SOURCE[0]} status $*" >&2 RET=1 else startdaemon "${@:-${SEEDS[@]}}" @@ -149,7 +152,6 @@ case "$OPT" in else error "unhandled status: $ERR" RET=1 - break fi ;; 'restart') @@ -166,7 +168,6 @@ case "$OPT" in else error "unhandled status: $ERR" RET=1 - break fi ;; 'status') diff --git a/rc.d/rc.template b/rc.d/rc.template index 23f6de3..d35fef7 100755 --- a/rc.d/rc.template +++ b/rc.d/rc.template @@ -1,5 +1,5 @@ #!/bin/bash -# Version: 0.3.0 +# Version: 0.3.1 # Copyright (c) 2005-2022: # Darren 'Tadgy' Austin # Licensed under the terms of the GNU General Public License version 3. @@ -14,6 +14,7 @@ PIDFILE="" # EXTRA_ARGS=() # Extra arguments passed to $EXEC. Must be an array. # SLAY_DELAY="" # Delay between the SIGTERM and SIGKILL on a 'stop'. Default: 2s. # RESTART_DELAY="" # Delay between stopping and starting on a 'restart'. Default: 2s. +# shellcheck disable=SC1090 [[ -e "/etc/default/${0##*rc.}" ]] && { source "/etc/default/${0##*rc.}" || return 1 2>/dev/null || exit 1; } error() { @@ -29,10 +30,11 @@ checkconfigured() { } checkstatus() { + # shellcheck disable=SC2155 local RUNPIDS="$({ pgrep -f "$EXEC"; pgrep -F "$PIDFILE" 2>/dev/null; } | sort -u )" - if [[ ! -z "$RUNPIDS" ]]; then + if [[ -n "$RUNPIDS" ]]; then printf "%s: %s: %s" "${BASH_SOURCE[0]##*/}" "${EXEC##*/}" "running" - if [[ ! -z "$PIDFILE" ]]; then + if [[ -n "$PIDFILE" ]]; then if [[ ! -e "$PIDFILE" ]]; then printf "%s" ", but .pid file does not exist" elif ! grep "\<$(<"$PIDFILE")\>" <<<"$RUNPIDS" >/dev/null 2>&1; then @@ -58,7 +60,9 @@ startdaemon() { error "not started - pre-start checks failed" return 2 fi + # shellcheck disable=SC2048,SC2086 ${ENVIRONMENT:+declare ${ENVIRONMENT[*]};} "$EXEC" ${ARGS[*]} ${EXTRA_ARGS[*]} + # shellcheck disable=SC2181 if (( $? != 0 )); then error "error starting daemon" return 2 diff --git a/rc.d/rc.tftpd b/rc.d/rc.tftpd index 2562637..2200690 100755 --- a/rc.d/rc.tftpd +++ b/rc.d/rc.tftpd @@ -4,6 +4,8 @@ # Darren 'Tadgy' Austin # Licensed under the terms of the GNU General Public License version 3. +# shellcheck disable=SC2016 + EXEC="/usr/sbin/in.tftpd" ARGS=('-l' '-s' '-u' '${RUNUSER:-tftp}' '-P' '/run/tftpd.pid' '/data/tftpboot') PIDFILE="/run/tftpd.pid" @@ -16,6 +18,7 @@ RUNUSER="tftp" # RUNUSER="" # The username to run the tftp daemon as. Default: tftp. # SLAY_DELAY="" # Delay between the SIGTERM and SIGKILL on a 'stop'. Default: 2s. # RESTART_DELAY="" # Delay between stopping and starting on a 'restart'. Default: 2s. +# shellcheck disable=SC1090 [[ -e "/etc/default/${0##*rc.}" ]] && { source "/etc/default/${0##*rc.}" || return 1 2>/dev/null || exit 1; } error() { @@ -32,10 +35,11 @@ checkconfigured() { } checkstatus() { + # shellcheck disable=SC2155 local RUNPIDS="$({ pgrep -f "$EXEC"; pgrep -F "$PIDFILE" 2>/dev/null; } | sort -u )" - if [[ ! -z "$RUNPIDS" ]]; then + if [[ -n "$RUNPIDS" ]]; then printf "%s: %s: %s" "${BASH_SOURCE[0]##*/}" "${EXEC##*/}" "running" - if [[ ! -z "$PIDFILE" ]]; then + if [[ -n "$PIDFILE" ]]; then if [[ ! -e "$PIDFILE" ]]; then printf "%s" ", but .pid file does not exist" elif ! grep "\<$(<"$PIDFILE")\>" <<<"$RUNPIDS" >/dev/null 2>&1; then @@ -61,7 +65,9 @@ startdaemon() { error "not started - pre-start checks failed" return 2 fi + # shellcheck disable=SC2048,SC2086 ${ENVIRONMENT:+declare ${ENVIRONMENT[*]};} "$EXEC" ${ARGS[*]} ${EXTRA_ARGS[*]} + # shellcheck disable=SC2181 if (( $? != 0 )); then error "error starting daemon" return 2