added notify to all needed in unraid essentials

This commit is contained in:
2026-04-09 17:20:09 -04:00
parent d12e034ef1
commit 6cc26c8fb9
11 changed files with 249 additions and 210 deletions
-134
View File
@@ -1,134 +0,0 @@
#!/bin/bash
# -----------------------------------------------------------------------------------------------
# --------------------------------- Git Pull & Execute Script -----------------------------------
# -----------------------------------------------------------------------------------------------
# Pulls latest scripts from Gitea repo via SSH.
# Uses GITEA_SSH_KEY and SSH_PORT from Master.conf.
# Supports --dry-run, --log, --status flags via common.sh parse_args.
# -----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
parse_args "$@"
# -----------------------------------------------------------------------------------------------
# STATUS MODE
# -----------------------------------------------------------------------------------------------
if [[ "$SHOW_STATUS" == true ]]; then
echo
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " $ICON_SUMMARY GIT SYNC STATUS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " $ICON_GEAR Repo: $REPO_SSH"
echo " $ICON_GEAR Target: $TARGET_DIR"
echo " $ICON_GEAR SSH Key: $GITEA_SSH_KEY"
echo " $ICON_GEAR SSH Port: $SSH_PORT"
echo " $ICON_INFO Dry Run: $DRY_RUN"
echo " $ICON_INFO Logging: $ENABLE_LOGGING"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
exit 0
fi
# -----------------------------------------------------------------------------------------------
# VALIDATION
# -----------------------------------------------------------------------------------------------
require_var REPO_SSH
require_var TARGET_DIR
require_var GITEA_SSH_KEY
require_var SSH_PORT
# -----------------------------------------------------------------------------------------------
# HEADER
# -----------------------------------------------------------------------------------------------
echo
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " $ICON_RUN GIT SYNC STARTING"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
info "$ICON_GEAR Repo: $REPO_SSH"
info "$ICON_GEAR Target: $TARGET_DIR"
info "$ICON_INFO Dry Run: $DRY_RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log "Repo: $REPO_SSH"
log "Target: $TARGET_DIR"
# -----------------------------------------------------------------------------------------------
# DRY RUN
# -----------------------------------------------------------------------------------------------
if [[ "$DRY_RUN" == true ]]; then
echo
warn "Dry-run enabled — no changes will be made"
info "Would sync: $REPO_SSH"
info "Would target: $TARGET_DIR"
echo
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " $ICON_SUMMARY GIT SYNC SUMMARY"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " $ICON_GEAR Repo: $REPO_SSH"
echo " $ICON_GEAR Target: $TARGET_DIR"
echo " $ICON_WARN Status: DRY RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
exit 0
fi
# -----------------------------------------------------------------------------------------------
# MAIN EXECUTION
# -----------------------------------------------------------------------------------------------
START_TIME=$(date +%s)
mkdir -p "$TARGET_DIR"
cd "$TARGET_DIR"
if [[ -d ".git" ]]; then
info "$ICON_SYNC Existing repository detected — updating"
log "git reset --hard"
git reset --hard
log "git clean -fd"
git clean -fd
info "$ICON_RUN Pulling latest changes..."
if GIT_SSH_COMMAND="ssh -i $GITEA_SSH_KEY -p $SSH_PORT" git pull; then
success "Git pull successful"
else
error "Git pull failed"
exit 1
fi
else
info "$ICON_SYNC No repository found — cloning"
if GIT_SSH_COMMAND="ssh -i $GITEA_SSH_KEY -p $SSH_PORT" git clone "$REPO_SSH" .; then
success "Clone successful"
else
error "Clone failed"
exit 1
fi
fi
# -----------------------------------------------------------------------------------------------
# PERMISSIONS
# -----------------------------------------------------------------------------------------------
info "$ICON_GEAR Setting executable permissions..."
find "$TARGET_DIR" -type f -name "*.sh" -exec chmod +x {} \;
success "Permissions applied"
# -----------------------------------------------------------------------------------------------
# SUMMARY
# -----------------------------------------------------------------------------------------------
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
echo
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " $ICON_SUMMARY GIT SYNC SUMMARY"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " $ICON_GEAR Repo: $REPO_SSH"
echo " $ICON_GEAR Target: $TARGET_DIR"
echo " $ICON_TIME Duration: $(format_duration $DURATION)"
echo " $ICON_SUCCESS Status: SUCCESS"
echo " $ICON_INFO Dry Run: $DRY_RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
success "Repository sync complete"
+31 -29
View File
@@ -4,50 +4,50 @@
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
# -----------------------------------------------------------------------------------------------
# Separate the positional directory argument from flag/key=value args.
# Flags and key=value pairs are passed to parse_args — directory is handled here.
# -----------------------------------------------------------------------------------------------
DIRECTORY=""
RAW_ARGS=()
for ARG in "$@"; do
case "$ARG" in
--*|*=*) RAW_ARGS+=("$ARG") ;;
*) [[ -z "$DIRECTORY" ]] && DIRECTORY="$ARG" || RAW_ARGS+=("$ARG") ;;
esac
done
parse_args "${RAW_ARGS[@]}"
[[ -z "$DIRECTORY" ]] && error "No directory specified. Usage: rsync.sh <dir> [--dry-run] [--log]" && exit 1
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_GEAR Setup ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_GEAR Setup ━━━"
detect_hosts
resolve_remote_ip
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SHIELD Pre-flight Checks ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_SHIELD Pre-flight Checks ━━━"
check_connectivity
check_remote_rootfs
check_remote_share "$DIRECTORY"
check_remote_disks "$DIRECTORY"
# -----------------------------------------------------------------------------------------------
# Profile is inferred from the directory basename (lowercased)
# e.g. /mnt/user/appdata-Failover/Arrs_Stack → arrs_stack
@@ -55,28 +55,28 @@ check_remote_disks "$DIRECTORY"
echo ""
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
info "$ICON_GEAR Loading profile: $PROFILE_NAME"
# Scalar overrides — use profile value if defined, fall back to global default
BW_LIMIT=${PROFILE_BW_LIMIT[$PROFILE_NAME]:-$BW_LIMIT}
RETRY_COUNT=${PROFILE_RETRY_COUNT[$PROFILE_NAME]:-$RETRY_COUNT}
SLEEP=${PROFILE_SLEEP[$PROFILE_NAME]:-$SLEEP}
CONTAINER_DELAY=${PROFILE_CONTAINER_DELAY[$PROFILE_NAME]:-$CONTAINER_DELAY}
# Array overrides — profile strings must be converted to bash arrays before use
read -r -a CRITICAL_CONTAINER_NAMES <<< "${PROFILE_CRITICAL_CONTAINER_NAMES[$PROFILE_NAME]:-}"
read -r -a DELAYED_CONTAINERS <<< "${PROFILE_DELAYED_CONTAINERS[$PROFILE_NAME]:-}"
read -r -a EXCLUDE_DIRS <<< "${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]:-}"
[[ "$SHOW_STATUS" == true ]] && show_status && exit 0
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_STOP $ICON_CONTAINERS Containers ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_STOP $ICON_CONTAINERS Containers ━━━"
stop_containers
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SYNC Transfer ━━━
# -----------------------------------------------------------------------------------------------
@@ -86,22 +86,22 @@ echo "$ICON_RUN Source: $DIRECTORY"
echo "$ICON_NET Remote: $REMOTE_SERVER:$DIRECTORY"
echo "$ICON_GEAR Profile: $PROFILE_NAME"
echo ""
get_rsync_opts
# Append profile excludes to rsync options
for ex in "${EXCLUDE_DIRS[@]}"; do
[[ -n "$ex" ]] && RSYNC_OPTS+=(--exclude="$ex")
done
[[ "$DRY_RUN" == true ]] && RSYNC_OPTS+=("--dry-run") && warn "DRY RUN — no changes will be made"
START=$(date +%s)
RSYNC_SUCCESS=false
for i in $(seq 1 "$RETRY_COUNT"); do
info "$ICON_RETRY Attempt $i of $RETRY_COUNT..."
# dirname "$DIRECTORY" is intentional — rsync places the directory itself on the remote
# e.g. source /mnt/user/Movies syncs to remote /mnt/user/Movies (not /mnt/user/Movies/Movies)
if rsync "${RSYNC_OPTS[@]}" \
@@ -115,19 +115,19 @@ for i in $(seq 1 "$RETRY_COUNT"); do
[[ "$i" -lt "$RETRY_COUNT" ]] && info "Retrying in ${SLEEP}s..." && sleep "$SLEEP"
fi
done
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_START $ICON_CONTAINERS Containers ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_START $ICON_CONTAINERS Containers ━━━"
start_containers
END=$(date +%s)
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Summary ━━━
# ━━━ Summary ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━━━ $ICON_SUMMARY SUMMARY ━━━━━"
@@ -136,10 +136,12 @@ echo "$ICON_GEAR Profile: $PROFILE_NAME"
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
if [[ "$RSYNC_SUCCESS" == true ]]; then
echo "$ICON_DONE Status: $ICON_SUCCESS DONE"
notify "Rsync complete — $DIRECTORY ($PROFILE_NAME) in $(format_duration $((END - START)))" "Rsync" "normal"
else
echo "$ICON_ERROR Status: $ICON_ERROR FAILED after $RETRY_COUNT attempts"
notify "Rsync failed — $DIRECTORY ($PROFILE_NAME) after $RETRY_COUNT attempts" "Rsync" "warning"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━"
[[ "$RSYNC_SUCCESS" == false ]] && exit 1
exit 0