Make rc.d scripts shellcheck friendly.

This commit is contained in:
Darren 'Tadgy' Austin 2022-09-05 18:02:39 +01:00
commit a3322cb47f
6 changed files with 43 additions and 13 deletions

View file

@ -4,6 +4,8 @@
# Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# 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')