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