Add some shellcheck directives for config source

This commit is contained in:
Jérémy Lecour 2020-04-01 07:31:33 +02:00 committed by Jérémy Lecour
parent 9ae2168b1b
commit 10cc3695a4
21 changed files with 47 additions and 14 deletions

View file

@ -4,7 +4,7 @@
# Usage: check
#
# shellcheck source=lib/config
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
return=0

View file

@ -4,6 +4,7 @@
# Usage: firewall <jailname>|all
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: help
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
cat <<EOF

View file

@ -4,6 +4,7 @@
# Usage: inc
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
date=$(date +"%Y-%m-%d-%H")

View file

@ -4,6 +4,7 @@
# Usage: init <jailname>
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: ip <jailname> [<ip>|all]
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: is-on <jailname>
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: key <jailname> [<keyfile>]
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -6,6 +6,7 @@
set -eu
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
[ -d "${JAILDIR}" ] || exit 0

View file

@ -4,6 +4,7 @@
# Usage: port <jailname> [<port>|auto]
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: reload <jailname>|all
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: remove <jailname>|all
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -6,6 +6,7 @@
set -eu
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: rm
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
for jail in $("${LIBDIR}/bkctld-list"); do

View file

@ -4,6 +4,7 @@
# Usage: start <jailname>|all
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: stats
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
mkdir -p "${INDEX_DIR}"

View file

@ -4,6 +4,7 @@
# Usage: status [<jailname>]
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: stop <jailname>|all
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: sync <jailname>|all
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -4,6 +4,7 @@
# Usage: update <jailname>|all
#
# shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"

View file

@ -48,7 +48,7 @@ SYNC_TASKS=${SYNC_TASKS:-1}
##### SETUP AND FUNCTIONS #############################################
BEGINNING=$(/bin/date +"%d-%m-%Y ; %H:%M")
BEGINNING=$(now)
# shellcheck disable=SC2174
mkdir -p -m 700 ${LOCAL_BACKUP_DIR}
@ -65,6 +65,18 @@ umask 077
## Initialize variable to store SSH connection errors
SERVERS_SSH_ERRORS=""
now() {
date +"%Y-%m-%dT%H:%M:%S%:z"
}
log_error() {
>&2 echo "$@"
printf "[%s] ERROR: %s\n" "$(now)" "$@" >> $LOGFILE
}
log_info() {
echo "$@"
printf "[%s] INFO: %s\n" "$(now)" "$@" >> $LOGFILE
}
# Call test_server with "HOST:PORT" string
# It will return with 0 if the server is reachable.
# It will return with 1 and a message on stderr if not.
@ -98,10 +110,7 @@ pick_server() {
new_error="No more server available"
SERVERS_SSH_ERRORS=$(printf "%s\n%s" "${SERVERS_SSH_ERRORS}" "${new_error}" | sed -e '/^$/d')
# Log errors to stderr
printf "%s\n" "${SERVERS_SSH_ERRORS}" >&2
# Log errors to logfile
printf "%s\n" "${SERVERS_SSH_ERRORS}" >> $LOGFILE
log_error "${SERVERS_SSH_ERRORS}"
return 1
fi
@ -130,7 +139,7 @@ if [ -e "${PIDFILE}" ]; then
done
# Then kill the main PID.
kill -9 "${pid}"
printf "%s is still running (PID %s). Process has been killed" "$0" "${pid}\n" >&2
log_error $(printf "%s is still running (PID %s). Process has been killed" "$0" "${pid}")
else
rm -f ${PIDFILE}
fi
@ -142,6 +151,7 @@ trap "rm -f ${PIDFILE}" EXIT
##### LOCAL BACKUP ####################################################
if [ "${LOCAL_TASKS}" = "1" ]; then
log_info "Local tasks: start"
# You can comment or uncomment sections below to customize the backup
## OpenLDAP : example with slapcat
@ -319,6 +329,9 @@ if [ "${LOCAL_TASKS}" = "1" ]; then
#getfacl -R /usr > ${LOCAL_BACKUP_DIR}/rights-usr.txt
#getfacl -R /home > ${LOCAL_BACKUP_DIR}/rights-home.txt
log_info "Local tasks: finish"
else
log_info "Local tasks: skip"
fi
##### REMOTE BACKUP ###################################################
@ -356,6 +369,7 @@ fi
if [ "${SYNC_TASKS}" = "1" ]; then
log_info "Sync tasks: start"
# /!\ DO NOT USE COMMENTS in the rsync command /!\
# It breaks the command and destroys data, simply remove (or add) lines.
@ -400,18 +414,18 @@ if [ "${SYNC_TASKS}" = "1" ]; then
-e "${RSH_COMMAND}" \
"root@${SSH_SERVER}:/var/backup/" \
| tail -30 >> $LOGFILE
log_info "Sync tasks: finish"
else
log_info "Sync tasks: skip"
fi
##### REPORTING #######################################################
END=$(/bin/date +"%d-%m-%Y ; %H:%M")
END=$(now)
printf "EvoBackup - %s - START %s ON %s (LOCAL_TASKS=%s SYNC_TASKS=%s)\n" \
"${HOSTNAME}" "${BEGINNING}" "${SSH_SERVER}" "${LOCAL_TASKS}" "${SYNC_TASKS}" \
>> $LOGFILE
printf "EvoBackup - %s - STOP %s ON %s (LOCAL_TASKS=%s SYNC_TASKS=%s)\n" \
"${HOSTNAME}" "${END}" "${SSH_SERVER}" "${LOCAL_TASKS}" "${SYNC_TASKS}" \
log_info "EvoBackup - %s - START %s STOP %s ON %s (LOCAL_TASKS=%s SYNC_TASKS=%s)\n" \
"${HOSTNAME}" "${BEGINNING}" "${END}" "${SSH_SERVER}" "${LOCAL_TASKS}" "${SYNC_TASKS}" \
>> $LOGFILE
tail -10 $LOGFILE | \