#!/bin/bash set -euo pipefail TEMPLATE_REMOTE="git@git.chipperfluff.at:projects/funkyFlaskTest.git" CONFIRM_MODULE="" SELF_PATH="$0" # === Dependency check === require() { if ! command -v "$1" &>/dev/null; then echo "โ— Missing dependency: $1" read -rp "๐Ÿ‘‰ Install $1 now? (y/n): " confirm if [[ "$confirm" =~ ^[Yy]$ ]]; then if [[ -f /etc/debian_version ]]; then sudo apt-get update && sudo apt-get install -y "$1" || { echo "๐Ÿ’ฅ Failed to install $1 via apt-get" exit 1 } elif [[ "$(uname)" == "Darwin" ]]; then brew install "$1" || { echo "๐Ÿ’ฅ Failed to install $1 via brew" exit 1 } else echo "๐Ÿคท I don't know how to install $1 on this system." exit 1 fi else echo "๐Ÿšซ Cannot continue without $1" exit 1 fi fi } require git require jq # === 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."