#!/bin/bash echo "==== STEP 1: Install Node.js 20 & PM2 ====" curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt-get install -y nodejs build-essential sudo npm install -g pm2 echo "==== STEP 2: Install PostgreSQL ====" sudo apt-get update sudo apt-get install -y postgresql postgresql-contrib echo "==== STEP 4: Create PostgreSQL user & DB for Medusa ====" read -p "Enter Medusa DB Username: " DB_USER read -p "Enter Medusa DB Password: " DB_PASS read -p "Enter Medusa Database Name: " DB_NAME sudo -u postgres psql < .env DATABASE_URL=postgres://$DB_USER:$DB_PASS@localhost:5432/$DB_NAME ADMIN_ONBOARDING=true JWT_SECRET=$(openssl rand -hex 16) COOKIE_SECRET=$(openssl rand -hex 16) EOT echo "==== STEP 8: Install dependencies ====" npm install echo "==== STEP 9: Build Medusa for production ====" npm run build echo "==== STEP 10: Start Medusa with PM2 ====" pm2 start "npm run start" --name medusa pm2 save pm2 startup systemd -u $USER --hp $HOME echo "==== SETUP COMPLETE ====" echo "Medusa API is now running at: http://$DOMAIN" echo "Use 'pm2 logs medusa' to monitor."