1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/bin/bash
- set -e
- # Check for required commands
- for cmd in node npm git sudo; do
- if ! command -v "$cmd" >/dev/null 2>&1; then
- 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
- exit 1
- fi
- done
- REPO_URL="https://github.com/orus-dev/sentryx.git"
- INSTALL_DIR="$HOME/sentryx"
- SERVICE_NAME="sentryx"
- SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
- NODE_BIN="$(which node)"
- RUN_USER="$(whoami)"
- # Backup if exists
- if [ -d "$INSTALL_DIR" ]; then
- echo "Sentryx already exists, backing up..."
- rm -rf "$INSTALL_DIR-backup"
- mv "$INSTALL_DIR" "$INSTALL_DIR-backup"
- fi
- # Clone as current user
- git clone "$REPO_URL" "$INSTALL_DIR"
- # Build as current user
- cd "$INSTALL_DIR"
- npm install
- npm run build
- # Create systemd service
- echo "Creating systemd service..."
- sudo tee "$SERVICE_FILE" > /dev/null <<EOF
- [Unit]
- Description=SentryX Server
- After=network.target
- [Service]
- Type=simple
- User=$RUN_USER
- WorkingDirectory=$INSTALL_DIR
- ExecStart="$NODE_BIN" "$INSTALL_DIR/node_modules/.bin/next" start
- Restart=on-failure
- Environment=NODE_ENV=production
- [Install]
- WantedBy=multi-user.target
- EOF
- sudo systemctl daemon-reload
- sudo systemctl enable --now "$SERVICE_NAME.service"
- echo "Done! Check service with: sudo systemctl status $SERVICE_NAME"
|