1
0

install-linux.sh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #!/bin/bash
  2. # Logseq Linux Installer Script
  3. # This script installs Logseq on Linux systems
  4. # Usage: ./install-linux.sh [version]
  5. set -e # Exit on any error
  6. # Default values
  7. DEFAULT_VERSION="latest"
  8. INSTALL_DIR="/opt/logseq"
  9. BIN_DIR="/usr/local/bin"
  10. # Colors for output
  11. RED='\033[0;31m'
  12. GREEN='\033[0;32m'
  13. YELLOW='\033[1;33m'
  14. NC='\033[0m' # No Color
  15. # Helper functions
  16. log_info() {
  17. echo -e "${GREEN}[INFO]${NC} $1"
  18. }
  19. log_warn() {
  20. echo -e "${YELLOW}[WARN]${NC} $1"
  21. }
  22. log_error() {
  23. echo -e "${RED}[ERROR]${NC} $1"
  24. }
  25. show_help() {
  26. cat << HELP
  27. Logseq Linux Installer
  28. This script installs Logseq on Linux systems.
  29. USAGE:
  30. $0 [VERSION] [OPTIONS]
  31. ARGUMENTS:
  32. VERSION Version to install (e.g., "0.10.14"). Default: latest
  33. OPTIONS:
  34. --help, -h Show this help message
  35. --prefix DIR Installation prefix (default: /opt/logseq)
  36. --user Install for current user only
  37. --no-desktop Skip desktop integration
  38. --verbose, -v Verbose output
  39. EXAMPLES:
  40. $0 # Install latest version
  41. $0 0.10.14 # Install specific version
  42. $0 --user # Install for current user
  43. $0 --prefix ~/.local/share/logseq # Custom install location
  44. For more information, visit: https://github.com/logseq/logseq
  45. HELP
  46. }
  47. # Parse command line arguments
  48. VERSION="$DEFAULT_VERSION"
  49. USER_INSTALL=false
  50. SKIP_DESKTOP=false
  51. VERBOSE=false
  52. while [[ $# -gt 0 ]]; do
  53. case $1 in
  54. --help|-h)
  55. show_help
  56. exit 0
  57. ;;
  58. --prefix)
  59. INSTALL_DIR="$2"
  60. shift 2
  61. ;;
  62. --user)
  63. USER_INSTALL=true
  64. shift
  65. ;;
  66. --no-desktop)
  67. SKIP_DESKTOP=true
  68. shift
  69. ;;
  70. --verbose|-v)
  71. VERBOSE=true
  72. shift
  73. ;;
  74. -*)
  75. log_error "Unknown option: $1"
  76. show_help
  77. exit 1
  78. ;;
  79. *)
  80. VERSION="$1"
  81. shift
  82. ;;
  83. esac
  84. done
  85. # Set installation paths based on user/system install
  86. if [[ "$USER_INSTALL" == true ]]; then
  87. INSTALL_DIR="${INSTALL_DIR/#\/opt\/logseq/$HOME/.local/share/logseq}"
  88. BIN_DIR="$HOME/.local/bin"
  89. mkdir -p "$BIN_DIR"
  90. # Add local bin to PATH if not already there
  91. if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then
  92. log_info "Adding $HOME/.local/bin to PATH..."
  93. export PATH="$HOME/.local/bin:$PATH"
  94. echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
  95. fi
  96. fi
  97. log_info "Installing Logseq $VERSION to $INSTALL_DIR"
  98. # Check if running as root for system-wide installation
  99. if [[ "$USER_INSTALL" == false && $EUID -ne 0 ]]; then
  100. log_warn "System-wide installation requires root privileges"
  101. log_warn "Run with sudo or use --user for user-specific installation"
  102. exit 1
  103. fi
  104. # Create temporary directory
  105. TEMP_DIR=$(mktemp -d)
  106. if [[ "$VERBOSE" == true ]]; then
  107. log_info "Using temporary directory: $TEMP_DIR"
  108. fi
  109. cd "$TEMP_DIR"
  110. # Determine download URL
  111. if [[ "$VERSION" == "latest" ]]; then
  112. log_info "Fetching latest release information..."
  113. LATEST_RELEASE=$(curl -s https://api.github.com/repos/logseq/logseq/releases/latest)
  114. DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | grep -o '"browser_download_url": "[^"]*Logseq-linux-x64-[^"]*\.zip"' | cut -d'"' -f4)
  115. if [[ -z "$DOWNLOAD_URL" ]]; then
  116. log_error "Could not find download URL for latest version"
  117. exit 1
  118. fi
  119. else
  120. DOWNLOAD_URL="https://github.com/logseq/logseq/releases/download/${VERSION}/Logseq-linux-x64-${VERSION}.zip"
  121. fi
  122. log_info "Download URL: $DOWNLOAD_URL"
  123. # Download Logseq
  124. log_info "Downloading Logseq..."
  125. if ! wget -q --show-progress -O logseq.zip "$DOWNLOAD_URL"; then
  126. log_error "Failed to download Logseq $VERSION"
  127. log_error "Please check if version $VERSION exists on GitHub releases"
  128. rm -rf "$TEMP_DIR"
  129. exit 1
  130. fi
  131. # Extract archive
  132. log_info "Extracting archive..."
  133. unzip -q logseq.zip
  134. # Find the extracted directory
  135. EXTRACTED_DIR=$(find . -maxdepth 2 -type d -name "Logseq-linux-x64*" | head -1)
  136. if [[ -z "$EXTRACTED_DIR" ]]; then
  137. log_error "Could not find extracted Logseq directory"
  138. rm -rf "$TEMP_DIR"
  139. exit 1
  140. fi
  141. # Install files
  142. log_info "Installing files..."
  143. if [[ "$USER_INSTALL" == false ]]; then
  144. mkdir -p "$INSTALL_DIR"
  145. cp -r "$EXTRACTED_DIR"/* "$INSTALL_DIR/"
  146. chmod +x "$INSTALL_DIR/Logseq"
  147. ln -sf "$INSTALL_DIR/Logseq" "$BIN_DIR/logseq"
  148. else
  149. mkdir -p "$INSTALL_DIR"
  150. cp -r "$EXTRACTED_DIR"/* "$INSTALL_DIR/"
  151. chmod +x "$INSTALL_DIR/Logseq"
  152. ln -sf "$INSTALL_DIR/Logseq" "$BIN_DIR/logseq"
  153. fi
  154. # Fix sandbox permissions
  155. if [[ -f "$INSTALL_DIR/chrome-sandbox" ]]; then
  156. log_info "Setting sandbox permissions..."
  157. chown root:root "$INSTALL_DIR/chrome-sandbox"
  158. chmod 4755 "$INSTALL_DIR/chrome-sandbox"
  159. fi
  160. # Desktop integration
  161. if [[ "$SKIP_DESKTOP" == false ]]; then
  162. log_info "Creating desktop integration..."
  163. DESKTOP_FILE="/usr/share/applications/logseq.desktop"
  164. if [[ "$USER_INSTALL" == true ]]; then
  165. mkdir -p ~/.local/share/applications/
  166. DESKTOP_FILE="$HOME/.local/share/applications/logseq.desktop"
  167. fi
  168. # Create desktop file
  169. cat > "$DESKTOP_FILE" << DESKTOP_EOF
  170. [Desktop Entry]
  171. Version=1.0
  172. Name=Logseq
  173. Comment=Logseq - A privacy-first, open-source platform for knowledge management and collaboration
  174. Exec=$INSTALL_DIR/Logseq %U
  175. Icon=$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png
  176. Terminal=false
  177. Type=Application
  178. Categories=Office;Productivity;Utility;TextEditor;
  179. MimeType=application/x-logseq;
  180. StartupWMClass=Logseq
  181. DESKTOP_EOF
  182. # Make desktop file executable
  183. chmod +x "$DESKTOP_FILE"
  184. # Copy icon to standard location
  185. if [[ -f "$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png" ]]; then
  186. ICON_DIR="/usr/share/icons/hicolor/512x512/apps/"
  187. if [[ "$USER_INSTALL" == true ]]; then
  188. ICON_DIR="$HOME/.local/share/icons/hicolor/512x512/apps/"
  189. mkdir -p "$ICON_DIR"
  190. fi
  191. cp "$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png" "$ICON_DIR/logseq.png"
  192. # Update desktop file to use the copied icon
  193. if [[ "$USER_INSTALL" == false ]]; then
  194. sed -i 's|Icon=$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png|Icon=logseq|' "$DESKTOP_FILE"
  195. fi
  196. fi
  197. # Update desktop database
  198. if [[ "$USER_INSTALL" == false ]]; then
  199. update-desktop-database /usr/share/applications/ 2>/dev/null || true
  200. else
  201. update-desktop-database ~/.local/share/applications/ 2>/dev/null || true
  202. fi
  203. fi
  204. # Clean up
  205. rm -rf "$TEMP_DIR"
  206. # Verify installation
  207. if command -v logseq >/dev/null 2>&1; then
  208. INSTALLED_VERSION=$(logseq --version 2>/dev/null | head -1 || echo "unknown")
  209. log_info "Logseq installed successfully!"
  210. log_info "Version: $INSTALLED_VERSION"
  211. log_info "Location: $INSTALL_DIR"
  212. log_info "Command: logseq"
  213. if [[ "$SKIP_DESKTOP" == false ]]; then
  214. log_info "Desktop integration: Enabled"
  215. log_info "You can find Logseq in your applications menu"
  216. fi
  217. else
  218. log_error "Installation completed but 'logseq' command not found in PATH"
  219. log_info "You may need to restart your terminal or add $BIN_DIR to your PATH"
  220. fi
  221. log_info "Installation completed successfully!"