#!/bin/bash

echo "What branch are you deploying?"
read BRANCH

if [[ $BRANCH != "staging" && $BRANCH != "master"  ]]; then
    echo "Please type staging or master. Exiting"
    exit 1
fi


echo "Deploying branch $BRANCH"

if [[ $BRANCH == "staging" ]]; then
   echo "Stopping supervisor staging services."
   sudo supervisorctl stop contemporanea:*
fi

git fetch
git pull -r origin $BRANCH
composer install --no-dev --optimize-autoloader
php artisan cache:clear
php artisan migrate --force
php artisan migrate --path=/database/migrations/project --force

if [[ $BRANCH == "staging" ]]; then
   echo "Starting supervisor staging services."
   sudo supervisorctl start contemporanea:*
fi

