소스 검색

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 일 전
부모
커밋
6f38313345
1개의 변경된 파일24개의 추가작업 그리고 0개의 파일을 삭제
  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
 }