#!/bin/bash # LittleShop Deployment to Hostinger VPS # Uses the vps_hardening_key for authentication # Updated: 2025-09-19 set -e # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # Configuration HOSTINGER_HOST="srv1002428.hstgr.cloud" HOSTINGER_PORT="2255" HOSTINGER_USER="root" SSH_KEY="$HOME/.ssh/vps_hardening_key" echo -e "${GREEN}═══════════════════════════════════════════════════${NC}" echo -e "${GREEN} LittleShop Deployment to Hostinger VPS${NC}" echo -e "${GREEN}═══════════════════════════════════════════════════${NC}" echo "" # Ensure SSH key is available if [ ! -f "$SSH_KEY" ]; then echo -e "${YELLOW}Setting up SSH key...${NC}" cp /mnt/c/Production/Source/LittleShop/Hostinger/vps_hardening_key "$SSH_KEY" chmod 600 "$SSH_KEY" fi # Create deployment archives echo -e "${YELLOW}📦 Creating deployment archives...${NC}" cd /mnt/c/Production/Source/LittleShop tar -czf littleshop-release.tar.gz -C publish littleshop tar -czf telebot-release.tar.gz -C publish telebot echo -e "${GREEN}✅ Archives created${NC}" # Upload to Hostinger echo -e "${YELLOW}📤 Uploading to Hostinger VPS...${NC}" scp -i "$SSH_KEY" -P $HOSTINGER_PORT -o StrictHostKeyChecking=no \ littleshop-release.tar.gz \ telebot-release.tar.gz \ docker-compose.prod.yml \ Dockerfile \ .env.production.template \ $HOSTINGER_USER@$HOSTINGER_HOST:/tmp/ echo -e "${GREEN}✅ Files uploaded${NC}" # Deploy on server echo -e "${YELLOW}🚀 Deploying on server...${NC}" ssh -i "$SSH_KEY" -p $HOSTINGER_PORT -o StrictHostKeyChecking=no $HOSTINGER_USER@$HOSTINGER_HOST << 'ENDSSH' set -e # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' echo -e "${YELLOW}Setting up deployment directories...${NC}" # Create directories mkdir -p /opt/littleshop mkdir -p /opt/telebot mkdir -p /var/lib/littleshop mkdir -p /var/log/littleshop mkdir -p /backups/littleshop # Backup current deployment if exists if [ -d "/opt/littleshop/littleshop" ]; then echo "Creating backup..." tar -czf /backups/littleshop/backup-$(date +%Y%m%d-%H%M%S).tar.gz -C /opt littleshop || true fi # Stop existing services if running echo -e "${YELLOW}Stopping existing services...${NC}" systemctl stop littleshop 2>/dev/null || true systemctl stop telebot 2>/dev/null || true docker-compose -f /opt/littleshop/docker-compose.yml down 2>/dev/null || true # Extract new deployment echo -e "${YELLOW}Extracting new deployment...${NC}" tar -xzf /tmp/littleshop-release.tar.gz -C /opt/ tar -xzf /tmp/telebot-release.tar.gz -C /opt/ # Set permissions chmod +x /opt/littleshop/LittleShop || true chmod +x /opt/telebot/TeleBot || true # Setup environment file if [ ! -f /opt/littleshop/.env ]; then echo -e "${YELLOW}Setting up environment configuration...${NC}" cp /tmp/.env.production.template /opt/littleshop/.env # Update with BTCPay Server details cat >> /opt/littleshop/.env << 'EOF' # BTCPay Server Configuration (Hostinger VPS) BTCPAY_SERVER_URL=https://thebankofdebbie.giize.com BTCPAY_STORE_ID=CvdvHoncGLM7TdMYRAG6Z15YuxQfxeMWRYwi9gvPhh5R BTCPAY_API_KEY=3ff1f1e8c488ab9bb19b0c979c8fa2f1bf5e8dc5 BTCPAY_WEBHOOK_SECRET=webhook-secret-to-configure # Web Push VAPID Keys (Production) WEBPUSH_VAPID_PUBLIC_KEY=BMc6fFJZ8oIQKQzcl3kMnP9tTsjrm3oI_VxLt3lAGYUMWGInzDKn7jqclEoZzjvXy1QXGFb3dIun8mVBwh-QuS4 WEBPUSH_VAPID_PRIVATE_KEY=sX5KHgb5LRd-FV8XYTWN6p8TpMZcQ2y3mcKwKe50NeE # TeleBot Configuration TELEBOT_API_URL=http://localhost:8081 TELEBOT_API_KEY=production-api-key # JWT Secret (Generate a secure one) JWT_SECRET_KEY=your-super-secret-jwt-key-that-is-at-least-32-characters-long-production EOF fi # Create systemd service for LittleShop cat > /etc/systemd/system/littleshop.service << 'SERVICE' [Unit] Description=LittleShop E-Commerce API After=network.target [Service] Type=simple User=www-data WorkingDirectory=/opt/littleshop ExecStart=/opt/littleshop/LittleShop Restart=on-failure RestartSec=10 Environment="ASPNETCORE_URLS=http://localhost:8080" Environment="ASPNETCORE_ENVIRONMENT=Production" EnvironmentFile=/opt/littleshop/.env [Install] WantedBy=multi-user.target SERVICE # Create systemd service for TeleBot cat > /etc/systemd/system/telebot.service << 'SERVICE' [Unit] Description=LittleShop TeleBot Service After=network.target littleshop.service [Service] Type=simple User=www-data WorkingDirectory=/opt/telebot ExecStart=/opt/telebot/TeleBot Restart=on-failure RestartSec=10 Environment="ASPNETCORE_URLS=http://localhost:8081" Environment="ASPNETCORE_ENVIRONMENT=Production" EnvironmentFile=/opt/littleshop/.env [Install] WantedBy=multi-user.target SERVICE # Setup nginx configuration if not exists if [ ! -f /etc/nginx/sites-available/littleshop ]; then echo -e "${YELLOW}Configuring nginx...${NC}" cat > /etc/nginx/sites-available/littleshop << 'NGINX' server { listen 80; server_name littleshop.silverlabs.uk srv1002428.hstgr.cloud; client_max_body_size 50M; location / { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /telebot/ { rewrite ^/telebot/(.*)$ /$1 break; proxy_pass http://localhost:8081; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } NGINX ln -sf /etc/nginx/sites-available/littleshop /etc/nginx/sites-enabled/ fi # Reload systemd and start services echo -e "${YELLOW}Starting services...${NC}" systemctl daemon-reload systemctl enable littleshop systemctl enable telebot systemctl start littleshop systemctl start telebot # Reload nginx if installed if command -v nginx &> /dev/null; then nginx -t && systemctl reload nginx fi # Wait for services sleep 10 # Check service health echo -e "${YELLOW}Checking service health...${NC}" if curl -f -s http://localhost:8080/api/push/vapid-key > /dev/null; then echo -e "${GREEN}✅ LittleShop API is running${NC}" curl -s http://localhost:8080/api/push/vapid-key | python3 -m json.tool 2>/dev/null || true else echo -e "⚠️ LittleShop API health check failed" systemctl status littleshop --no-pager | head -20 fi # Clean up rm -f /tmp/littleshop-release.tar.gz rm -f /tmp/telebot-release.tar.gz rm -f /tmp/docker-compose.prod.yml rm -f /tmp/Dockerfile rm -f /tmp/.env.production.template echo -e "${GREEN}✅ Deployment complete!${NC}" # Show status echo "" echo "Service Status:" systemctl is-active littleshop && echo " LittleShop: Running" || echo " LittleShop: Not running" systemctl is-active telebot && echo " TeleBot: Running" || echo " TeleBot: Not running" # Show recent logs echo "" echo "Recent logs:" journalctl -u littleshop -n 5 --no-pager || true ENDSSH # Clean up local files rm -f littleshop-release.tar.gz rm -f telebot-release.tar.gz echo "" echo -e "${GREEN}═══════════════════════════════════════════════════${NC}" echo -e "${GREEN} Deployment Complete!${NC}" echo -e "${GREEN}═══════════════════════════════════════════════════${NC}" echo "" echo "📌 Service URLs:" echo " - LittleShop API: http://srv1002428.hstgr.cloud:8080" echo " - Admin Panel: http://srv1002428.hstgr.cloud:8080/admin" echo " - BTCPay Server: https://thebankofdebbie.giize.com" echo "" echo "🔧 Useful Commands:" echo " Check status: ssh -i $SSH_KEY -p 2255 root@srv1002428.hstgr.cloud 'systemctl status littleshop telebot'" echo " View logs: ssh -i $SSH_KEY -p 2255 root@srv1002428.hstgr.cloud 'journalctl -u littleshop -f'" echo "" echo "⚠️ Next Steps:" echo " 1. Update /opt/littleshop/.env on server with proper secrets" echo " 2. Configure BTCPay webhook URL" echo " 3. Set up SSL certificates with certbot"