Added saudo priviliges with flag --sudo

master
Kynsight 3 days ago
parent 561f4ff265
commit 190d7f2c4a

@ -25,7 +25,7 @@ get_flag() {
VALID_FLAGS=(
"source" "target" "dry-run" "verbose" "compress" "system"
"ssh-send" "ssh-receive" "link" "ntfs" "name" "exclude"
"progress"
"progress" "sudo"
)
# ----------------------------------------------------------------------------
@ -81,6 +81,7 @@ COMPRESS=false
SYSTEM=false
NTFS=false
PROGRESS=false
SUDO_PRIV=flase
get_flag "dry-run" && DRY_RUN=true
get_flag "verbose" && VERBOSE=true
@ -88,6 +89,7 @@ get_flag "compress" && COMPRESS=true
get_flag "system" && SYSTEM=true
get_flag "ntfs" && NTFS=true
get_flag "progress" && PROGRESS=true
get_flag "sudo" && SUDO_PRIV=true
# ----------------------------------------------------------------------------
# Required argument checks
@ -109,17 +111,6 @@ else
TARGET_PATH="${TARGET[0]}"
fi
# -----------------------------------------------------------------------------
# Prevent recursive backup of target inside source (Ask me how I Know)
# -----------------------------------------------------------------------------
if [[ "${SOURCE[0]}" == "/" || "${SOURCE[0]}" == /* ]]; then
# Resolve absolute target path
TARGET_REAL=$(realpath "$TARGET_PATH")
if [[ "$TARGET_REAL" == "${SOURCE[0]}"* ]]; then
EXCLUDES+=("$TARGET_REAL")
fi
fi
# ----------------------------------------------------------------------------
# SSH configuration (push or pull)
@ -167,6 +158,23 @@ if [[ "$SYSTEM" == true ]]; then
EXCLUDES+=("${SYSTEM_EXCLUDES[@]}")
fi
# -----------------------------------------------------------------------------
# Prevent recursive backup of target inside source and Link (Ask me how I Know)
# -----------------------------------------------------------------------------
if [[ "${SOURCE[0]}" == "/" || "${SOURCE[0]}" == /* ]]; then
# Resolve absolute target path
TARGET_REAL=$(realpath "$TARGET_PATH")
if [[ "$TARGET_REAL" == "${SOURCE[0]}"* ]]; then
EXCLUDES+=("$TARGET_REAL")
fi
fi
if [[ -n "$LINK_DIR" ]]; then
# Automatically exclude the link destination itself
EXCLUDES+=("$LINK_DIR")
fi
# ----------------------------------------------------------------------------
# Build rsync command
# ----------------------------------------------------------------------------
@ -180,6 +188,7 @@ fi
[[ "$PROGRESS" == true ]] && CMD+=("-P")
[[ "$PROGRESS" == false ]] && CMD+=("--partial")
[[ "$SUDO_PRIV" == true ]] && CMD+=("--rsync-path=\"sudo rsync\"")
CMD+=("--delete-excluded")

Loading…
Cancel
Save