Structure change and vissually fixing code to make it easier to read
This commit is contained in:
@@ -12,7 +12,12 @@ in unRAID User Scripts, to use scripts in git
|
||||
add a line pointing to script plus local folder to be synced
|
||||
Exampl = /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-test/Arrs/
|
||||
|
||||
This opens the script and passes the folder overas an argument
|
||||
This opens the script and passes the folder over as an argument
|
||||
This allows for multiple rsync ops running off a single core script
|
||||
|
||||
All changes made to 1 single core script then works for all user scripts that point to rsync.sh
|
||||
|
||||
The Master.conf file is where all user changeable variables live, This is for all scripts
|
||||
|
||||
A common.sh file also is used to share all common codes that multiple scripts use
|
||||
This allows for easier managment of scripts, editing, and what not
|
||||
+88
-26
@@ -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"
|
||||
+24
-7
@@ -1,5 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# --------------------------------- Rsync Core 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
|
||||
#
|
||||
# Use arguments in unRAID User Plugin for directory
|
||||
# Example = /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
@@ -7,7 +24,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/../Master.conf"
|
||||
source "$SCRIPT_DIR/../common.sh"
|
||||
|
||||
# ----------------------------- Input -----------------------------
|
||||
# Input
|
||||
DIRECTORY="$1"
|
||||
if [[ -z "$DIRECTORY" ]]; then
|
||||
echo "Usage: $0 <directory-to-sync> [--dry-run] [VAR=value ...]"
|
||||
@@ -16,11 +33,11 @@ fi
|
||||
shift
|
||||
parse_args "$@"
|
||||
|
||||
# ----------------------------- Host & IP -----------------------------
|
||||
# Host & IP
|
||||
detect_hosts
|
||||
resolve_remote_ip
|
||||
|
||||
# ----------------------------- Profile -----------------------------
|
||||
# Profile
|
||||
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
MAX_RSYNC_PROCS=${PROFILE_MAX_PROCS[$PROFILE_NAME]:-$MAX_RSYNC_PROCS}
|
||||
@@ -32,14 +49,14 @@ RETRY_COUNT=${PROFILE_RETRY_COUNT[$PROFILE_NAME]:-$RETRY_COUNT}
|
||||
SLEEP=${PROFILE_SLEEP[$PROFILE_NAME]:-$SLEEP}
|
||||
EXCLUDE_DIRS=(${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]:-${EXCLUDE_DIRS[@]}})
|
||||
|
||||
# ----------------------------- Status Mode -----------------------------
|
||||
# Status Mode
|
||||
if [[ "$SHOW_STATUS" == true ]]; then
|
||||
show_status
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# ----------------------------- User Info -----------------------------
|
||||
# User Info
|
||||
echo "============================================================"
|
||||
echo " Sync Job Starting"
|
||||
echo "------------------------------------------------------------"
|
||||
@@ -53,7 +70,7 @@ log "Settings: MAX_RSYNC_PROCS=$MAX_RSYNC_PROCS, BW_LIMIT=$BW_LIMIT"
|
||||
log "Containers: ${CRITICAL_CONTAINER_NAMES[*]}"
|
||||
log "Excludes: ${EXCLUDE_DIRS[*]}"
|
||||
|
||||
# ----------------------------- Rsync Wait -----------------------------
|
||||
# Rsync Wait
|
||||
wait_for_rsync() {
|
||||
for attempt in $(seq 1 "$RETRY_COUNT"); do
|
||||
RSYNC_COUNT=$(pgrep -fc "rsync.*root@${REMOTE_SERVER}" || true)
|
||||
@@ -69,7 +86,7 @@ wait_for_rsync() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ----------------------------- Main -----------------------------
|
||||
# Main
|
||||
main() {
|
||||
echo ""
|
||||
echo "🔍 Checking remote connectivity..."
|
||||
|
||||
+25
-22
@@ -1,17 +1,20 @@
|
||||
!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#------------------------------------- Rsync command -------------------------------------------
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# ------------------------------------ Rsync command -------------------------------------------
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
|
||||
/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-test/Arrs/
|
||||
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#-------------------------------------------- Info ---------------------------------------------
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# ------------------------------------------- Info ---------------------------------------------
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
#
|
||||
# These global configuartions can be added as arguments at the end of the script after folder location
|
||||
#
|
||||
# Its better to add profile in Master.conf for perm changes
|
||||
#
|
||||
# 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
|
||||
|
||||
@@ -20,15 +23,15 @@
|
||||
#----------------------------- Arguments, add after rsync command ------------------------------
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
# Does a dry run making no changes
|
||||
#--dry-run
|
||||
# --dry-run
|
||||
#
|
||||
#Force logging
|
||||
#--log)
|
||||
# Force logging
|
||||
# --log)
|
||||
#
|
||||
#Force logging to be dissabled
|
||||
#--no-log
|
||||
# Force logging to be dissabled
|
||||
# --no-log
|
||||
#
|
||||
#--help
|
||||
# --help
|
||||
#
|
||||
# Example = /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-test/Arrs/ --dry-run --no-log
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
@@ -37,32 +40,32 @@
|
||||
#
|
||||
#
|
||||
# Network speed limit (KB/s)
|
||||
#BW_LIMIT=12500
|
||||
# BW_LIMIT=12500
|
||||
#
|
||||
# Retry logic
|
||||
#RETRY_COUNT=3
|
||||
# RETRY_COUNT=3
|
||||
#
|
||||
# Sleep between retries (seconds)
|
||||
#SLEEP=300
|
||||
# SLEEP=300
|
||||
#
|
||||
# Max number of concurrently running rsync processes
|
||||
#MAX_RSYNC_PROCS=1
|
||||
# MAX_RSYNC_PROCS=1
|
||||
#
|
||||
# Container start/stop/restart before and after rsync
|
||||
#CRITICAL_CONTAINER_NAMES=()
|
||||
# CRITICAL_CONTAINER_NAMES=()
|
||||
#
|
||||
# Containers that need delayed before starting
|
||||
#DELAYED_CONTAINERS=()
|
||||
# DELAYED_CONTAINERS=()
|
||||
#
|
||||
# Delay in seconds between starting containers, useful for things like Authelia
|
||||
#CONTAINER_DELAY=5
|
||||
# CONTAINER_DELAY=5
|
||||
#
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#---------------End Of User Variables, Please adjust in Master.cong as needed ------------------
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#
|
||||
#Examples
|
||||
#/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-test/Arrs/ MAX_RSYNC_PROCS=2
|
||||
#/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-test/Arrs/ --dry-run MAX_RSYNC_PROCS=2
|
||||
# Examples
|
||||
# /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-test/Arrs/ MAX_RSYNC_PROCS=2
|
||||
# /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-test/Arrs/ --dry-run MAX_RSYNC_PROCS=2
|
||||
#
|
||||
# Copy and paste into unRAID User Script plugin
|
||||
Reference in New Issue
Block a user