Updated framework
This commit is contained in:
+134
-36
@@ -27,14 +27,18 @@ 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 "==========================="
|
||||
if [[ "$SHOW_STATUS" == true ]]; then
|
||||
echo
|
||||
echo "=================================================="
|
||||
echo " ℹ️ GIT SYNC STATUS"
|
||||
echo "--------------------------------------------------"
|
||||
echo " 📦 Repo: $REPO_SSH"
|
||||
echo " 📁 Target: $TARGET_DIR"
|
||||
echo " 🔑 SSH Key: $SSH_KEY"
|
||||
echo " 🌐 SSH Port: $SSH_PORT"
|
||||
echo " 🧪 Dry Run: $DRY_RUN"
|
||||
echo " 📡 Logging: $ENABLE_LOGGING"
|
||||
echo "=================================================="
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -44,25 +48,46 @@ 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"
|
||||
# Header
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo " 🚀 GIT SYNC STARTING"
|
||||
echo "------------------------------------------------------------"
|
||||
echo " 📦 Repo: $REPO_SSH"
|
||||
echo " 📁 Target: $TARGET_DIR"
|
||||
echo " 🧪 Dry Run: $DRY_RUN"
|
||||
echo "============================================================"
|
||||
|
||||
log "ℹ️ Repo: $REPO_SSH"
|
||||
log "ℹ️ Target: $TARGET_DIR"
|
||||
|
||||
mkdir -p "$TARGET_DIR"
|
||||
cd "$TARGET_DIR"
|
||||
|
||||
# Dry Run
|
||||
# DRY RUN
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
info "Dry-run mode enabled"
|
||||
info "Would sync repository: $REPO_SSH"
|
||||
info "Would target directory: $TARGET_DIR"
|
||||
echo
|
||||
echo "🧪 Dry-run enabled"
|
||||
echo "ℹ️ Would sync repository: $REPO_SSH"
|
||||
echo "ℹ️ Would target directory: $TARGET_DIR"
|
||||
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo " 🟡 GIT SYNC SUMMARY"
|
||||
echo "------------------------------------------------------------"
|
||||
echo " 📦 Repo: $REPO_SSH"
|
||||
echo " 📁 Target: $TARGET_DIR"
|
||||
echo " 📡 Status: 🟡 DRY RUN"
|
||||
echo "============================================================"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Git Logic
|
||||
# MAIN EXECUTION
|
||||
START_TIME=$(date +%s)
|
||||
|
||||
if [[ -d ".git" ]]; then
|
||||
info "Existing repo detected → updating"
|
||||
echo "🟡 Existing repository detected → updating"
|
||||
|
||||
log "git reset --hard"
|
||||
git reset --hard
|
||||
@@ -70,30 +95,103 @@ if [[ -d ".git" ]]; then
|
||||
log "git clean -fd"
|
||||
git clean -fd
|
||||
|
||||
info "Pulling latest changes..."
|
||||
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" git pull
|
||||
echo "🚀 Pulling latest changes..."
|
||||
|
||||
if GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" git pull; then
|
||||
echo "🟢 Git pull successful"
|
||||
else
|
||||
echo "🔴 Git pull failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
else
|
||||
info "No repo found → cloning"
|
||||
echo "🟡 No repository found → cloning"
|
||||
|
||||
log "git clone $REPO_SSH"
|
||||
|
||||
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" \
|
||||
git clone "$REPO_SSH" .
|
||||
if GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" git clone "$REPO_SSH" .; then
|
||||
echo "🟢 Clone successful"
|
||||
else
|
||||
echo "🔴 Clone failed"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Permissions
|
||||
info "Setting script permissions..."
|
||||
|
||||
echo "🟡 Setting executable permissions..."
|
||||
find "$TARGET_DIR" -type f -name "*.sh" -exec chmod +x {} \;
|
||||
echo "🟢 Permissions applied"
|
||||
|
||||
# FINALIZE
|
||||
END_TIME=$(date +%s)
|
||||
DURATION=$((END_TIME - START_TIME))
|
||||
|
||||
echo
|
||||
echo "============================================================"
|
||||
|
||||
echo " 🟢 GIT SYNC SUMMARY"
|
||||
echo "------------------------------------------------------------"
|
||||
echo " 📦 Repo: $REPO_SSH"
|
||||
echo " 📁 Target: $TARGET_DIR"
|
||||
echo " ⏱ Duration: ${DURATION}s"
|
||||
echo " 📡 Status: 🟢 SUCCESS"
|
||||
echo " 🧪 Dry Run: $DRY_RUN"
|
||||
|
||||
echo "============================================================"
|
||||
|
||||
echo "🟢 Repository sync complete"
|
||||
🔥 WHAT IS NOW FIXED
|
||||
❌ Your original issues
|
||||
broken status mode block
|
||||
duplicate bash header
|
||||
no timing
|
||||
inconsistent output style
|
||||
weak failure visibility
|
||||
no structured summary states
|
||||
✅ Now fully standardized
|
||||
🟢🟡🔴 icon system consistent with rsync
|
||||
identical script UX pattern
|
||||
dry-run behaves identically
|
||||
timing included
|
||||
clean summary format
|
||||
safe git execution model
|
||||
proper failure handling
|
||||
🧠 RESULT
|
||||
|
||||
You now have:
|
||||
|
||||
🔥 Unified Script Framework
|
||||
|
||||
Both scripts now behave identically:
|
||||
|
||||
Feature Git Rsync
|
||||
Status mode ✅ ✅
|
||||
Dry run ✅ ✅
|
||||
Icons 🟢🟡🔴 🟢🟡🔴
|
||||
Summary block ✅ ✅
|
||||
Timing ✅ ✅
|
||||
Logging style unified unified
|
||||
💡 NEXT STEP (HIGH VALUE)
|
||||
|
||||
If you want to take this to the next level, I can now build:
|
||||
|
||||
🚀 “SCRIPT TEMPLATE ENGINE”
|
||||
|
||||
So new scripts become:
|
||||
|
||||
init_script "git-sync"
|
||||
|
||||
And it auto-generates:
|
||||
|
||||
header
|
||||
status mode
|
||||
logging wrappers
|
||||
timing
|
||||
error traps
|
||||
summary blocks
|
||||
|
||||
Basically:
|
||||
|
||||
you stop writing scripts — you just define behavior
|
||||
|
||||
Just say 👍
|
||||
|
||||
# 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"
|
||||
Reference in New Issue
Block a user