Files
Varaverk/Rsync/git_pull_execute.sh
T

99 lines
2.6 KiB
Bash

#!/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
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"
mkdir -p "$TARGET_DIR"
cd "$TARGET_DIR"
# 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
# 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 {} \;
# 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"