feat: Small code improvements
This commit is contained in:
parent
323e5d9fc8
commit
c37ee0de66
@ -20,6 +20,7 @@ __version='0.0.0'
|
|||||||
__config=
|
__config=
|
||||||
__verbose=
|
__verbose=
|
||||||
__log_file='./log.txt'
|
__log_file='./log.txt'
|
||||||
|
__log_date_fmt='%d/%b/%Y:%H:%M:%S %z'
|
||||||
__tar_options='-acf'
|
__tar_options='-acf'
|
||||||
__tar_compression='gzip'
|
__tar_compression='gzip'
|
||||||
__name_date_fmt='_%Y%m%d-%H%M'
|
__name_date_fmt='_%Y%m%d-%H%M'
|
||||||
@ -113,14 +114,14 @@ done
|
|||||||
# ---------------------------------------------------------- #
|
# ---------------------------------------------------------- #
|
||||||
|
|
||||||
# Scripts counter.
|
# Scripts counter.
|
||||||
_count=${#__args[@]} # count
|
__count=${#__args[@]} # count
|
||||||
_iter=1 # iterator
|
__iter=1 # iterator
|
||||||
|
|
||||||
# Startup log.
|
# Startup log.
|
||||||
date +'Start: %d %b %Y %T %z'
|
date +'Start: %d %b %Y %T %z'
|
||||||
log "Backup STARTED"
|
log "Backup STARTED"
|
||||||
log -p "Configuration file: $([ "$__config" ] || echo not specified && echo "$__config")"
|
log -p "Configuration file: $([ "$__config" ] || echo not specified && echo "$__config")"
|
||||||
log "Scripts to process (${_count}): ${__args[@]}"
|
log "Scripts to process (${__count}): ${__args[@]}"
|
||||||
|
|
||||||
|
|
||||||
for script in "${__args[@]}"; do
|
for script in "${__args[@]}"; do
|
||||||
@ -130,7 +131,7 @@ for script in "${__args[@]}"; do
|
|||||||
[ -n "$__config" ] && . "$__config"
|
[ -n "$__config" ] && . "$__config"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo -e "\e[1m==> Script: ${__args[_iter-1]##*/} [$_iter/$_count]\e[0m" | log -p
|
echo -e "\e[1m==> Script: ${__args[__iter-1]##*/} [$__iter/$__count]\e[0m" | log -p
|
||||||
|
|
||||||
# Initialise variables
|
# Initialise variables
|
||||||
__user_script="$script"
|
__user_script="$script"
|
||||||
@ -161,7 +162,7 @@ for script in "${__args[@]}"; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase counter
|
# Increase counter
|
||||||
((_iter++)) || true
|
((__iter++)) || true
|
||||||
|
|
||||||
# Unset user defined variables
|
# Unset user defined variables
|
||||||
unset tar_options
|
unset tar_options
|
||||||
|
@ -294,8 +294,10 @@ gen_backup_name() {
|
|||||||
|
|
||||||
# Overwrite __name_date_fmt
|
# Overwrite __name_date_fmt
|
||||||
if [ -n "$name_date_fmt" ]; then
|
if [ -n "$name_date_fmt" ]; then
|
||||||
__name_date_fmt="$name_date_fmt"
|
date_fmt="$name_date_fmt"
|
||||||
|
else
|
||||||
|
date_fmt="$__name_date_fmt"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
date +"${prefix}${name}${__name_date_fmt}${name_ext}"
|
date +"${prefix}${name}${date_fmt}${name_ext}"
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ log() {
|
|||||||
[[ ! -t 0 ]] || [[ "$#" == 0 ]] && message="$(cat <&0)"
|
[[ ! -t 0 ]] || [[ "$#" == 0 ]] && message="$(cat <&0)"
|
||||||
|
|
||||||
# Set log date format
|
# Set log date format
|
||||||
[ "$log_date_fmt" ] || log_date_fmt='%d/%b/%Y:%H:%M:%S %z'
|
[ "$log_date_fmt" ] || log_date_fmt="$__log_date_fmt"
|
||||||
|
|
||||||
while (( "$#" )); do
|
while (( "$#" )); do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -61,12 +61,14 @@ setup() {
|
|||||||
. source.sh
|
. source.sh
|
||||||
. uri.sh # for parse_uri()
|
. uri.sh # for parse_uri()
|
||||||
source_script $DIR/files/basic.plan
|
source_script $DIR/files/basic.plan
|
||||||
[ "$__main_target" == '/etc/lvm/backup' ]
|
[ "$__main_target" == 'file:/etc/lvm/backup' ]
|
||||||
|
[ "$__main_target_path" == '/etc/lvm/backup' ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Set __main_target from multiple 'file' targets" {
|
@test "Set __main_target from multiple 'file' targets" {
|
||||||
. source.sh
|
. source.sh
|
||||||
. uri.sh # for parse_uri()
|
. uri.sh # for parse_uri()
|
||||||
source_script $DIR/files/multiple_file_targets.plan
|
source_script $DIR/files/multiple_file_targets.plan
|
||||||
[ "$__main_target" == '/etc/lvm/backup' ]
|
[ "$__main_target" == 'file:///etc/lvm/backup' ]
|
||||||
|
[ "$__main_target_path" == '/etc/lvm/backup' ]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user