#!/bin/bash GREEN='\033[0;32m' RED='\033[0;31m' NO_COLOR='\033[0m' APP_PATH='/var/www' API_PATH="${APP_PATH}/api" FRONTEND_PATH="${APP_PATH}/frontend" if [ ! -d $APP_PATH ] then echo -e "${RED}" echo "############################################################" echo "### ###" echo "### Aplication directory not found ###" echo "### ###" echo "############################################################" echo -e "${NO_COLOR}" exit 1 fi ########################## REPOSITORY ########################## cd $APP_PATH echo -e "${GREEN}" echo "############################################################" echo "### ###" echo "### Updating repository... ###" echo "### ###" echo "############################################################" echo -e "${NO_COLOR}" git config --global --add safe.directory $APP_PATH CURRENT_BRANCH=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match) while true; do echo -e "Current branch: ${GREEN}${CURRENT_BRANCH}${NO_COLOR}" read -p "Do you want to proceed? (y/n) " answer case $answer in [yY] ) break;; [nN] ) exit 1;; * ) echo -e "Invalid answer\n";; esac done echo if ! git fetch; then exit 1 fi echo read -p 'New version: ' new_version if ! git checkout $new_version; then exit 1 fi ################################ API ################################# cd $API_PATH echo -e "${GREEN}" echo "############################################################" echo "### ###" echo "### Installing api dependencies... ###" echo "### ###" echo "############################################################" echo -e "${NO_COLOR}" if ! composer install; then exit 1 fi echo -e "${GREEN}" echo "############################################################" echo "### ###" echo "### Caching api routes... ###" echo "### ###" echo "############################################################" echo -e "${NO_COLOR}" if ! php artisan route:cache; then exit 1 fi echo -e "${GREEN}" echo "############################################################" echo "### ###" echo "### Updating api files permissions... ###" echo "### ###" echo "############################################################" echo -e "${NO_COLOR}" if ! find $API_PATH -path $API_PATH/storage -prune -o -exec chown www-data:www-data {} +; then exit 1 fi echo -e "${GREEN}Files permissions updated!${NO_COLOR}" echo -e "${GREEN}" echo "############################################################" echo "### ###" echo "### Updating databases... ###" echo "### ###" echo "############################################################" echo -e "${NO_COLOR}" if ! php artisan publish; then exit 1 fi ############################## FRONTEND ############################## cd $FRONTEND_PATH echo -e "${GREEN}" echo "############################################################" echo "### ###" echo "### Installing frontend dependencies... ###" echo "### ###" echo "############################################################" echo -e "${NO_COLOR}" if ! npm ci; then exit 1 fi echo -e "${GREEN}" echo "############################################################" echo "### ###" echo "### Building frontend application... ###" echo "### ###" echo "############################################################" echo -e "${NO_COLOR}" if ! npm run build; then exit 1 fi ###################################################################### echo -e "${GREEN}" echo "############################################################" echo "### ###" echo "### All done. ###" echo "### ###" echo "############################################################" echo -e "${NO_COLOR}" exit 0