102 lines
2.5 KiB
Bash
102 lines
2.5 KiB
Bash
#!/bin/bash
|
|
###############################################################################
|
|
# forgejo_sync.sh
|
|
#
|
|
# Interactive git sync tool for KingDezigns "07 - Projects" folders on NAS16.
|
|
# Prompts for which folder to update and a free-form commit description,
|
|
# then pulls, stages, commits, and pushes the changes to Forgejo.
|
|
#
|
|
# Usage: run directly and follow the prompts.
|
|
# ./forgejo_sync.sh
|
|
###############################################################################
|
|
|
|
set -uo pipefail
|
|
|
|
# Auto-exit helper function: sleeps 10 seconds and exits
|
|
auto_exit() {
|
|
local status="${1:-0}"
|
|
echo ""
|
|
echo "Closing terminal window in 10 seconds..."
|
|
sleep 10
|
|
exit "$status"
|
|
}
|
|
|
|
PROJECTS_ROOT="/export/kingdezignsnas-16/Public/07 - Projects"
|
|
|
|
declare -A FOLDER_MAP=(
|
|
[1]="NAS08"
|
|
[2]="NAS16"
|
|
[3]="PLEX32"
|
|
[4]="Infrastructure"
|
|
)
|
|
|
|
echo "Which folder would you like to update?"
|
|
echo " 1) NAS08"
|
|
echo " 2) NAS16"
|
|
echo " 3) PLEX32"
|
|
echo " 4) Infrastructure"
|
|
echo ""
|
|
read -rp "Enter selection [1-4]: " SELECTION
|
|
|
|
FOLDER="${FOLDER_MAP[$SELECTION]:-}"
|
|
|
|
if [ -z "$FOLDER" ]; then
|
|
echo "Invalid selection. Exiting."
|
|
auto_exit 1
|
|
fi
|
|
|
|
REPO_PATH="$PROJECTS_ROOT/$FOLDER"
|
|
|
|
if [ ! -d "$REPO_PATH" ]; then
|
|
echo "ERROR: Folder not found at: $REPO_PATH"
|
|
auto_exit 1
|
|
fi
|
|
|
|
if [ ! -d "$REPO_PATH/.git" ]; then
|
|
echo "ERROR: '$FOLDER' is not yet a git repository (no .git found)."
|
|
echo "This folder needs one-time setup first — create the org/repo in"
|
|
echo "Forgejo, then run: git init && git remote add origin <url>"
|
|
auto_exit 1
|
|
fi
|
|
|
|
cd "$REPO_PATH" || auto_exit 1
|
|
|
|
echo ""
|
|
echo "Pulling latest changes for $FOLDER..."
|
|
if ! git pull --no-edit; then
|
|
echo "ERROR: git pull failed — likely a conflict. Resolve manually before continuing."
|
|
auto_exit 1
|
|
fi
|
|
|
|
if [ -z "$(git status --porcelain)" ]; then
|
|
echo "No changes detected in $FOLDER. Nothing to commit."
|
|
auto_exit 0
|
|
fi
|
|
|
|
echo ""
|
|
echo "Changed files:"
|
|
git status --short
|
|
echo ""
|
|
|
|
read -rp "Enter a description for this change: " DESCRIPTION
|
|
|
|
if [ -z "$DESCRIPTION" ]; then
|
|
echo "A description is required. Exiting without committing."
|
|
auto_exit 1
|
|
fi
|
|
|
|
git add -A
|
|
git commit -m "$DESCRIPTION"
|
|
|
|
echo ""
|
|
echo "Pushing to Forgejo..."
|
|
if git push origin main; then
|
|
echo ""
|
|
echo "SUCCESS: $FOLDER updated and pushed."
|
|
auto_exit 0
|
|
else
|
|
echo ""
|
|
echo "ERROR: push failed. Your commit was saved locally — retry with:"
|
|
echo " cd \"$REPO_PATH\" && git push origin main"
|
|
auto_exit 1
|
|
fi
|