#!/usr/bin/env bash ############################################################################### # GEEKCADE RESET # Undo geekcade_install.sh v2.0 # # Restores the system to (approximately) the state it was in before # the GeekCade installer ran. Safe to run multiple times - each step # checks before doing anything. # # By default this is a SOFT reset: # - Removes config files (mame.ini, attract.cfg, mame.cfg, romlist) # - Removes per-game state (cfg/, nvram/, hi/, inp/, etc.) # - Removes MAME's runtime crud # - PRESERVES all USB-synced content: roms, flyers, marquees, snaps, # videosnaps, dats, history, samples, and the .geekcade_synced_size # markers so the next asset sync skips already-extracted zips. # # For a full nuke (delete everything including roms and asset folders), # pass --hard: # ./geekcade_reset.sh --hard # # Run as: geekcade ############################################################################### set -u if [ "$(whoami)" != "geekcade" ]; then echo "ERROR: This reset must be run as user 'geekcade'." exit 1 fi # ============================== # [0] ARGUMENT PARSING # ============================== HARD_RESET=0 for arg in "$@"; do case "$arg" in --hard) HARD_RESET=1 ;; --help|-h) sed -n '2,/^####/p' "$0" | sed 's/^#//' | head -n -1 exit 0 ;; *) echo "Unknown option: $arg" >&2 echo "Run with --help for usage." >&2 exit 2 ;; esac done GREEN=$'\033[0;32m' RED=$'\033[0;31m' YELLOW=$'\033[1;33m' CYAN=$'\033[0;36m' NC=$'\033[0m' confirm() { if [ "$HARD_RESET" -eq 1 ]; then echo -e "${RED}=== HARD RESET ===${NC}" echo -e "${YELLOW}This will:${NC}" echo " - Remove ~/mame ENTIRELY (including roms and all USB-synced assets)" echo " - Remove ~/attractplus ENTIRELY" else echo -e "${CYAN}=== SOFT RESET (preserves USB-synced content) ===${NC}" echo -e "${YELLOW}This will:${NC}" echo " - Remove MAME config (mame.ini) and per-game state (cfg/, nvram/, hi/, etc.)" echo " - Remove AM+ config (attract.cfg, mame.cfg) and romlists" fi echo " - Remove ~/attractplus-source (if present)" echo " - Remove ~/logs, ~/wallpaper, ~/configs" echo " - Remove ~/mame.sh, ~/attractplus.sh, ~/geekcade_assets.sh" echo " - Remove ~/.geekcade_install_success" echo " - Remove ~/.mame, ~/.attractplus, ~/.attract (parallel-config dirs)" echo " - Remove GeekCade aliases from ~/.bash_aliases" echo " - Remove AM+ autostart block from ~/.bash_profile" echo " - Uninstall attractplus (.deb or compiled)" echo " - Remove the disable-tty-blank systemd service" echo " - Remove the GEEKCADE USB automount units" echo " - Remove tty1 auto-login drop-in" echo " - Remove geekcade poweroff/reboot sudoers" echo "" if [ "$HARD_RESET" -eq 0 ]; then echo -e "${GREEN}This will NOT:${NC}" echo " - Touch ~/mame/roms/ (your ROM library)" echo " - Touch the extracted asset folders (flyers, marquees, snap, etc.)" echo " - Touch ~/mame/dats, folders, history, samples, videosnaps, soundtrack" echo " - Touch the .geekcade_synced_size markers (so re-sync stays fast)" echo " - For a full nuke instead, run: ./geekcade_reset.sh --hard" echo "" fi echo -e "${YELLOW}Will not be touched (regardless of mode):${NC}" echo " - apt packages (mame, build tools, libs) - left in place" echo " - geekcade from input/video/render groups - left in place" echo "" read -r -p "Continue? [y/N] " answer case "$answer" in [yY]|[yY][eE][sS]) return 0 ;; *) echo "Cancelled."; exit 0 ;; esac } step() { echo -e "${YELLOW}======> $1${NC}" } ok() { echo -e " ${GREEN}done${NC}" } confirm echo "Requesting sudo..." sudo -v || { echo "Need sudo. Exiting."; exit 1; } # 1. Remove GeekCade directories and files in $HOME if [ "$HARD_RESET" -eq 1 ]; then step "HARD: Removing all GeekCade home directories" rm -rf "$HOME/mame" \ "$HOME/attractplus" \ "$HOME/attractplus-source" \ "$HOME/logs" \ "$HOME/wallpaper" \ "$HOME/configs" else # Soft reset: keep all the USB-synced asset content. Only remove # config files and per-game state that gets regenerated by the # installer or by playing games. step "SOFT: Removing MAME config and per-game state (preserving content)" if [ -d "$HOME/mame" ]; then # MAME's config + runtime state. These all regenerate. rm -f "$HOME/mame/mame.ini" rm -rf "$HOME/mame/cfg" \ "$HOME/mame/nvram" \ "$HOME/mame/inp" \ "$HOME/mame/sta" \ "$HOME/mame/diff" \ "$HOME/mame/comments" \ "$HOME/mame/hi" \ "$HOME/mame/cheat" \ "$HOME/mame/snap-cfg" \ "$HOME/mame/ctrlr" \ "$HOME/mame/ini" # Note what we're keeping for the user if [ -d "$HOME/mame/roms" ]; then _rom_count="$(find "$HOME/mame/roms" -maxdepth 1 -name '*.zip' 2>/dev/null | wc -l | awk '{print $1}')" echo -e " ${GREEN}Preserving:${NC} ~/mame/roms ($_rom_count zips)" fi for d in flyers marquees snap snaps cabinets bosses cpanel pcb titles ends \ gameover howto icons logo manuals scores select versus warning \ artpreview devices; do if [ -d "$HOME/mame/$d" ]; then echo -e " ${GREEN}Preserving:${NC} ~/mame/$d" fi done for d in dats folders history samples artwork videosnaps soundtrack; do if [ -d "$HOME/mame/$d" ]; then echo -e " ${GREEN}Preserving:${NC} ~/mame/$d" fi done [ -f "$HOME/mame/cheat.7z" ] && echo -e " ${GREEN}Preserving:${NC} ~/mame/cheat.7z" fi step "SOFT: Removing AM+ config and romlists (preserving any content)" if [ -d "$HOME/attractplus" ]; then # AM+ config files rm -f "$HOME/attractplus/config/attract.cfg" rm -f "$HOME/attractplus/emulators/mame.cfg" # AM+ caches and rebuildable state rm -rf "$HOME/attractplus/cache" rm -f "$HOME/attractplus/romlists/mame.txt" # Per-game stats stay (AM+ tracks how often you played each game) # menu-art folders stay (user customizations) fi # Always remove these unconditionally - they don't hold sync content rm -rf "$HOME/attractplus-source" \ "$HOME/logs" \ "$HOME/wallpaper" \ "$HOME/configs" fi rm -f "$HOME/mame.sh" \ "$HOME/attractplus.sh" \ "$HOME/geekcade_assets.sh" \ "$HOME/geekcade_lib.sh" \ "$HOME/.geekcade_install_success" ok # 1b. Remove parallel-config dirs created by running mame/attractplus # directly (without the .sh launchers) before aliases were in place. # Also remove ~/.attract which AM+ creates as its default config dir # when launched without --config (e.g. before our launcher was set up). step "Removing parallel-config dirs (~/.mame, ~/.attractplus, ~/.attract)" rm -rf "$HOME/.mame" "$HOME/.attractplus" "$HOME/.attract" # Also clear any stale skip-gate flag (the menu uses this for its boot gate) rm -f /tmp/.geekcade_skip_gate ok # Note: ~/geekcade_menu.sh is intentionally NOT removed - you maintain # the menu independently of the installer, so reset preserves it. # 1c. Strip GeekCade aliases from ~/.bash_aliases step "Removing GeekCade aliases from ~/.bash_aliases" if [ -f "$HOME/.bash_aliases" ]; then sed -i '/# >>> GeekCade aliases >>>/,/# <<< GeekCade aliases <</dev/null || true sudo rm -f /etc/systemd/system/disable-tty-blank.service sudo systemctl daemon-reload fi ok # 4b. Remove tty1 auto-login drop-in step "Removing tty1 auto-login drop-in" sudo rm -f /etc/systemd/system/getty@tty1.service.d/autologin.conf sudo rmdir /etc/systemd/system/getty@tty1.service.d 2>/dev/null || true sudo systemctl daemon-reload ok # 4b2. Remove GEEKCADE USB automount units step "Removing GEEKCADE USB automount units" sudo systemctl stop media-GEEKCADE.automount 2>/dev/null || true sudo systemctl stop media-GEEKCADE.mount 2>/dev/null || true sudo systemctl disable media-GEEKCADE.automount 2>/dev/null || true sudo rm -f /etc/systemd/system/media-GEEKCADE.automount sudo rm -f /etc/systemd/system/media-GEEKCADE.mount sudo rmdir /media/GEEKCADE 2>/dev/null || true sudo systemctl daemon-reload ok # 4c. Remove passwordless poweroff/reboot sudoers step "Removing geekcade poweroff/reboot sudoers" sudo rm -f /etc/sudoers.d/geekcade-power /etc/sudoers.d/geekcade-kbd /etc/sudoers.d/geekcade-getty ok # 4d. Strip auto-launch block from .bash_profile step "Removing AM+ auto-start block from ~/.bash_profile" if [ -f "$HOME/.bash_profile" ]; then sed -i '/# >>> GeekCade autostart >>>/,/# <<< GeekCade autostart <<