|
| 1 | +#!/bin/bash |
| 2 | +# Ratifact Uninstallation Script for Linux |
| 3 | +# Removes Ratifact application, Docker container, and PostgreSQL volume |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +# Color codes |
| 8 | +RED='\033[0;31m' |
| 9 | +GREEN='\033[0;32m' |
| 10 | +YELLOW='\033[1;33m' |
| 11 | +CYAN='\033[0;36m' |
| 12 | +NC='\033[0m' # No Color |
| 13 | + |
| 14 | +# Logging setup |
| 15 | +LOG_FILE="/tmp/ratifact-uninstall-$(date +%Y%m%d_%H%M%S).log" |
| 16 | +exec > >(tee -a "$LOG_FILE") |
| 17 | +exec 2>&1 |
| 18 | + |
| 19 | +echo "Uninstall log: $LOG_FILE" |
| 20 | + |
| 21 | +# Helper functions |
| 22 | +print_header() { |
| 23 | + echo "" |
| 24 | + echo -e "${CYAN}╔═══════════════════════════════════════════════════════════╗${NC}" |
| 25 | + echo -e "${CYAN}║ Ratifact Uninstallation Script - Linux ║${NC}" |
| 26 | + echo -e "${CYAN}╚═══════════════════════════════════════════════════════════╝${NC}" |
| 27 | + echo "" |
| 28 | +} |
| 29 | + |
| 30 | +print_success() { |
| 31 | + echo -e "${GREEN}✓ $1${NC}" |
| 32 | +} |
| 33 | + |
| 34 | +print_error() { |
| 35 | + echo -e "${RED}❌ ERROR: $1${NC}" |
| 36 | +} |
| 37 | + |
| 38 | +print_warning() { |
| 39 | + echo -e "${YELLOW}⚠️ WARNING: $1${NC}" |
| 40 | +} |
| 41 | + |
| 42 | +print_info() { |
| 43 | + echo -e "${CYAN}ℹ️ $1${NC}" |
| 44 | +} |
| 45 | + |
| 46 | +print_section() { |
| 47 | + echo "" |
| 48 | + echo -e "${CYAN}▶ $1${NC}" |
| 49 | +} |
| 50 | + |
| 51 | +# Confirmation prompt |
| 52 | +confirm() { |
| 53 | + local prompt="$1" |
| 54 | + local response |
| 55 | + read -p "$(echo -e "${YELLOW}$prompt (yes/no)${NC}: ")" response |
| 56 | + [[ "$response" == "yes" ]] && return 0 || return 1 |
| 57 | +} |
| 58 | + |
| 59 | +# Main uninstall process |
| 60 | +main() { |
| 61 | + print_header |
| 62 | + |
| 63 | + # Determine installation directory |
| 64 | + INSTALL_DIR="${RATIFACT_INSTALL_DIR:-.}" |
| 65 | + if [ ! -d "$INSTALL_DIR" ] || [ ! -f "$INSTALL_DIR/Cargo.toml" ]; then |
| 66 | + # Try to find it |
| 67 | + if [ -d "$HOME/ratifact" ]; then |
| 68 | + INSTALL_DIR="$HOME/ratifact" |
| 69 | + elif [ -d "/opt/ratifact" ]; then |
| 70 | + INSTALL_DIR="/opt/ratifact" |
| 71 | + else |
| 72 | + print_warning "Could not locate Ratifact installation directory" |
| 73 | + read -p "Enter the path to your Ratifact installation: " INSTALL_DIR |
| 74 | + if [ ! -d "$INSTALL_DIR" ] || [ ! -f "$INSTALL_DIR/Cargo.toml" ]; then |
| 75 | + print_error "Invalid installation directory: $INSTALL_DIR" |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + fi |
| 79 | + fi |
| 80 | + |
| 81 | + print_info "Found Ratifact installation at: $INSTALL_DIR" |
| 82 | + echo "" |
| 83 | + |
| 84 | + # Confirmation |
| 85 | + echo -e "${YELLOW}This will:${NC}" |
| 86 | + echo " 1. Stop the PostgreSQL Docker container" |
| 87 | + echo " 2. Remove the PostgreSQL Docker volume (optional)" |
| 88 | + echo " 3. Clean build artifacts" |
| 89 | + echo " 4. Remove the installation directory (optional)" |
| 90 | + echo "" |
| 91 | + |
| 92 | + if ! confirm "Do you want to continue with uninstallation?"; then |
| 93 | + print_info "Uninstallation cancelled" |
| 94 | + exit 0 |
| 95 | + fi |
| 96 | + |
| 97 | + print_section "Stopping Docker containers..." |
| 98 | + if cd "$INSTALL_DIR" 2>/dev/null; then |
| 99 | + if [ -f "compose.yml" ]; then |
| 100 | + if docker compose down 2>/dev/null; then |
| 101 | + print_success "Docker containers stopped" |
| 102 | + else |
| 103 | + print_warning "Could not stop Docker containers (they may not be running)" |
| 104 | + fi |
| 105 | + else |
| 106 | + print_warning "compose.yml not found" |
| 107 | + fi |
| 108 | + else |
| 109 | + print_warning "Could not change to installation directory" |
| 110 | + fi |
| 111 | + |
| 112 | + # Ask about removing volume |
| 113 | + echo "" |
| 114 | + print_info "PostgreSQL data volume: ratifact-postgres-data" |
| 115 | + if confirm "Do you want to remove the PostgreSQL volume (this will delete all database data)?"; then |
| 116 | + print_section "Removing PostgreSQL volume..." |
| 117 | + if docker volume rm ratifact-postgres-data 2>/dev/null; then |
| 118 | + print_success "PostgreSQL volume removed" |
| 119 | + else |
| 120 | + print_warning "Could not remove volume (it may not exist)" |
| 121 | + fi |
| 122 | + else |
| 123 | + print_info "Keeping PostgreSQL volume" |
| 124 | + fi |
| 125 | + |
| 126 | + # Clean build artifacts |
| 127 | + print_section "Cleaning build artifacts..." |
| 128 | + if [ -d "$INSTALL_DIR/target" ]; then |
| 129 | + if cd "$INSTALL_DIR" && cargo clean 2>/dev/null; then |
| 130 | + print_success "Build artifacts cleaned" |
| 131 | + else |
| 132 | + print_warning "Could not clean build artifacts" |
| 133 | + fi |
| 134 | + else |
| 135 | + print_info "No build artifacts found" |
| 136 | + fi |
| 137 | + |
| 138 | + # Ask about removing installation directory |
| 139 | + echo "" |
| 140 | + if confirm "Do you want to remove the entire installation directory?"; then |
| 141 | + print_section "Removing installation directory..." |
| 142 | + if rm -rf "$INSTALL_DIR"; then |
| 143 | + print_success "Installation directory removed: $INSTALL_DIR" |
| 144 | + else |
| 145 | + print_error "Could not remove installation directory (permission denied?)" |
| 146 | + print_info "You can manually remove it with: rm -rf $INSTALL_DIR" |
| 147 | + exit 1 |
| 148 | + fi |
| 149 | + else |
| 150 | + print_info "Keeping installation directory at: $INSTALL_DIR" |
| 151 | + fi |
| 152 | + |
| 153 | + echo "" |
| 154 | + print_section "Uninstallation complete!" |
| 155 | + echo "" |
| 156 | + print_success "Ratifact has been successfully uninstalled" |
| 157 | + echo "" |
| 158 | + print_info "To reinstall, visit: https://github.com/adolfousier/ratifact" |
| 159 | + echo "" |
| 160 | +} |
| 161 | + |
| 162 | +main "$@" |
0 commit comments