#!/usr/bin/env bash
set -x
HOTFIX_BRANCH=$1
cd /var/www/magento2/
sudo chown -R php-fpm:php-fpm /var/www/magento2/generated /var/www/magento2/pub/static/
sudo chmod -R 755 /var/www/magento2/generated /var/www/magento2/pub/static/
sudo -uphp-fpm php -d opcache.enable=0 -d display_errors=1 -d set_time_limit=0 -d memory_limit=-1 bin/magento cache:flush
sudo -uphp-fpm git config core.fileMode false
sudo -uphp-fpm git config user.name "nbwebbuilder"
sudo -uphp-fpm git config user.email "ecommerce.operations@nobelbiocare.com"
sudo -uphp-fpm git fetch --all
#sudo -uphp-fpm git merge $HOTFIX_BRANCH --no-squash
sudo -uphp-fpm git checkout production
sudo -uphp-fpm git branch -d hotfix/eifu
sudo -uphp-fpm git checkout -b hotfix/eifu $HOTFIX_BRANCH
sudo -uphp-fpm php -d opcache.enable=0 -d display_errors=1 -d set_time_limit=0 -d memory_limit=-1 bin/magento setup:upgrade
sudo -uphp-fpm php -d opcache.enable=0 -d display_errors=1 -d set_time_limit=0 -d memory_limit=-1 bin/magento setup:di:compile
sudo yum install parallel -y && sudo -uphp-fpm parallel php -d opcache.enable=0 -d display_errors=1 -d set_time_limit=0 -d memory_limit=-1 /var/www/magento2//bin/magento setup:static-content:deploy ::: en_US en_AU en_BE en_CA en_DK en_SE en_FI en_GB en_HK en_HU en_IE en_IN en_NL en_NO en_NZ de_AT de_CH de_DE en_ZA es_ES es_MX fr_BE fr_CA fr_CH fr_FR it_CH it_IT ja_JP pt_PT ru_RU
sudo -uphp-fpm php -d opcache.enable=0 -d display_errors=1 -d set_time_limit=0 -d memory_limit=-1 bin/magento cache:flush
sudo systemctl stop php-fpm
sudo rm -rf /var/lib/php/fpm/opcache/*
sudo systemctl start php-fpm