#!/bin/bash

# USER="jacem"
# PASSWORD="af5ad3733ca6505ebca7de70dade9f6d"
# SERVER="46.101.147.121"

STAGE=${1:-developers}

shopt -s nocasematch
if [ "${STAGE}" = "developers" ]; then

echo "Deploying Developers";
USER="root"
PASSWORD="chk9BOsi"
SERVER="92.222.91.39"
PROJECT_PATH="/var/www/biss-api"

elif [ "${STAGE}" = "smart" ]; then

echo "Deploying SMART";
USER="bissuser"
PASSWORD="z5&^Y8dw*$^0s7LUaLad"
SERVER="41.231.112.19"
PROJECT_PATH="/var/www/html/bissdist"

fi

ssh -tt -C ${USER}:${PASSWORD}@${SERVER} \
    "cd ${PROJECT_PATH} \
    && git reset --hard origin/master \
    && git pull origin master \
    && mkdir -p backup_db  \
    && ./backup_database.sh \
    && php composer.phar install \
    && php artisan cache:clear \
    && chmod -R 777 storage/* \
    && chgrp -R www-data storage bootstrap/cache \
    && chmod -R ug+rwx storage bootstrap/cache \
    && chgrp -R www-data storage bootstrap/cache \
    && php artisan cache:clear \
    && exit"; 
    # && php artisan db:seed \
    # && php artisan api:generate --routePrefix='api/v1/*' --force --actAsUserId=1 \
 	# && php artisan migrate \
 	# && php artisan migrate:reset \
