Files
glitch_bloodsugar/setup-remotes.sh
T

79 lines
2.3 KiB
Bash
Raw Normal View History

2026-03-24 11:30:14 +01:00
#!/bin/bash
# Sets up git remotes for all glitch-component folders and pushes to ramanujan.
#
# Usage:
# ./setup-remotes.sh # set remotes only
# ./setup-remotes.sh --push # set remotes and push all
#
# Reads GIT_USER / GIT_PASSWORD from ../.env if present, otherwise prompts.
set -e
REMOTE_HOST="ramanujan.glitch.university"
COMPONENTS_DIR="$(cd "$(dirname "$0")" && pwd)"
PUSH=false
[[ "$1" == "--push" ]] && PUSH=true
# ── Load credentials ──────────────────────────────────────────────────────────
ENV_FILE="$COMPONENTS_DIR/../gnommoweb/.env.prod"
if [ -f "$ENV_FILE" ]; then
GIT_USER=$(grep -E '^GIT_USER=' "$ENV_FILE" | cut -d= -f2 | tr -d '"'"'" | head -1)
GIT_PASSWORD=$(grep -E '^GIT_PASSWORD=' "$ENV_FILE" | cut -d= -f2 | tr -d '"'"'" | head -1)
fi
if [ -z "$GIT_USER" ] || [ -z "$GIT_PASSWORD" ]; then
read -rp "Git username: " GIT_USER
read -rsp "Git password: " GIT_PASSWORD
echo
fi
REMOTE_BASE="https://${GIT_USER}:${GIT_PASSWORD}@${REMOTE_HOST}"
# ── Process each component folder ─────────────────────────────────────────────
for dir in "$COMPONENTS_DIR"/*/; do
name=$(basename "$dir")
# Skip the skills folder and any non-component entries
[[ "$name" == "skills" ]] && continue
echo "── $name"
cd "$dir"
# Init if not already a git repo
if [ ! -d ".git" ]; then
git init -q
git add -A
git commit -q -m "Initial commit" 2>/dev/null || true
echo " initialised"
fi
# Add or update remote
if git remote get-url origin &>/dev/null; then
git remote set-url origin "${REMOTE_BASE}/${name}.git"
echo " remote updated"
else
git remote add origin "${REMOTE_BASE}/${name}.git"
echo " remote added"
fi
# Push
if $PUSH; then
if git push -u origin main -q 2>/dev/null || git push -u origin master:main -q 2>/dev/null; then
echo " pushed"
else
echo " push failed (repo may not exist on server yet)"
fi
fi
cd "$COMPONENTS_DIR"
done
echo ""
if $PUSH; then
echo "Done."
else
echo "Remotes configured. Run with --push to push all, or push individually."
fi