#!/usr/bin/env bash # Function to prompt user for confirmation prompt_confirmation() { while true; do read -r -p "Would you like to uninstall Gitea? This is not reversible. [Y/n] " input case $input in [yY][eE][sS]|[yY]) return 0 ;; [nN][oO]|[nN]) return 1 ;; *) echo "That wasn't an option..." ;; esac done } # Function to perform uninstallation uninstall_gitea() { echo "Stopping Gitea service..." sudo systemctl stop gitea echo "Disabling Gitea service..." sudo systemctl disable gitea echo "Removing Gitea service file..." sudo rm -rf /etc/systemd/system/gitea.service echo "Backing up files..." timestamp=$(date +"%Y%m%d_%H%M%S") tar -cvzf "gitea_backup_${timestamp}.tar.gz" /var/lib/gitea/ /etc/gitea || { echo "Failed to backup files. Exiting."; exit 1; } echo "Removing Gitea user and home directory..." sudo userdel -r git || { echo "Failed to delete Gitea user. Exiting."; exit 1; } echo "Removing Gitea binary..." sudo rm -rf /usr/local/bin/gitea echo "Cleaning up Gitea data and configuration..." sudo rm -rf /var/lib/gitea/* /etc/gitea echo "Removing firewall rule for port 3000..." sudo ufw delete allow 3000 echo "Gitea has been uninstalled, and all files have been backed up." } # Main script trap 'exit 130' INT if prompt_confirmation; then uninstall_gitea else echo "Gitea uninstallation aborted." fi exit 0