#!/bin/bash # LittleShop Deployment Script for Hostinger VPS # This script installs LittleShop as a systemd service with localhost-only binding set -e echo "=== LittleShop Deployment Script ===" echo # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Please run as root (use sudo)" exit 1 fi # Variables APP_DIR="/opt/littleshop" SERVICE_FILE="/etc/systemd/system/littleshop.service" RUNTIME_VERSION="9.0" echo "1. Checking .NET Runtime..." if ! command -v dotnet &> /dev/null; then echo " .NET Runtime not found. Installing..." # Add Microsoft package repository wget https://packages.microsoft.com/config/debian/13/packages-microsoft-prod.deb -O packages-microsoft-prod.deb dpkg -i packages-microsoft-prod.deb rm packages-microsoft-prod.deb # Install .NET Runtime apt-get update apt-get install -y aspnetcore-runtime-$RUNTIME_VERSION echo " .NET Runtime installed successfully" else echo " .NET Runtime already installed: $(dotnet --version)" fi echo echo "2. Creating application directory..." mkdir -p $APP_DIR mkdir -p $APP_DIR/logs mkdir -p $APP_DIR/uploads echo echo "3. Stopping existing service (if any)..." if systemctl is-active --quiet littleshop; then systemctl stop littleshop echo " Service stopped" else echo " No existing service found" fi echo echo "4. Copying application files..." cp -r ./* $APP_DIR/ chmod +x $APP_DIR/LittleShop echo echo "5. Setting up database..." if [ ! -f "$APP_DIR/littleshop-production.db" ]; then echo " Database will be created on first run" else echo " Existing database found, will be preserved" fi echo echo "6. Setting permissions..." chown -R www-data:www-data $APP_DIR chmod 750 $APP_DIR chmod -R 640 $APP_DIR/* chmod 750 $APP_DIR/LittleShop chmod -R 770 $APP_DIR/logs chmod -R 770 $APP_DIR/uploads echo echo "7. Installing systemd service..." cp $APP_DIR/littleshop.service $SERVICE_FILE systemctl daemon-reload systemctl enable littleshop echo echo "8. Starting service..." systemctl start littleshop echo echo "9. Checking service status..." sleep 3 if systemctl is-active --quiet littleshop; then echo " ✓ Service is running" echo echo "=== Deployment Complete ===" echo echo "Service Status:" systemctl status littleshop --no-pager | head -n 10 echo echo "Application is running on: http://127.0.0.1:5000" echo "Logs location: $APP_DIR/logs/" echo echo "Useful commands:" echo " - Check status: systemctl status littleshop" echo " - View logs: journalctl -u littleshop -f" echo " - Restart: systemctl restart littleshop" echo " - Stop: systemctl stop littleshop" echo echo "To test locally on the server:" echo " curl http://127.0.0.1:5000/api/health" else echo " ✗ Service failed to start" echo " Check logs with: journalctl -u littleshop -n 50" exit 1 fi echo echo "10. Testing health endpoint..." sleep 2 if curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:5000/api/health | grep -q "200"; then echo " ✓ Health check passed" else echo " ⚠ Health check failed or service still starting" echo " Try again with: curl http://127.0.0.1:5000/api/health" fi echo echo "=== Setup Complete ===" echo echo "IMPORTANT: Edit /opt/littleshop/appsettings.Localhost.json to configure:" echo " - JWT secret key" echo " - SilverPay API credentials" echo " - Royal Mail API credentials (if using)" echo " - WebPush VAPID keys (if using)" echo echo "After editing configuration, restart the service:" echo " systemctl restart littleshop"