#!/bin/bash # Fix SilverPAY on Hostinger Server # This script configures SilverPAY with all required settings echo "=========================================" echo " FIXING SILVERPAY ON HOSTINGER" echo "=========================================" # Server details SERVER="31.97.57.205" PORT="2255" PASSWORD='I6s1Wnm7B$9Bd6t@' # Create the configuration script cat > /tmp/fix_silverpay.sh << 'EOF' #!/bin/bash echo "1. Checking SilverPAY container status..." docker ps -a | grep silverpay echo -e "\n2. Checking SilverPAY logs for errors..." CONTAINER_ID=$(docker ps -a | grep silverpay | awk '{print $1}' | head -1) if [ ! -z "$CONTAINER_ID" ]; then echo "Container ID: $CONTAINER_ID" docker logs --tail 50 $CONTAINER_ID 2>&1 | grep -E "ERROR|Failed|Exception|error|failed" fi echo -e "\n3. Checking if SilverPAY directory exists..." if [ -d "/root/silverpay" ]; then cd /root/silverpay echo "Found SilverPAY at /root/silverpay" # Check for .env file if [ ! -f ".env" ]; then echo "Creating .env file with proper configuration..." cat > .env << 'ENVEOF' # SilverPAY Environment Configuration ENVIRONMENT=production DEBUG=false API_HOST=0.0.0.0 API_PORT=8001 # Database DATABASE_URL=sqlite:///./data/silverpay.db # HD Wallet Mnemonic (CHANGE IN PRODUCTION!) WALLET_MNEMONIC="profit canyon draft system example volcano humor pelican rotate merit purity bomb" # API Keys BLOCKCYPHER_TOKEN="" BLOCKNOMICS_API_KEY="" BLOCKCHAIR_API_KEY="" # Exchange Rate API EXCHANGE_RATE_API_KEY="" EXCHANGE_RATE_API_URL="https://api.exchangerate-api.com/v4/latest/" # Webhook Configuration WEBHOOK_SECRET="webhook_secret_2025" # Logging LOG_LEVEL=INFO # Fiat Currency DEFAULT_FIAT_CURRENCY=GBP # Testnet mode (set to true for testing) USE_TESTNET=false ENVEOF echo "Created .env file" else echo ".env file already exists" fi # Initialize database echo -e "\n4. Initializing database..." if [ ! -d "data" ]; then mkdir -p data fi # Check if we have the schema file if [ -f "database/schema.sql" ]; then echo "Found schema.sql, initializing database..." sqlite3 data/silverpay.db < database/schema.sql 2>/dev/null || echo "Database might already be initialized" fi # Create initialization SQL if schema.sql doesn't exist if [ ! -f "database/schema.sql" ]; then echo "Creating database schema..." cat > /tmp/init_db.sql << 'SQLEOF' -- SilverPAY Database Schema CREATE TABLE IF NOT EXISTS orders ( id TEXT PRIMARY KEY, external_id TEXT UNIQUE NOT NULL, amount DECIMAL(20,8) NOT NULL, currency TEXT NOT NULL, payment_address TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, expires_at TIMESTAMP NOT NULL, paid_at TIMESTAMP, tx_hash TEXT, confirmations INTEGER DEFAULT 0, webhook_url TEXT, metadata TEXT ); CREATE INDEX IF NOT EXISTS idx_orders_status ON orders(status); CREATE INDEX IF NOT EXISTS idx_orders_external_id ON orders(external_id); CREATE INDEX IF NOT EXISTS idx_orders_payment_address ON orders(payment_address); CREATE TABLE IF NOT EXISTS wallets ( id INTEGER PRIMARY KEY AUTOINCREMENT, currency TEXT NOT NULL, address TEXT UNIQUE NOT NULL, private_key TEXT NOT NULL, derivation_path TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, last_used_at TIMESTAMP ); CREATE INDEX IF NOT EXISTS idx_wallets_currency ON wallets(currency); CREATE INDEX IF NOT EXISTS idx_wallets_address ON wallets(address); CREATE TABLE IF NOT EXISTS exchange_rates ( id INTEGER PRIMARY KEY AUTOINCREMENT, from_currency TEXT NOT NULL, to_currency TEXT NOT NULL, rate DECIMAL(20,8) NOT NULL, source TEXT NOT NULL, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX IF NOT EXISTS idx_exchange_rates ON exchange_rates(from_currency, to_currency); SQLEOF sqlite3 data/silverpay.db < /tmp/init_db.sql echo "Database schema created" fi echo -e "\n5. Restarting SilverPAY container..." # Stop existing container if [ ! -z "$CONTAINER_ID" ]; then docker stop $CONTAINER_ID docker rm $CONTAINER_ID fi # Check if we have docker-compose if [ -f "docker-compose.yml" ]; then echo "Starting with docker-compose..." docker-compose up -d else echo "Starting with docker run..." # Run SilverPAY container docker run -d \ --name silverpay \ --restart unless-stopped \ -p 8001:8001 \ -v $(pwd)/data:/app/data \ -v $(pwd)/.env:/app/.env \ -e PYTHONUNBUFFERED=1 \ silverpay:latest \ || echo "Container might already exist" fi # Wait for container to start sleep 5 echo -e "\n6. Checking new container status..." docker ps | grep silverpay echo -e "\n7. Testing health endpoint..." curl -s http://localhost:8001/health || echo "Health check failed" echo -e "\n8. Testing order creation..." curl -X POST http://localhost:8001/api/v1/orders \ -H "Content-Type: application/json" \ -H "X-API-Key: sp_live_key_2025_production" \ -d '{ "external_id": "test-'$(date +%s)'", "fiat_amount": 10.00, "fiat_currency": "GBP", "currency": "BTC", "webhook_url": "http://localhost:8080/api/orders/payments/webhook", "expires_in_hours": 24 }' 2>/dev/null | python3 -m json.tool || echo "Order creation test failed" else echo "SilverPAY directory not found at /root/silverpay" echo "Checking alternative location at /opt/silverpay..." if [ -d "/opt/silverpay" ]; then cd /opt/silverpay echo "Found at /opt/silverpay" else echo "ERROR: Cannot find SilverPAY installation!" echo "You may need to deploy SilverPAY first" fi fi echo -e "\n=========================================" echo " FIX COMPLETE - CHECK OUTPUT ABOVE" echo "=========================================" EOF # Run the fix script on the server echo "Connecting to server and running fix script..." sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no root@$SERVER -p $PORT 'bash -s' < /tmp/fix_silverpay.sh echo -e "\n✅ Fix script execution complete!" echo "Check the output above for any errors."