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