#!/bin/bash # Deploy TeleBot to Hostinger server with source code build # This script builds TeleBot from source and deploys it set -e echo "🚀 Starting TeleBot deployment to Hostinger..." # Configuration REMOTE_HOST="srv1002428.hstgr.cloud" REMOTE_USER="root" REMOTE_PORT="2255" REMOTE_DIR="/opt/telebot" REMOTE_PASS="Proxmox8426!" # SSH command with password SSH_CMD="sshpass -p '${REMOTE_PASS}' ssh -p ${REMOTE_PORT} -o StrictHostKeyChecking=no" SCP_CMD="sshpass -p '${REMOTE_PASS}' scp -P ${REMOTE_PORT} -o StrictHostKeyChecking=no" RSYNC_CMD="sshpass -p '${REMOTE_PASS}' rsync" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' echo -e "${YELLOW}Step 1: Creating deployment directory on remote server...${NC}" ${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} "mkdir -p ${REMOTE_DIR}" echo -e "${YELLOW}Step 2: Copying source code to remote server...${NC}" # Create a clean copy excluding unnecessary files ${RSYNC_CMD} -avz --delete \ --exclude 'bin/' \ --exclude 'obj/' \ --exclude '.git/' \ --exclude '*.log' \ --exclude 'logs/' \ --exclude 'data/' \ --exclude 'image_cache/' \ -e "ssh -p ${REMOTE_PORT} -o StrictHostKeyChecking=no" \ ./ ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}/ echo -e "${YELLOW}Step 3: Creating .env file from environment variables...${NC}" ${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} << 'EOF' cd /opt/telebot # Create .env file with production configuration cat > .env << 'ENVEOF' # TeleBot Production Configuration BOT_TOKEN=7569267607:AAFcXs3qeHqr_KKiGSb2EShJJLznNBXRfB8 WEBHOOK_URL=https://telebot.thebankofdebbie.giize.com/api/telegram/webhook LITTLESHOP_API_KEY=your-api-key-here # Database DATABASE_CONNECTION_STRING=Data Source=/app/data/telebot.db # Logging LOG_LEVEL=Information ENVEOF echo ".env file created" EOF echo -e "${YELLOW}Step 4: Building and deploying TeleBot container...${NC}" ${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} << 'EOF' cd /opt/telebot # Stop existing container if running echo "Stopping existing TeleBot container..." docker stop telebot 2>/dev/null || true docker rm telebot 2>/dev/null || true # Build new image from source echo "Building TeleBot image from source code..." docker build -t telebot:latest -f TeleBot/TeleBot/Dockerfile . # Create necessary directories with proper permissions echo "Creating data directories..." mkdir -p /opt/telebot/logs mkdir -p /opt/telebot/data mkdir -p /opt/telebot/image_cache # Set permissions for the telebot user inside container (UID 1001 typically) chown -R 1001:1001 /opt/telebot/logs chown -R 1001:1001 /opt/telebot/data chown -R 1001:1001 /opt/telebot/image_cache # Run the container echo "Starting TeleBot container..." docker run -d \ --name telebot \ --restart unless-stopped \ --network littleshop-network \ --env-file .env \ -e ASPNETCORE_ENVIRONMENT=Production \ -e LittleShopApi__BaseUrl=http://littleshop-admin:8080 \ -e TelegramBot__UseWebhook=false \ -e Logging__LogLevel__Default=Information \ -v /opt/telebot/logs:/app/logs \ -v /opt/telebot/data:/app/data \ -v /opt/telebot/image_cache:/app/image_cache \ telebot:latest echo "Waiting for container to start..." sleep 10 # Check container status docker ps | grep telebot docker logs --tail 20 telebot EOF echo -e "${GREEN}✅ TeleBot deployment complete!${NC}" echo -e "${GREEN}Container should now be running with latest code from source${NC}" echo "" echo "To check status:" echo " ${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} 'docker logs telebot'" echo " ${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} 'docker ps | grep telebot'"