Last active
November 21, 2018 20:32
-
-
Save dnetix/51c89f562fa1cd66cc47626ef757443b to your computer and use it in GitHub Desktop.
Prepares basic actions over installed projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Prepares sites to be updated though the install.sh | |
ORIGIN_PATH=/var/www/vhosts/placetopay.com/sites/ | |
HOME_PATH=/home/diegocalle/ | |
BACKUP_PATH=/home/diegocalle/backup/co_ | |
ACTION=$1 | |
cd ${HOME_PATH} | |
if [[ ${ACTION} == "prepare" ]] | |
then | |
# CODE TO PREPARE | |
if [ -d ${HOME_PATH}redirection ] || [ -d ${HOME_PATH}rest-services ] | |
then | |
echo "Projects already exists on the home directory" | |
read -p "Do you want to clean them up? (y/n) " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo "" | |
sudo rm -rf ${HOME_PATH}redirection ${HOME_PATH}rest-services | |
if [ $? == 0 ] | |
then | |
echo "Successfully removed the home projects" | |
else | |
echo "ERROR Cleaning up the projects on home path" | |
exit 1 | |
fi | |
else | |
echo "" | |
exit 1 | |
fi | |
fi | |
echo "Copying REDIRECTION and RESTSERVICES to the home path" | |
sudo cp -rp ${ORIGIN_PATH}redirection ${ORIGIN_PATH}rest-services ${HOME_PATH} | |
echo -e "\nEntering REDIRECTION" | |
cd ${HOME_PATH}redirection | |
echo "Cleaning up additional modifications" | |
git reset --hard | |
BRANCH=$(git symbolic-ref -q --short HEAD) | |
echo "Pulling newest version of ${BRANCH}" | |
git pull origin ${BRANCH} --tags | |
echo "Installing dependencies" | |
composer install | |
echo "Cleaning up PHP caches" | |
php artisan config:clear && php artisan route:clear && php artisan view:clear | |
echo -e "\nEntering RESTSERVICES" | |
cd ${HOME_PATH}rest-services | |
echo "Cleaning up additional modifications" | |
git reset --hard | |
BRANCH=$(git symbolic-ref -q --short HEAD) | |
echo "Pulling newest version of ${BRANCH}" | |
git pull origin ${BRANCH} --tags | |
echo "Installing dependencies" | |
composer install | |
echo "Cleaning up PHP caches" | |
php artisan config:clear && php artisan route:clear && php artisan view:clear | |
echo -e "\nPreparation finished" | |
elif [[ ${ACTION} == "install" ]] | |
then | |
# CODE TO INSTALL | |
if [ -d ${BACKUP_PATH}redirection ] || [ -d ${BACKUP_PATH}rest-services ] | |
then | |
echo "Projects already exists on the BACKUP directory" | |
read -p "Do you want to clean them up? (y/n) " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo "" | |
sudo rm -rf ${BACKUP_PATH}redirection ${BACKUP_PATH}rest-services | |
if [ $? == 0 ] | |
then | |
echo "Successfully removed the backup projects" | |
else | |
echo "ERROR Cleaning up the projects on backup path" | |
exit 1 | |
fi | |
else | |
echo "" | |
exit 1 | |
fi | |
fi | |
read -p "Do you really want to install ${ORIGIN_PATH} (y/n) " -n 1 -r | |
if [[ $REPLY =~ ^[nN]$ ]] | |
then | |
echo "" | |
exit 1 | |
fi | |
echo "" | |
echo "Backing up projects" | |
echo "REDIRECTION to ${BACKUP_PATH}redirection" | |
sudo mv ${ORIGIN_PATH}redirection ${BACKUP_PATH}redirection | |
echo "REST SERVICES to ${BACKUP_PATH}rest-services" | |
sudo mv ${ORIGIN_PATH}rest-services ${BACKUP_PATH}rest-services | |
echo "Installing new REDIRECTION" | |
sudo cp -rp ${HOME_PATH}redirection ${ORIGIN_PATH} | |
echo "Installing new REST SERVICES" | |
sudo cp -rp ${HOME_PATH}rest-services ${ORIGIN_PATH} | |
echo "" | |
echo "Entering REDIRECTION ${ORIGIN_PATH}redirection" | |
cd ${ORIGIN_PATH}redirection | |
echo "Caching configurations" | |
php artisan view:clear && php artisan config:cache && php artisan route:cache && php artisan cache:clear | |
echo "Restarting queues" | |
php artisan queue:restart | |
echo "" | |
echo "Entering REST SERVICES ${ORIGIN_PATH}rest-services" | |
cd ${ORIGIN_PATH}rest-services | |
echo "Caching configurations" | |
php artisan view:clear && php artisan config:cache && php artisan route:cache && php artisan cache:clear | |
echo "Restarting queues" | |
php artisan queue:restart | |
cd ${HOME_PATH} | |
echo -e "\nInstallation finished" | |
elif [[ ${ACTION} == "rollback" ]] | |
then | |
# CODE TO ROLLBACK | |
if [ -d ${BACKUP_PATH}redirection ] || [ -d ${BACKUP_PATH}rest-services ] | |
then | |
echo "Moving blamed projects" | |
echo "Moving REDIRECTION to ${HOME_PATH}bad_redirection" | |
sudo mv ${ORIGIN_PATH}redirection ${HOME_PATH}bad_redirection | |
echo "Moving REST SERVICES to ${HOME_PATH}bad_rest-services" | |
sudo mv ${ORIGIN_PATH}rest-services ${HOME_PATH}bad_rest-services | |
echo -e "\nBacking UP" | |
echo "REDIRECTION" | |
sudo cp -rp ${BACKUP_PATH}redirection ${ORIGIN_PATH}redirection | |
echo "REST SERVICES" | |
sudo cp -rp ${BACKUP_PATH}rest-services ${ORIGIN_PATH}rest-services | |
else | |
echo -e "\n-- THERE IS NO BACKED UP PROJECTS --\n" | |
exit 1 | |
fi | |
echo -e "\nEmergency backup finished" | |
else | |
echo "You can just prepare, install or rollback" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment