Structure change and vissually fixing code to make it easier to read

This commit is contained in:
2026-03-26 22:35:44 +00:00
parent 84cdc6169b
commit 4ef4c1428c
14 changed files with 253 additions and 141 deletions
+88 -26
View File
@@ -1,37 +1,99 @@
#!/bin/bash
set -e
# ----------------------------------------------------------------------------------------------
# --------------------------------- Git, Pull & Exectute Script --------------------------------
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
# ----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
# Scripts now just contain runtime logic
#
# This new setup allows for profiles and arguments to use the core script
# ----------------------------------------------------------------------------------------------
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
#!/bin/bash
set -e
# -----------------------------
# Configurable variables
# -----------------------------
REPO_SSH="git@192.168.50.2:FailedProxy/Unraid_Scripts.git"
TARGET_DIR="/mnt/user/appdata/unraid_scripts"
SSH_KEY="/root/.ssh/id_gitea_rsync"
SSH_PORT=221
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Core System
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
parse_args "$@"
# Status Mode
echo "===== GIT SYNC STATUS ====="
echo "Repo: $REPO_SSH"
echo "Target: $TARGET_DIR"
echo "SSH Key: $SSH_KEY"
echo "SSH Port: $SSH_PORT"
echo "Logging: $ENABLE_LOGGING"
echo "Dry Run: $DRY_RUN"
echo "==========================="
exit 0
fi
# Validation
require_var REPO_SSH
require_var TARGET_DIR
require_var SSH_KEY
require_var SSH_PORT
# Start
info "Starting repository sync"
log "Repo: $REPO_SSH"
log "Target: $TARGET_DIR"
# -----------------------------
# Create target directory if it doesn't exist
# -----------------------------
mkdir -p "$TARGET_DIR"
cd "$TARGET_DIR"
# -----------------------------
# Clone or pull repo (discard local changes)
# -----------------------------
if [ -d ".git" ]; then
echo "Repository already exists. Resetting local changes and pulling latest..."
git reset --hard
git clean -fd
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" git pull
else
echo "Cloning $REPO_SSH into $TARGET_DIR..."
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" git clone "$REPO_SSH" .
# Dry Run
if [[ "$DRY_RUN" == true ]]; then
info "Dry-run mode enabled"
info "Would sync repository: $REPO_SSH"
info "Would target directory: $TARGET_DIR"
exit 0
fi
# -----------------------------
# Ensure scripts are executable
# -----------------------------
echo "Setting executable permissions on scripts..."
# Git Logic
if [[ -d ".git" ]]; then
info "Existing repo detected → updating"
log "git reset --hard"
git reset --hard
log "git clean -fd"
git clean -fd
info "Pulling latest changes..."
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" git pull
else
info "No repo found → cloning"
log "git clone $REPO_SSH"
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" \
git clone "$REPO_SSH" .
fi
# Permissions
info "Setting script permissions..."
find "$TARGET_DIR" -type f -name "*.sh" -exec chmod +x {} \;
echo "Repository is up to date and scripts are executable."
# Summary
echo "===== GIT SYNC SUMMARY ====="
echo "Repository: $REPO_SSH"
echo "Directory: $TARGET_DIR"
echo "Status: SUCCESS"
echo "Logging: $ENABLE_LOGGING"
echo "Dry Run: $DRY_RUN"
echo "============================"
info "Repository sync complete"