Selaa lähdekoodia

feat(installer): add check for existing installation

Add check_existing_installation function to detect and handle cases
where the target directory already exists. Supports auto-confirmation
via -y flag for non-interactive reinstalls and prompts user for
confirmation otherwise.
clanker 5 päivää sitten
vanhempi
sitoutus
6f38313345
1 muutettua tiedostoa jossa 24 lisäystä ja 0 poistoa
  1. 24 0
      installer/main.sh

+ 24 - 0
installer/main.sh

@@ -92,6 +92,27 @@ check_root() {
     fi
 }
 
+# Check if target directory exists and handle reinstallation
+check_existing_installation() {
+    if [[ -d "$TARGET_DIR" ]]; then
+        log_warn "Target directory '$TARGET_DIR' already exists."
+        
+        if [[ "$ASSUME_YES" == "true" ]]; then
+            log_info "Removing existing installation (auto-confirmed with -y)..."
+            rm -rf "$TARGET_DIR"
+            return 0
+        fi
+        
+        if confirm "Do you want to delete it and reinstall?" "n"; then
+            log_info "Removing existing installation..."
+            rm -rf "$TARGET_DIR"
+        else
+            echo "Installation cancelled."
+            exit 0
+        fi
+    fi
+}
+
 # Main installation function
 run_installation() {
     # Set up temporary directory
@@ -151,6 +172,9 @@ main() {
         exit 0
     fi
     
+    # Check if target directory exists and handle reinstallation
+    check_existing_installation
+    
     # Run the installation
     run_installation
 }