sync.sh: add some code in functions

This commit is contained in:
2022-05-10 20:38:34 +02:00
parent 9ea7e38759
commit 28780ef13c

View File

@@ -142,13 +142,8 @@
###############################################################################
######################### options default values
###############################################################################
<<<<<<< Updated upstream
# These ones can be set by command-line.
# They can also be overwritten in configuration file (prefered option).
=======
# These ones can be set by command-line and in configuration file.
# priority is given to configuration file.
>>>>>>> Stashed changes
YEARLY=n # (-ay) yearly backup (y/n)
MONTHLY=n # (-am) monthly backup (y/n)
WEEKLY=n # (-aw) weekly backup (y/n)
@@ -378,8 +373,9 @@ exit_handler() {
###############################################################################
######################### Options/Environment setup
###############################################################################
# command-line options parsing.
OPTIND=1
# command-line parsing / configuration file read.
parse_opts() {
OPTIND=0
shopt -s extglob # to parse "-a" option
while getopts a:DfnruvzZ todo; do
case "$todo" in
@@ -413,6 +409,7 @@ done
shift $((OPTIND - 1))
(( $# != 1 )) && usage
CONFIG="$1"
LOCKDIR=".sync-$SERVER-${CONFIG##*/}.lock"
if [[ ! -r "$CONFIG" ]]; then
@@ -421,16 +418,23 @@ if [[ ! -r "$CONFIG" ]]; then
fi
# shellcheck source=/dev/null
source "$CONFIG"
}
parse_opts "$@"
# we set backups to be done if none has been set yet (i.e. none is "y").
# Note: we use the form +%-d to avoid zero padding :
# for bash, starting with 0 => octal => 08 is invalid
adjust_targets() {
if ! [[ "$DAILY$WEEKLY$MONTHLY$YEARLY" =~ .*y.* ]]; then
(( $(date +%u) == 7 )) && WEEKLY=y
(( $(date +%-d) == 1 )) && MONTHLY=y
(( $(date +%-d) == 1 && $(date +%-m) == 1 )) && YEARLY=y
DAILY=y
fi
}
adjust_targets
# After these basic initializations, errors will be managed by the
# following handler. It is better to do this before the redirections below.
@@ -485,11 +489,7 @@ log -n "Compression: " && [[ $ZIPMAIL = gzip ]] && log "gzip" || log "none"
declare -a cmdavail=()
log -n "Checking for commands : "
for cmd in rsync base64 sendmail gzip; do
<<<<<<< Updated upstream
log -n "%s..." "$cmd..."
=======
log -n "%s..." "$cmd"
>>>>>>> Stashed changes
if type -P "$cmd" > /dev/null; then
log -n "ok "
else