#!/bin/bash # Mock API Uninstallation Script set -e # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' APP_DIR="/opt/mockapi" SERVICE_NAME="mockapi" SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" print_status() { echo -e "${GREEN}[+]${NC} $1" } print_warning() { echo -e "${YELLOW}[!]${NC} $1 } print_error() { echo -e "${RED}[!]${NC} $1" } echo -e "${GREEN}========================================${NC}" echo -e "${GREEN} Mock API Uninstallation Script ${NC}" echo -e "${GREEN}========================================${NC}" echo # Confirm uninstallation read -p "Are you sure you want to uninstall Mock API? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Uninstallation cancelled." exit 0 fi # Stop and disable service if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then print_status "Stopping service..." sudo systemctl stop "$SERVICE_NAME" fi if systemctl is-enabled --quiet "$SERVICE_NAME" 2>/dev/null; then print_status "Disabling service..." sudo systemctl disable "$SERVICE_NAME" fi # Remove service file if [[ -f "$SERVICE_FILE" ]]; then print_status "Removing service file..." sudo rm "$SERVICE_FILE" sudo systemctl daemon-reload fi # Ask about removing application directory if [[ -d "$APP_DIR" ]]; then read -p "Remove application directory ($APP_DIR)? (y/N): " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then print_status "Removing application directory..." sudo rm -rf "$APP_DIR" else print_status "Application directory kept at $APP_DIR" print_warning "Note: .env file with credentials is still in $APP_DIR" fi fi print_status "Uninstallation complete!"