ref: minor changes

This commit is contained in:
ge 2022-08-13 18:22:51 +03:00
parent 484040ecbe
commit 3e61338c0d

View File

@ -33,7 +33,7 @@ if [ -f "$LIBRARY/lib.sh" ]; then
# shellcheck disable=SC1091
. "$LIBRARY/lib.sh"
else
echo "Error: Cannot source library from $LIBRARY" >&2
echo "Error: Cannot source library $LIBRARY/lib.sh: No such file" >&2
exit 1
fi
@ -106,11 +106,14 @@ done
# Final arguments parser
while (( "$#" )); do
case "$1" in
-c|--config|--config=*) optval "$1" "$2"; __config="$val"; shift "$sft";;
-c|--config|--config=*)
optval "$1" "$2"; __config="$val"; shift "$sft";;
-v|--verbose) __verbose=1; shift;;
-l|--log-file|--log-file=*) optval "$1" "$2"; __log_file="$val"; shift "$sft";;
-p|--pid-file|--pid-file=*) optval "$1" "$2"; __pid_file="$val"; shift "$sft";;
-h|--help) print_help; exit 1;;
-l|--log-file|--log-file=*)
optval "$1" "$2"; __log_file="$val"; shift "$sft";;
-p|--pid-file|--pid-file=*)
optval "$1" "$2"; __pid_file="$val"; shift "$sft";;
-h|--help) print_help; exit 0;;
-V|--version) echo "$__version"; exit 0;;
-*) echo "Error: Unknown option: $1" >&2; exit 1;;
*) __args+=("$1"); shift;; # Save positional args
@ -139,14 +142,16 @@ fi
echo "$$" > "$__pid_file"
# Scripts counter.
__count="${#__args[@]}" # count
__iter=1 # iterator
__count="${#__args[@]}" # count
__i=1 # iterator
# Startup log.
date +'Start: %d %b %Y %T %z'
log -p "Library path: $LIBRARY"
log -p "Log file: $__log_file"
log -p "Configuration file: $([ "$__config" ] || echo not specified && echo "$__config")"
log -p "Configuration file: $(if [ "$__config" ]; then \
echo not specified; else echo "$__config"; fi)"
log -p "Total scripts: $__count"
log "Scripts to process (${__count}): ${__args[*]}"
for script in "${__args[@]}"; do
@ -165,8 +170,8 @@ for script in "${__args[@]}"; do
# shellcheck source=/dev/null
[ -n "$__config" ] && . "$__config"
echo
echo -e "\e[1m--> Script: ${__args[__iter-1]##*/} [$__iter/$__count]\e[0m" | log -p
echo -e "\n\e[1m--> Script: ${__args[__i-1]##*/} [$__i/$__count]\e[0m" |
log -p
# Run prepare() before all if set
if is_function_set prepare; then
@ -192,8 +197,8 @@ for script in "${__args[@]}"; do
unset finalise
fi
# Increase counter
((__iter++)) || true
# Increase iterator
((__i++)) || true
# Unset on_error function to prevent misuse
unset on_error
@ -214,8 +219,8 @@ done
if [[ "$(cat $__errors_file)" != '0' ]]; then
echo
log -p "Backup [Failed]: Process finished with $(cat $__errors_file) errors."\
"See $__log_file for info."
log -p "Backup [Failed]: Process finished with $(cat $__errors_file) " \
"errors. See $__log_file for info."
rm "$__errors_file"
else
echo -e "\nBackup [Done]"