#!/bin/bash # Set new writable directory APP_DIR="/home/node/app" GIT_REPO="https://github.com/abubasith456/Node-WLA.git" BRANCH="main" echo "🚀 Deployment started..." # Ensure the directory exists if [ -d "$APP_DIR" ]; then cd "$APP_DIR" # Check if it's a valid Git repository if [ -d ".git" ]; then echo "📂 Directory exists, pulling latest changes..." git reset --hard git pull origin "$BRANCH" else echo "⚠️ Not a valid Git repository. Removing directory and re-cloning..." rm -rf "$APP_DIR" git clone -b "$BRANCH" "$GIT_REPO" "$APP_DIR" fi else echo "📂 Directory not found. Cloning repository..." git clone -b "$BRANCH" "$GIT_REPO" "$APP_DIR" fi # Navigate to the app directory cd "$APP_DIR" # Install dependencies echo "📦 Installing dependencies..." npm install --unsafe-perm # Start the server echo "🚀 Starting the server..." npm start