Files
glitch_bloodsugar/setup-remotes.sh
T

60 lines
1.2 KiB
Bash
Raw Normal View History

2026-03-24 11:30:14 +01:00
#!/bin/bash
set -e
REMOTE_HOST="ramanujan.glitch.university"
COMPONENTS_DIR="$(cd "$(dirname "$0")" && pwd)"
PUSH=false
[[ "$1" == "--push" ]] && PUSH=true
2026-04-01 22:36:42 +02:00
REMOTE_BASE="ssh://git@${REMOTE_HOST}/git/repos"
2026-03-24 11:30:14 +01:00
for dir in "$COMPONENTS_DIR"/*/; do
name=$(basename "$dir")
[[ "$name" == "skills" ]] && continue
echo "── $name"
cd "$dir"
if [ ! -d ".git" ]; then
git init -q
git add -A
git commit -q -m "Initial commit" 2>/dev/null || true
echo " initialised"
fi
2026-04-01 22:36:42 +02:00
REMOTE_URL="https://${REMOTE_HOST}/${name}.git"
2026-03-24 11:30:14 +01:00
if git remote get-url origin &>/dev/null; then
2026-04-01 22:36:42 +02:00
git remote set-url origin "$REMOTE_URL"
2026-03-24 11:30:14 +01:00
echo " remote updated"
else
2026-04-01 22:36:42 +02:00
git remote add origin "$REMOTE_URL"
2026-03-24 11:30:14 +01:00
echo " remote added"
fi
if $PUSH; then
2026-04-01 22:36:42 +02:00
if ssh git@"$REMOTE_HOST" create-repo "${name}.git" 2>/dev/null; then
echo " remote repo ensured"
else
echo " remote repo may already exist"
fi
2026-03-24 11:30:14 +01:00
if git push -u origin main -q 2>/dev/null || git push -u origin master:main -q 2>/dev/null; then
echo " pushed"
else
2026-04-01 22:36:42 +02:00
echo " push failed"
2026-03-24 11:30:14 +01:00
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