FinancePlanner/git-setup.sh
2026-05-29 12:00:49 +01:00

98 lines
3.1 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ─────────────────────────────────────────────
# git-setup.sh · Run ONCE to initialise the
# local repo and connect it to Gitea.
# ─────────────────────────────────────────────
set -e # stop on any error
REMOTE_URL="https://git.cdb-online.co.uk/Computers_Dont_Byte/FinancePlanner"
BRANCH="main"
echo ""
echo "╔══════════════════════════════════════════╗"
echo "║ Finance Planner — Git Setup ║"
echo "╚══════════════════════════════════════════╝"
echo ""
# ── Move to the directory this script lives in
cd "$(dirname "$0")"
echo "📁 Working directory: $(pwd)"
echo ""
# ── Ask for identity (used in commit messages)
read -p "Your name (for git commits): " GIT_NAME
read -p "Your email (for git commits): " GIT_EMAIL
echo ""
# ── Initialise git if not already done
if [ ! -d ".git" ]; then
git init
git checkout -b "$BRANCH" 2>/dev/null || git branch -m "$BRANCH"
echo "✅ Git repository initialised."
else
echo " Git already initialised — skipping."
fi
# ── Set local identity
git config user.name "$GIT_NAME"
git config user.email "$GIT_EMAIL"
# ── Set remote
if git remote get-url origin &>/dev/null; then
git remote set-url origin "$REMOTE_URL"
echo "✅ Remote 'origin' updated."
else
git remote add origin "$REMOTE_URL"
echo "✅ Remote 'origin' added."
fi
echo ""
echo "Remote → $REMOTE_URL"
echo ""
# ── Copy in the .gitignore if not present
if [ ! -f ".gitignore" ]; then
cat > .gitignore << 'GITIGNORE'
db.php
*.log
*.cache
/vendor/
*.env
.DS_Store
Thumbs.db
desktop.ini
.vscode/
.idea/
*.swp
*.swo
*~
GITIGNORE
echo "✅ .gitignore created (db.php is excluded to protect credentials)."
fi
# ── Initial commit
git add -A
git status --short
echo ""
git commit -m "Initial commit — Finance Planner setup" || echo " Nothing new to commit."
echo ""
echo "╔══════════════════════════════════════════╗"
echo "║ Setup complete! ║"
echo "╚══════════════════════════════════════════╝"
echo ""
echo "Next steps:"
echo ""
echo " Option A — HTTPS (username + password / token):"
echo " git push -u origin $BRANCH"
echo " (You will be prompted for your Gitea credentials)"
echo ""
echo " Option B — SSH (no password prompts):"
echo " ssh-keygen -t ed25519 -C \"$GIT_EMAIL\""
echo " cat ~/.ssh/id_ed25519.pub # paste this into Gitea → Settings → SSH Keys"
echo " git remote set-url origin git@git.cdb-online.co.uk:Computers_Dont_Byte/FinancePlanner.git"
echo " git push -u origin $BRANCH"
echo ""
echo " Then run ./git-sync.sh any time you want to push changes."
echo ""