1
0

install-linux.sh 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. $0 uninstall
  32. COMMANDS:
  33. install (default) Install Logseq
  34. uninstall Removes Logseq installation (keeps user data)
  35. ARGUMENTS:
  36. VERSION Version to install (e.g., "0.10.14"). Default: latest
  37. OPTIONS:
  38. --help, -h Show this help message
  39. --prefix DIR Installation prefix (default: /opt/logseq)
  40. --user Install for current user only
  41. --no-desktop Skip desktop integration
  42. --verbose, -v Verbose output
  43. EXAMPLES:
  44. $0 # Install latest version
  45. $0 0.10.14 # Install specific version
  46. $0 --user # Install for current user
  47. $0 --prefix ~/.local/share/logseq # Custom install location
  48. For more information, visit: https://github.com/logseq/logseq
  49. HELP
  50. }
  51. uninstall() {
  52. log_info "Searching for Logseq installations..."
  53. local user_removed=false
  54. local system_removed=false
  55. # User installation paths
  56. local -a user_paths=(
  57. "$HOME/.local/share/logseq"
  58. "$HOME/.local/bin/logseq"
  59. "$HOME/.local/share/applications/logseq.desktop"
  60. "$HOME/.local/share/icons/hicolor/512x512/apps/logseq.png"
  61. )
  62. # System installation paths
  63. local -a system_paths=(
  64. "/opt/logseq"
  65. "/usr/local/bin/logseq"
  66. "/usr/share/applications/logseq.desktop"
  67. "/usr/share/icons/hicolor/512x512/apps/logseq.png"
  68. )
  69. # Remove user installation
  70. log_info "Checking user installation..."
  71. for path in "${user_paths[@]}"; do
  72. if [[ -e "$path" ]] || [[ -L "$path" ]]; then
  73. log_info "Removing: $path"
  74. rm -rf "$path"
  75. user_removed=true
  76. fi
  77. done
  78. # Remove system installation
  79. log_info "Checking system-wide installation..."
  80. for path in "${system_paths[@]}"; do
  81. if [[ -e "$path" ]] || [[ -L "$path" ]]; then
  82. if [[ "$EUID" -ne 0 ]]; then
  83. log_warn "System-wide installation found at $path, but root privileges required"
  84. log_warn "Run with sudo to uninstall system-wide installation"
  85. else
  86. log_info "Removing: $path"
  87. rm -rf "$path"
  88. system_removed=true
  89. fi
  90. fi
  91. done
  92. # Update desktop databases
  93. if [[ "$user_removed" == true ]] && [[ -d "$HOME/.local/share/applications" ]]; then
  94. update-desktop-database "$HOME/.local/share/applications" 2>/dev/null || true
  95. fi
  96. if [[ "$system_removed" == true ]]; then
  97. update-desktop-database /usr/share/applications 2>/dev/null || true
  98. fi
  99. # Final status message
  100. if [[ "$user_removed" == true ]] || [[ "$system_removed" == true ]]; then
  101. log_info "Logseq has been uninstalled successfully!"
  102. else
  103. log_warn "No Logseq installation found in default locations"
  104. fi
  105. }
  106. # Parse command line arguments
  107. VERSION="$DEFAULT_VERSION"
  108. USER_INSTALL=false
  109. SKIP_DESKTOP=false
  110. VERBOSE=false
  111. while [[ $# -gt 0 ]]; do
  112. case $1 in
  113. --help|-h)
  114. show_help
  115. exit 0
  116. ;;
  117. --prefix)
  118. INSTALL_DIR="$2"
  119. shift 2
  120. ;;
  121. --user)
  122. USER_INSTALL=true
  123. shift
  124. ;;
  125. --no-desktop)
  126. SKIP_DESKTOP=true
  127. shift
  128. ;;
  129. --verbose|-v)
  130. VERBOSE=true
  131. shift
  132. ;;
  133. uninstall)
  134. uninstall
  135. exit 0
  136. ;;
  137. -*)
  138. log_error "Unknown option: $1"
  139. show_help
  140. exit 1
  141. ;;
  142. *)
  143. VERSION="$1"
  144. shift
  145. ;;
  146. esac
  147. done
  148. # Set installation paths based on user/system install
  149. if [[ "$USER_INSTALL" == true ]]; then
  150. INSTALL_DIR="${INSTALL_DIR/#\/opt\/logseq/$HOME/.local/share/logseq}"
  151. BIN_DIR="$HOME/.local/bin"
  152. mkdir -p "$BIN_DIR"
  153. # Add local bin to PATH if not already there
  154. if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then
  155. log_info "Adding $HOME/.local/bin to PATH..."
  156. export PATH="$HOME/.local/bin:$PATH"
  157. echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
  158. fi
  159. fi
  160. log_info "Installing Logseq $VERSION to $INSTALL_DIR"
  161. # Check if running as root for system-wide installation
  162. if [[ "$USER_INSTALL" == false && $EUID -ne 0 ]]; then
  163. log_warn "System-wide installation requires root privileges"
  164. log_warn "Run with sudo or use --user for user-specific installation"
  165. exit 1
  166. fi
  167. # Create temporary directory
  168. TEMP_DIR=$(mktemp -d)
  169. if [[ "$VERBOSE" == true ]]; then
  170. log_info "Using temporary directory: $TEMP_DIR"
  171. fi
  172. cd "$TEMP_DIR"
  173. # Determine download URL
  174. if [[ "$VERSION" == "latest" ]]; then
  175. log_info "Fetching latest release information..."
  176. LATEST_RELEASE=$(curl -s https://api.github.com/repos/logseq/logseq/releases/latest)
  177. DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | grep -o '"browser_download_url": "[^"]*Logseq-linux-x64-[^"]*\.zip"' | cut -d'"' -f4)
  178. if [[ -z "$DOWNLOAD_URL" ]]; then
  179. log_error "Could not find download URL for latest version"
  180. exit 1
  181. fi
  182. else
  183. DOWNLOAD_URL="https://github.com/logseq/logseq/releases/download/${VERSION}/Logseq-linux-x64-${VERSION}.zip"
  184. fi
  185. log_info "Download URL: $DOWNLOAD_URL"
  186. # Download Logseq
  187. log_info "Downloading Logseq..."
  188. if ! wget -q --show-progress -O logseq.zip "$DOWNLOAD_URL"; then
  189. log_error "Failed to download Logseq $VERSION"
  190. log_error "Please check if version $VERSION exists on GitHub releases"
  191. rm -rf "$TEMP_DIR"
  192. exit 1
  193. fi
  194. # Extract archive
  195. log_info "Extracting archive..."
  196. unzip -q logseq.zip
  197. # Find the extracted directory
  198. EXTRACTED_DIR=$(find . -maxdepth 2 -type d -name "Logseq-linux-x64*" | head -1)
  199. if [[ -z "$EXTRACTED_DIR" ]]; then
  200. log_error "Could not find extracted Logseq directory"
  201. rm -rf "$TEMP_DIR"
  202. exit 1
  203. fi
  204. # Install files
  205. log_info "Installing files..."
  206. if [[ "$USER_INSTALL" == false ]]; then
  207. mkdir -p "$INSTALL_DIR"
  208. cp -r "$EXTRACTED_DIR"/* "$INSTALL_DIR/"
  209. chmod +x "$INSTALL_DIR/Logseq"
  210. ln -sf "$INSTALL_DIR/Logseq" "$BIN_DIR/logseq"
  211. else
  212. mkdir -p "$INSTALL_DIR"
  213. cp -r "$EXTRACTED_DIR"/* "$INSTALL_DIR/"
  214. chmod +x "$INSTALL_DIR/Logseq"
  215. ln -sf "$INSTALL_DIR/Logseq" "$BIN_DIR/logseq"
  216. fi
  217. # Fix sandbox permissions
  218. if [[ "$USER_INSTALL" == false && -f "$INSTALL_DIR/chrome-sandbox" ]]; then
  219. log_info "Setting sandbox permissions..."
  220. chown root:root "$INSTALL_DIR/chrome-sandbox"
  221. chmod 4755 "$INSTALL_DIR/chrome-sandbox"
  222. fi
  223. # Desktop integration
  224. if [[ "$SKIP_DESKTOP" == false ]]; then
  225. log_info "Creating desktop integration..."
  226. DESKTOP_FILE="/usr/share/applications/logseq.desktop"
  227. if [[ "$USER_INSTALL" == true ]]; then
  228. mkdir -p ~/.local/share/applications/
  229. DESKTOP_FILE="$HOME/.local/share/applications/logseq.desktop"
  230. fi
  231. # Copy icon to standard location
  232. ICON_DIR="/usr/share/icons/hicolor/512x512/apps/"
  233. if [[ "$USER_INSTALL" == true ]]; then
  234. ICON_DIR="$HOME/.local/share/icons/hicolor/512x512/apps/"
  235. mkdir -p "$ICON_DIR"
  236. fi
  237. # Create desktop file
  238. cat > "$DESKTOP_FILE" << DESKTOP_EOF
  239. [Desktop Entry]
  240. Version=1.0
  241. Name=Logseq
  242. Comment=Logseq - A privacy-first, open-source platform for knowledge management and collaboration
  243. Exec=$INSTALL_DIR/Logseq $([ "$USER_INSTALL" = true ] && echo "--no-sandbox") %U
  244. Icon=$ICON_DIR/logseq.png
  245. Terminal=false
  246. Type=Application
  247. Categories=Office;Productivity;Utility;TextEditor;
  248. MimeType=application/x-logseq;
  249. StartupWMClass=Logseq
  250. DESKTOP_EOF
  251. # Make desktop file executable
  252. chmod +x "$DESKTOP_FILE"
  253. if [[ -f "$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png" ]]; then
  254. cp "$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png" "$ICON_DIR/logseq.png"
  255. # Update desktop file to use the copied icon
  256. if [[ "$USER_INSTALL" == false ]]; then
  257. sed -i 's|Icon=$INSTALL_DIR/resources/app.asar.unpacked/dist/icon.png|Icon=logseq|' "$DESKTOP_FILE"
  258. fi
  259. fi
  260. if [[ "$USER_INSTALL" == true && -f "$INSTALL_DIR/resources/app/icon.png" ]]; then
  261. cp "$INSTALL_DIR/resources/app/icon.png" "$ICON_DIR/logseq.png"
  262. fi
  263. # Update desktop database
  264. if [[ "$USER_INSTALL" == false ]]; then
  265. update-desktop-database /usr/share/applications/ 2>/dev/null || true
  266. else
  267. update-desktop-database ~/.local/share/applications/ 2>/dev/null || true
  268. fi
  269. fi
  270. # Clean up
  271. rm -rf "$TEMP_DIR"
  272. # Verify installation
  273. if command -v logseq >/dev/null 2>&1; then
  274. INSTALLED_VERSION=$(logseq --version 2>/dev/null | head -1 || echo "unknown")
  275. log_info "Logseq installed successfully!"
  276. log_info "Version: $INSTALLED_VERSION"
  277. log_info "Location: $INSTALL_DIR"
  278. log_info "Command: logseq"
  279. if [[ "$SKIP_DESKTOP" == false ]]; then
  280. log_info "Desktop integration: Enabled"
  281. log_info "You can find Logseq in your applications menu"
  282. fi
  283. else
  284. log_error "Installation completed but 'logseq' command not found in PATH"
  285. log_info "You may need to restart your terminal or add $BIN_DIR to your PATH"
  286. fi
  287. log_info "Installation completed successfully!"