浏览代码

fix: Fix install-linux.sh and add uninstall option

- Fix broken installation with --user option
- Fix desktop icon link when in --user mode
- Add uninstall command (only installation, not user's data)
Paulo Bueno 1 周之前
父节点
当前提交
6b68197e55
共有 1 个文件被更改,包括 87 次插入10 次删除
  1. 87 10
      scripts/install-linux.sh

+ 87 - 10
scripts/install-linux.sh

@@ -38,6 +38,11 @@ This script installs Logseq on Linux systems.
 
 
 USAGE:
 USAGE:
     $0 [VERSION] [OPTIONS]
     $0 [VERSION] [OPTIONS]
+    $0 uninstall
+
+COMMANDS:
+    install (default)   Install Logseq
+    uninstall           Removes Logseq installation (keeps user data)
 
 
 ARGUMENTS:
 ARGUMENTS:
     VERSION    Version to install (e.g., "0.10.14"). Default: latest
     VERSION    Version to install (e.g., "0.10.14"). Default: latest
@@ -59,6 +64,70 @@ For more information, visit: https://github.com/logseq/logseq
 HELP
 HELP
 }
 }
 
 
+uninstall() {
+    log_info "Searching for Logseq installations..."
+    
+    local user_removed=false
+    local system_removed=false
+    
+    # User installation paths
+    local -a user_paths=(
+        "$HOME/.local/share/logseq"
+        "$HOME/.local/bin/logseq"
+        "$HOME/.local/share/applications/logseq.desktop"
+        "$HOME/.local/share/icons/hicolor/512x512/apps/logseq.png"
+    )
+    
+    # System installation paths
+    local -a system_paths=(
+        "/opt/logseq"
+        "/usr/local/bin/logseq"
+        "/usr/share/applications/logseq.desktop"
+        "/usr/share/icons/hicolor/512x512/apps/logseq.png"
+    )
+    
+    # Remove user installation
+    log_info "Checking user installation..."
+    for path in "${user_paths[@]}"; do
+        if [[ -e "$path" ]] || [[ -L "$path" ]]; then
+            log_info "Removing: $path"
+            rm -rf "$path"
+            user_removed=true
+        fi
+    done
+    
+    # Remove system installation
+    log_info "Checking system-wide installation..."
+    for path in "${system_paths[@]}"; do
+        if [[ -e "$path" ]] || [[ -L "$path" ]]; then
+            if [[ "$EUID" -ne 0 ]]; then
+                log_warn "System-wide installation found at $path, but root privileges required"
+                log_warn "Run with sudo to uninstall system-wide installation"
+            else
+                log_info "Removing: $path"
+                rm -rf "$path"
+                system_removed=true
+            fi
+        fi
+    done
+    
+    # Update desktop databases
+    if [[ "$user_removed" == true ]] && [[ -d "$HOME/.local/share/applications" ]]; then
+        update-desktop-database "$HOME/.local/share/applications" 2>/dev/null || true
+    fi
+    
+    if [[ "$system_removed" == true ]]; then
+        update-desktop-database /usr/share/applications 2>/dev/null || true
+    fi
+    
+    # Final status message
+    if [[ "$user_removed" == true ]] || [[ "$system_removed" == true ]]; then
+        log_info "Logseq has been uninstalled successfully!"
+    else
+        log_warn "No Logseq installation found in default locations"
+    fi
+}
+
 # Parse command line arguments
 # Parse command line arguments
 VERSION="$DEFAULT_VERSION"
 VERSION="$DEFAULT_VERSION"
 USER_INSTALL=false
 USER_INSTALL=false
@@ -87,6 +156,10 @@ while [[ $# -gt 0 ]]; do
             VERBOSE=true
             VERBOSE=true
             shift
             shift
             ;;
             ;;
+        uninstall)
+            uninstall
+            exit 0
+            ;;
         -*)
         -*)
             log_error "Unknown option: $1"
             log_error "Unknown option: $1"
             show_help
             show_help
@@ -183,7 +256,7 @@ else
 fi
 fi
 
 
 # Fix sandbox permissions
 # Fix sandbox permissions
