improved args
This commit is contained in:
@@ -14,13 +14,27 @@
|
||||
# Profiles in Master.conf match the last string of folder location
|
||||
# if a match is made with a list in Master.conf then the associated profile will be used
|
||||
# If no match is made it defualts to global defualts
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#----------------------------- Arguments, add after rsync command ------------------------------
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
# Does a dry run making no changes
|
||||
#--dry-run
|
||||
#
|
||||
#Force logging
|
||||
#--log)
|
||||
#
|
||||
#Force logging to be dissabled
|
||||
#--no-log
|
||||
#
|
||||
#--help
|
||||
#
|
||||
# Example = /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-test/Arrs/ --dry-run --no-log
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#----------------- User Variables, Please adjust in Master.cong as needed ----------------------
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Does a dry run making no changes
|
||||
#--dry-run
|
||||
#
|
||||
# Network speed limit (KB/s)
|
||||
#BW_LIMIT=12500
|
||||
|
||||
@@ -25,33 +25,49 @@ log() {
|
||||
|
||||
parse_args() {
|
||||
DRY_RUN=${DRY_RUN:-false}
|
||||
ENABLE_LOGGING=${ENABLE_LOGGING:-false}
|
||||
|
||||
for ARG in "$@"; do
|
||||
if [[ "$ARG" == *=* ]]; then
|
||||
VAR_NAME="${ARG%%=*}"
|
||||
VAR_VALUE="${ARG#*=}"
|
||||
|
||||
if declare -p "$VAR_NAME" &>/dev/null; then
|
||||
printf -v "$VAR_NAME" '%s' "$VAR_VALUE"
|
||||
log "Override: $VAR_NAME=$VAR_VALUE"
|
||||
else
|
||||
warn "Unknown variable $VAR_NAME, ignoring."
|
||||
fi
|
||||
case "$VAR_NAME" in
|
||||
LOG)
|
||||
if [[ "$VAR_VALUE" == "true" ]]; then
|
||||
ENABLE_LOGGING=true
|
||||
info "Verbose logging enabled"
|
||||
elif [[ "$VAR_VALUE" == "false" ]]; then
|
||||
ENABLE_LOGGING=false
|
||||
else
|
||||
warn "Invalid value for LOG: $VAR_VALUE (use true/false)"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if declare -p "$VAR_NAME" &>/dev/null; then
|
||||
printf -v "$VAR_NAME" '%s' "$VAR_VALUE"
|
||||
log "Overriding $VAR_NAME -> $VAR_VALUE"
|
||||
else
|
||||
warn "Unknown variable $VAR_NAME, ignoring."
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
else
|
||||
case "$ARG" in
|
||||
--dry-run|-n)
|
||||
DRY_RUN=true
|
||||
info "Dry-run mode enabled"
|
||||
;;
|
||||
LOG=true|--log)
|
||||
--log)
|
||||
ENABLE_LOGGING=true
|
||||
info "Verbose logging enabled"
|
||||
;;
|
||||
LOG=false)
|
||||
--no-log)
|
||||
ENABLE_LOGGING=false
|
||||
;;
|
||||
--help|-h)
|
||||
echo "Usage: script [--dry-run|-n] [LOG=true] [VAR=value ...]"
|
||||
echo "Usage: script <dir> [--dry-run|-n] [--log] [LOG=true] [VAR=value ...]"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
|
||||
Reference in New Issue
Block a user