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 # Usage: check
# #
# shellcheck source=lib/config # shellcheck source=config
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config" LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
return=0 return=0

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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