install.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. set -e
  3. # Check for required commands
  4. for cmd in node npm git sudo; do
  5. if ! command -v "$cmd" >/dev/null 2>&1; then
  6. echo "Error: Required command '$cmd' is not installed or not in PATH. For more info: https://github.com/orus-dev/sentryx/wiki/Common-errors" >&2
  7. exit 1
  8. fi
  9. done
  10. REPO_URL="https://github.com/orus-dev/sentryx.git"
  11. INSTALL_DIR="$HOME/sentryx"
  12. SERVICE_NAME="sentryx"
  13. SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
  14. NODE_BIN="$(which node)"
  15. RUN_USER="$(whoami)"
  16. # Backup if exists
  17. if [ -d "$INSTALL_DIR" ]; then
  18. echo "Sentryx already exists, backing up..."
  19. rm -rf "$INSTALL_DIR-backup"
  20. mv "$INSTALL_DIR" "$INSTALL_DIR-backup"
  21. fi
  22. # Clone as current user
  23. git clone "$REPO_URL" "$INSTALL_DIR"
  24. # Build as current user
  25. cd "$INSTALL_DIR"
  26. npm install
  27. npm run build
  28. # Create systemd service
  29. echo "Creating systemd service..."
  30. sudo tee "$SERVICE_FILE" > /dev/null <<EOF
  31. [Unit]
  32. Description=SentryX Server
  33. After=network.target
  34. [Service]
  35. Type=simple
  36. User=$RUN_USER
  37. WorkingDirectory=$INSTALL_DIR
  38. ExecStart="$NODE_BIN" "$INSTALL_DIR/node_modules/.bin/next" start
  39. Restart=on-failure
  40. Environment=NODE_ENV=production
  41. [Install]
  42. WantedBy=multi-user.target
  43. EOF
  44. sudo systemctl daemon-reload
  45. sudo systemctl enable --now "$SERVICE_NAME.service"
  46. echo "Done! Check service with: sudo systemctl status $SERVICE_NAME"