improved args
This commit is contained in:
@@ -14,13 +14,27 @@
|
|||||||
# Profiles in Master.conf match the last string of folder location
|
# 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 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
|
# 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 ----------------------
|
#----------------- User Variables, Please adjust in Master.cong as needed ----------------------
|
||||||
#-----------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Does a dry run making no changes
|
|
||||||
#--dry-run
|
|
||||||
#
|
#
|
||||||
# Network speed limit (KB/s)
|
# Network speed limit (KB/s)
|
||||||
#BW_LIMIT=12500
|
#BW_LIMIT=12500
|
||||||
|
|||||||
@@ -25,33 +25,49 @@ log() {
|
|||||||
|
|
||||||
parse_args() {
|
parse_args() {
|
||||||
DRY_RUN=${DRY_RUN:-false}
|
DRY_RUN=${DRY_RUN:-false}
|
||||||
|
ENABLE_LOGGING=${ENABLE_LOGGING:-false}
|
||||||
|
|
||||||
for ARG in "$@"; do
|
for ARG in "$@"; do
|
||||||
if [[ "$ARG" == *=* ]]; then
|
if [[ "$ARG" == *=* ]]; then
|
||||||
VAR_NAME="${ARG%%=*}"
|
VAR_NAME="${ARG%%=*}"
|
||||||
VAR_VALUE="${ARG#*=}"
|
VAR_VALUE="${ARG#*=}"
|
||||||
|
|
||||||
|
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
|
if declare -p "$VAR_NAME" &>/dev/null; then
|
||||||
printf -v "$VAR_NAME" '%s' "$VAR_VALUE"
|
printf -v "$VAR_NAME" '%s' "$VAR_VALUE"
|
||||||
log "Override: $VAR_NAME=$VAR_VALUE"
|
log "Overriding $VAR_NAME -> $VAR_VALUE"
|
||||||
else
|
else
|
||||||
warn "Unknown variable $VAR_NAME, ignoring."
|
warn "Unknown variable $VAR_NAME, ignoring."
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
else
|
else
|
||||||
case "$ARG" in
|
case "$ARG" in
|
||||||
--dry-run|-n)
|
--dry-run|-n)
|
||||||
DRY_RUN=true
|
DRY_RUN=true
|
||||||
info "Dry-run mode enabled"
|
info "Dry-run mode enabled"
|
||||||
;;
|
;;
|
||||||
LOG=true|--log)
|
--log)
|
||||||
ENABLE_LOGGING=true
|
ENABLE_LOGGING=true
|
||||||
info "Verbose logging enabled"
|
info "Verbose logging enabled"
|
||||||
;;
|
;;
|
||||||
LOG=false)
|
--no-log)
|
||||||
ENABLE_LOGGING=false
|
ENABLE_LOGGING=false
|
||||||
;;
|
;;
|
||||||
--help|-h)
|
--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
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|||||||
Reference in New Issue
Block a user