|
@@ -25,34 +25,115 @@ echo "Installation directory: $INSTALL_DIR"
|
|
|
echo "Service name: $SERVICE_NAME"
|
|
echo "Service name: $SERVICE_NAME"
|
|
|
echo ""
|
|
echo ""
|
|
|
|
|
|
|
|
-# Prompt for API key
|
|
|
|
|
-echo "Please enter the API key for authentication:"
|
|
|
|
|
-read -s API_KEY
|
|
|
|
|
-echo ""
|
|
|
|
|
-
|
|
|
|
|
-if [ -z "$API_KEY" ]; then
|
|
|
|
|
- echo "Error: API key cannot be empty"
|
|
|
|
|
- exit 1
|
|
|
|
|
|
|
+# Check if application is already installed
|
|
|
|
|
+EXISTING_INSTALLATION=false
|
|
|
|
|
+EXISTING_ENV_FILE="$INSTALL_DIR/.env"
|
|
|
|
|
+
|
|
|
|
|
+if [ -f "$EXISTING_ENV_FILE" ]; then
|
|
|
|
|
+ EXISTING_INSTALLATION=true
|
|
|
|
|
+ echo "Existing installation detected!"
|
|
|
|
|
+ echo "Found existing configuration at: $EXISTING_ENV_FILE"
|
|
|
|
|
+ echo ""
|
|
|
|
|
+
|
|
|
|
|
+ # Load existing configuration
|
|
|
|
|
+ source "$EXISTING_ENV_FILE" 2>/dev/null || true
|
|
|
|
|
+
|
|
|
|
|
+ # Set defaults from existing config or fallback to hardcoded defaults
|
|
|
|
|
+ EXISTING_API_KEY="$API_KEY"
|
|
|
|
|
+ EXISTING_HOST="${HOST:-0.0.0.0}"
|
|
|
|
|
+ EXISTING_PORT="${PORT:-3000}"
|
|
|
|
|
+ EXISTING_MAX_CONCURRENT_JOBS="${MAX_CONCURRENT_JOBS:-3}"
|
|
|
|
|
+
|
|
|
|
|
+ echo "Current configuration:"
|
|
|
|
|
+ echo " API Key: ${EXISTING_API_KEY:0:8}... (masked)"
|
|
|
|
|
+ echo " Host: $EXISTING_HOST"
|
|
|
|
|
+ echo " Port: $EXISTING_PORT"
|
|
|
|
|
+ echo " Max Concurrent Jobs: $EXISTING_MAX_CONCURRENT_JOBS"
|
|
|
|
|
+ echo ""
|
|
|
|
|
+
|
|
|
|
|
+ # Ask if user wants to keep existing configuration
|
|
|
|
|
+ echo "Do you want to keep the existing configuration? [Y/n]:"
|
|
|
|
|
+ read KEEP_CONFIG
|
|
|
|
|
+ KEEP_CONFIG=${KEEP_CONFIG:-Y}
|
|
|
|
|
+
|
|
|
|
|
+ if [[ "$KEEP_CONFIG" =~ ^[Yy]([Ee][Ss])?$ ]]; then
|
|
|
|
|
+ echo "Using existing configuration..."
|
|
|
|
|
+ API_KEY="$EXISTING_API_KEY"
|
|
|
|
|
+ HOST="$EXISTING_HOST"
|
|
|
|
|
+ PORT="$EXISTING_PORT"
|
|
|
|
|
+ MAX_CONCURRENT_JOBS="$EXISTING_MAX_CONCURRENT_JOBS"
|
|
|
|
|
+ SKIP_CONFIG_PROMPTS=true
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "Will prompt for new configuration..."
|
|
|
|
|
+ SKIP_CONFIG_PROMPTS=false
|
|
|
|
|
+ fi
|
|
|
|
|
+ echo ""
|
|
|
|
|
+else
|
|
|
|
|
+ echo "No existing installation found. Starting fresh installation..."
|
|
|
|
|
+ echo ""
|
|
|
|
|
+ SKIP_CONFIG_PROMPTS=false
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
-# Prompt for host/IP address
|
|
|
|
|
-echo "Enter the host/IP address to listen on:"
|
|
|
|
|
-echo " - 0.0.0.0 for all interfaces (accessible from anywhere)"
|
|
|
|
|
-echo " - 127.0.0.1 for localhost only (accessible only from this machine)"
|
|
|
|
|
-echo " - or enter a specific IP address"
|
|
|
|
|
-echo "Default: 0.0.0.0"
|
|
|
|
|
-read HOST
|
|
|
|
|
-HOST=${HOST:-0.0.0.0}
|
|
|
|
|
-
|
|
|
|
|
-# Prompt for port (optional)
|
|
|
|
|
-echo "Enter the HTTP port (default: 3000):"
|
|
|
|
|
-read PORT
|
|
|
|
|
-PORT=${PORT:-3000}
|
|
|
|
|
-
|
|
|
|
|
-# Prompt for max concurrent jobs (optional)
|
|
|
|
|
-echo "Enter the maximum number of concurrent jobs (default: 3):"
|
|
|
|
|
-read MAX_CONCURRENT_JOBS
|
|
|
|
|
-MAX_CONCURRENT_JOBS=${MAX_CONCURRENT_JOBS:-3}
|
|
|
|
|
|
|
+# Configuration prompts (skip if using existing config)
|
|
|
|
|
+if [ "$SKIP_CONFIG_PROMPTS" != "true" ]; then
|
|
|
|
|
+ # Prompt for API key
|
|
|
|
|
+ if [ "$EXISTING_INSTALLATION" = "true" ]; then
|
|
|
|
|
+ echo "Enter new API key for authentication (current: ${EXISTING_API_KEY:0:8}...):"
|
|
|
|
|
+ echo "Press Enter to keep current API key, or enter new one:"
|
|
|
|
|
+ read -s NEW_API_KEY
|
|
|
|
|
+ if [ -n "$NEW_API_KEY" ]; then
|
|
|
|
|
+ API_KEY="$NEW_API_KEY"
|
|
|
|
|
+ else
|
|
|
|
|
+ API_KEY="$EXISTING_API_KEY"
|
|
|
|
|
+ fi
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "Please enter the API key for authentication:"
|
|
|
|
|
+ read -s API_KEY
|
|
|
|
|
+ fi
|
|
|
|
|
+ echo ""
|
|
|
|
|
+
|
|
|
|
|
+ if [ -z "$API_KEY" ]; then
|
|
|
|
|
+ echo "Error: API key cannot be empty"
|
|
|
|
|
+ exit 1
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ # Prompt for host/IP address
|
|
|
|
|
+ echo "Enter the host/IP address to listen on:"
|
|
|
|
|
+ echo " - 0.0.0.0 for all interfaces (accessible from anywhere)"
|
|
|
|
|
+ echo " - 127.0.0.1 for localhost only (accessible only from this machine)"
|
|
|
|
|
+ echo " - or enter a specific IP address"
|
|
|
|
|
+ if [ "$EXISTING_INSTALLATION" = "true" ]; then
|
|
|
|
|
+ echo "Current: $EXISTING_HOST, Default: $EXISTING_HOST"
|
|
|
|
|
+ read HOST
|
|
|
|
|
+ HOST=${HOST:-$EXISTING_HOST}
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "Default: 0.0.0.0"
|
|
|
|
|
+ read HOST
|
|
|
|
|
+ HOST=${HOST:-0.0.0.0}
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ # Prompt for port (optional)
|
|
|
|
|
+ if [ "$EXISTING_INSTALLATION" = "true" ]; then
|
|
|
|
|
+ echo "Enter the HTTP port (current: $EXISTING_PORT):"
|
|
|
|
|
+ read PORT
|
|
|
|
|
+ PORT=${PORT:-$EXISTING_PORT}
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "Enter the HTTP port (default: 3000):"
|
|
|
|
|
+ read PORT
|
|
|
|
|
+ PORT=${PORT:-3000}
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ # Prompt for max concurrent jobs (optional)
|
|
|
|
|
+ if [ "$EXISTING_INSTALLATION" = "true" ]; then
|
|
|
|
|
+ echo "Enter the maximum number of concurrent jobs (current: $EXISTING_MAX_CONCURRENT_JOBS):"
|
|
|
|
|
+ read MAX_CONCURRENT_JOBS
|
|
|
|
|
+ MAX_CONCURRENT_JOBS=${MAX_CONCURRENT_JOBS:-$EXISTING_MAX_CONCURRENT_JOBS}
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "Enter the maximum number of concurrent jobs (default: 3):"
|
|
|
|
|
+ read MAX_CONCURRENT_JOBS
|
|
|
|
|
+ MAX_CONCURRENT_JOBS=${MAX_CONCURRENT_JOBS:-3}
|
|
|
|
|
+ fi
|
|
|
|
|
+fi
|
|
|
|
|
|
|
|
echo ""
|
|
echo ""
|
|
|
echo "Configuration:"
|
|
echo "Configuration:"
|
|
@@ -161,14 +242,30 @@ systemctl daemon-reload
|
|
|
echo "Enabling service..."
|
|
echo "Enabling service..."
|
|
|
systemctl enable "$SERVICE_NAME"
|
|
systemctl enable "$SERVICE_NAME"
|
|
|
|
|
|
|
|
-# Start service
|
|
|
|
|
-echo "Starting service..."
|
|
|
|
|
-systemctl start "$SERVICE_NAME"
|
|
|
|
|
|
|
+# Handle service startup based on existing installation
|
|
|
|
|
+if [ "$EXISTING_INSTALLATION" = "true" ]; then
|
|
|
|
|
+ # Check if service is already running
|
|
|
|
|
+ if systemctl is-active --quiet "$SERVICE_NAME"; then
|
|
|
|
|
+ echo "Service is currently running. Restarting with new configuration..."
|
|
|
|
|
+ systemctl restart "$SERVICE_NAME"
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "Starting service..."
|
|
|
|
|
+ systemctl start "$SERVICE_NAME"
|
|
|
|
|
+ fi
|
|
|
|
|
+else
|
|
|
|
|
+ # Fresh installation - start service
|
|
|
|
|
+ echo "Starting service..."
|
|
|
|
|
+ systemctl start "$SERVICE_NAME"
|
|
|
|
|
+fi
|
|
|
|
|
|
|
|
# Check status
|
|
# Check status
|
|
|
echo ""
|
|
echo ""
|
|
|
echo "==================================="
|
|
echo "==================================="
|
|
|
-echo "Installation completed successfully!"
|
|
|
|
|
|
|
+if [ "$EXISTING_INSTALLATION" = "true" ]; then
|
|
|
|
|
+ echo "Update completed successfully!"
|
|
|
|
|
+else
|
|
|
|
|
+ echo "Installation completed successfully!"
|
|
|
|
|
+fi
|
|
|
echo "==================================="
|
|
echo "==================================="
|
|
|
echo ""
|
|
echo ""
|
|
|
echo "Service status:"
|
|
echo "Service status:"
|
|
@@ -181,6 +278,13 @@ echo " Restart service: sudo systemctl restart $SERVICE_NAME"
|
|
|
echo " View logs: sudo journalctl -u $SERVICE_NAME -f"
|
|
echo " View logs: sudo journalctl -u $SERVICE_NAME -f"
|
|
|
echo " Check status: sudo systemctl status $SERVICE_NAME"
|
|
echo " Check status: sudo systemctl status $SERVICE_NAME"
|
|
|
echo ""
|
|
echo ""
|
|
|
-echo "API is available at: http://localhost:$PORT"
|
|
|
|
|
-echo "Health check: http://localhost:$PORT/health"
|
|
|
|
|
|
|
+# Display appropriate URL based on host configuration
|
|
|
|
|
+if [ "$HOST" = "0.0.0.0" ]; then
|
|
|
|
|
+ DISPLAY_HOST="localhost"
|
|
|
|
|
+else
|
|
|
|
|
+ DISPLAY_HOST="$HOST"
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
|
|
+echo "API is available at: http://$DISPLAY_HOST:$PORT"
|
|
|
|
|
+echo "Health check: http://$DISPLAY_HOST:$PORT/health"
|
|
|
echo ""
|
|
echo ""
|