generated from projects/testosmaximus
63 lines
1.7 KiB
Bash
Executable File
63 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
TEMPLATE_REMOTE="git@git.chipperfluff.at:projects/funkyFlaskTest.git"
|
|
CONFIRM_MODULE=""
|
|
SELF_PATH="$0"
|
|
|
|
# === Parse CLI args ===
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--confirm) CONFIRM_MODULE="$2"; shift ;;
|
|
--help)
|
|
echo "Usage: ./reset.sh [--confirm your-current-module-name]"
|
|
echo "Wipes current repo and resets to template:"
|
|
echo " $TEMPLATE_REMOTE"
|
|
exit 0 ;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
exit 1 ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# === Detect current module name from package.json ===
|
|
if [[ ! -f source/package.json ]]; then
|
|
echo "❌ Can't find source/package.json. Not a proper squirrel module?"
|
|
exit 1
|
|
fi
|
|
|
|
CURRENT_NAME=$(jq -r '.name' source/package.json)
|
|
|
|
# === Confirm the name matches or prompt ===
|
|
if [[ -z "$CONFIRM_MODULE" ]]; then
|
|
read -rp "⚠️ Type the current module name to confirm reset ($CURRENT_NAME): " CONFIRM_MODULE
|
|
fi
|
|
|
|
if [[ "$CONFIRM_MODULE" != "$CURRENT_NAME" ]]; then
|
|
echo "🛑 Confirmation failed. You typed '$CONFIRM_MODULE', but module is '$CURRENT_NAME'."
|
|
exit 1
|
|
fi
|
|
|
|
echo "🧨 Confirmed. Resetting module '$CURRENT_NAME' to template."
|
|
|
|
# === Ensure git repo exists ===
|
|
if [[ ! -d .git ]]; then
|
|
echo "📁 No git repo found. Initializing..."
|
|
git init
|
|
git remote add origin "$TEMPLATE_REMOTE"
|
|
fi
|
|
|
|
# === Ensure correct remote is set ===
|
|
if ! git remote get-url origin | grep -q "$TEMPLATE_REMOTE"; then
|
|
echo "🔗 Setting template remote to $TEMPLATE_REMOTE"
|
|
git remote set-url origin "$TEMPLATE_REMOTE"
|
|
fi
|
|
|
|
# === Reset hard to remote ===
|
|
echo "🔥 Fetching template and resetting..."
|
|
git fetch origin
|
|
git reset --hard origin/HEAD
|
|
|
|
echo "✅ Reset complete. Your sins have been erased."
|