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