#!/bin/bash
# Cron job: extracts deploy archive and restarts app
# Set up in cPanel → Cron Jobs → every minute:
#   * * * * * /bin/bash /home/atulyhco/deploy.sh

APP="/home/atulyhco/api-pwd.techdarshak.com"
TRIGGER="$APP/deploy.trigger"
ARCHIVE="$APP/deploy.tar.gz"

if [ -f "$TRIGGER" ]; then
    rm -f "$TRIGGER"
    cd "$APP" || exit 1
    tar xzf "$ARCHIVE" 2>/dev/null
    rm -f "$ARCHIVE"
    mkdir -p tmp && touch tmp/restart.txt
    echo "[$(date)] Deployed successfully" >> "$APP/deploy.log"
fi
