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