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)
This commit is contained in:
Paulo Bueno
2025-10-06 23:35:49 -03:00
committed by Tienson Qin
parent 14c240dd5c
commit 6b68197e55

View File

@@ -38,6 +38,11 @@ This script installs Logseq on Linux systems.
USAGE:
$0 [VERSION] [OPTIONS]
$0 uninstall
COMMANDS:
install (default) Install Logseq
uninstall Removes Logseq installation (keeps user data)
ARGUMENTS:
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
}
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
VERSION="$DEFAULT_VERSION"
USER_INSTALL=false
@@ -87,6 +156,10 @@ while [[ $# -gt 0 ]]; do
VERBOSE=true
shift
;;
uninstall)
uninstall
exit 0
;;
-*)
log_error "Unknown option: $1"
show_help
@@ -183,7 +256,7 @@ else
fi
# 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..."
chown root:root "$INSTALL_DIR/chrome-sandbox"
chmod 4755 "$INSTALL_DIR/chrome-sandbox"
@@ -192,12 +265,19 @@ fi
# Desktop integration
if [[ "$SKIP_DESKTOP" == false ]]; then
log_info "Creating desktop integration..."
DESKTOP_FILE="/usr/share/applications/logseq.desktop"
if [[ "$USER_INSTALL" == true ]]; then
mkdir -p ~/.local/share/applications/
DESKTOP_FILE="$HOME/.local/share/applications/logseq.desktop"
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
cat > "$DESKTOP_FILE" << DESKTOP_EOF
@@ -205,8 +285,8 @@ if [[ "$SKIP_DESKTOP" == false ]]; then
Version=1.0
Name=Logseq
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
Type=Application
Categories=Office;Productivity;Utility;TextEditor;
@@ -217,13 +297,7 @@ DESKTOP_EOF
# Make desktop file executable
chmod +x "$DESKTOP_FILE"
# Copy icon to standard location
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"
@@ -232,6 +306,9 @@ DESKTOP_EOF
sed -i 's|Icon=$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png|Icon=logseq|' "$DESKTOP_FILE"
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
if [[ "$USER_INSTALL" == false ]]; then