-if [[ -f "$INSTALL_DIR/chrome-sandbox" ]]; then
+if [[ "$USER_INSTALL" == false && -f "$INSTALL_DIR/chrome-sandbox" ]]; then
     log_info "Setting sandbox permissions..."
     log_info "Setting sandbox permissions..."
     chown root:root "$INSTALL_DIR/chrome-sandbox"
     chown root:root "$INSTALL_DIR/chrome-sandbox"
     chmod 4755 "$INSTALL_DIR/chrome-sandbox"
     chmod 4755 "$INSTALL_DIR/chrome-sandbox"
@@ -192,12 +265,19 @@ fi
 # Desktop integration
 # Desktop integration
 if [[ "$SKIP_DESKTOP" == false ]]; then
 if [[ "$SKIP_DESKTOP" == false ]]; then
     log_info "Creating desktop integration..."
     log_info "Creating desktop integration..."
-    
+
     DESKTOP_FILE="/usr/share/applications/logseq.desktop"
     DESKTOP_FILE="/usr/share/applications/logseq.desktop"
     if [[ "$USER_INSTALL" == true ]]; then
     if [[ "$USER_INSTALL" == true ]]; then
         mkdir -p ~/.local/share/applications/
         mkdir -p ~/.local/share/applications/
         DESKTOP_FILE="$HOME/.local/share/applications/logseq.desktop"
         DESKTOP_FILE="$HOME/.local/share/applications/logseq.desktop"
     fi
     fi
+
+    # Copy icon to standard location
+    ICON_DIR="/usr/share/icons/hicolor/512x512/apps/"
+    if [[ "$USER_INSTALL" == true ]]; then
+        ICON_DIR="$HOME/.local/share/icons/hicolor/512x512/apps/"
+        mkdir -p "$ICON_DIR"
+    fi
     
     
     # Create desktop file
     # Create desktop file
     cat > "$DESKTOP_FILE" << DESKTOP_EOF
     cat > "$DESKTOP_FILE" << DESKTOP_EOF
@@ -205,8 +285,8 @@ if [[ "$SKIP_DESKTOP" == false ]]; then
 Version=1.0
 Version=1.0
 Name=Logseq
 Name=Logseq
 Comment=Logseq - A privacy-first, open-source platform for knowledge management and collaboration
 Comment=Logseq - A privacy-first, open-source platform for knowledge management and collaboration
-Exec=$INSTALL_DIR/Logseq %U
-Icon=$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png
+Exec=$INSTALL_DIR/Logseq $([ "$USER_INSTALL" = true ] && echo "--no-sandbox") %U
+Icon=$ICON_DIR/logseq.png
 Terminal=false
 Terminal=false
 Type=Application
 Type=Application
 Categories=Office;Productivity;Utility;TextEditor;
 Categories=Office;Productivity;Utility;TextEditor;
@@ -217,13 +297,7 @@ DESKTOP_EOF
     # Make desktop file executable
     # Make desktop file executable
     chmod +x "$DESKTOP_FILE"
     chmod +x "$DESKTOP_FILE"
     
     
-    # Copy icon to standard location
     if [[ -f "$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png" ]]; then
     if [[ -f "$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png" ]]; then
-        ICON_DIR="/usr/share/icons/hicolor/512x512/apps/"
-        if [[ "$USER_INSTALL" == true ]]; then
-            ICON_DIR="$HOME/.local/share/icons/hicolor/512x512/apps/"
-            mkdir -p "$ICON_DIR"
-        fi
         
         
         cp "$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png" "$ICON_DIR/logseq.png"
         cp "$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png" "$ICON_DIR/logseq.png"
         
         
@@ -232,6 +306,9 @@ DESKTOP_EOF
             sed -i 's|Icon=$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png|Icon=logseq|' "$DESKTOP_FILE"
             sed -i 's|Icon=$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png|Icon=logseq|' "$DESKTOP_FILE"
         fi
         fi
     fi
     fi
+    if [[ "$USER_INSTALL" == true && -f "$INSTALL_DIR/resources/app/icon.png" ]]; then
+        cp "$INSTALL_DIR/resources/app/icon.png" "$ICON_DIR/logseq.png"
+    fi
     
     
     # Update desktop database
     # Update desktop database
     if [[ "$USER_INSTALL" == false ]]; then
     if [[ "$USER_INSTALL" == false ]]; then