2017-03-17 11:38:37 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
bypass=0
|
|
|
|
forceClearCache=0
|
|
|
|
while getopts "hbc" option
|
|
|
|
do
|
|
|
|
case $option in
|
|
|
|
h)
|
|
|
|
echo -e "Update or install all Monarc modules, frontend views and migrate database."
|
|
|
|
echo -e "\t-b\tbypass migrate database"
|
|
|
|
echo -e "\t-c\tforce clear cache"
|
|
|
|
echo -e "\t-h\tdisplay this message"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
b)
|
|
|
|
bypass=1
|
|
|
|
echo "Migrate database don't execute !!!"
|
|
|
|
;;
|
|
|
|
c)
|
|
|
|
forceClearCache=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2016-04-27 16:59:05 +02:00
|
|
|
|
|
|
|
pull_if_exists() {
|
|
|
|
if [ -d $1 ]; then
|
|
|
|
pushd $1
|
|
|
|
git pull
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-03-17 11:45:46 +01:00
|
|
|
migrate_module() {
|
|
|
|
if [[ -d $2 ]]; then
|
|
|
|
$1 ./vendor/robmorgan/phinx/bin/phinx migrate -c ./$2/migrations/phinx.php
|
|
|
|
if [[ -d "${2}/hooks" && -f "${2}/.git/hooks/pre-commit.sh" ]]; then
|
|
|
|
cd $2/.git/hooks
|
|
|
|
ln -s ../../hooks/pre-commit.sh pre-commit 2>/dev/null
|
|
|
|
chmod u+x pre-commit
|
|
|
|
cd $2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:20:18 +01:00
|
|
|
if [[ ! -f "config/autoload/local.php" && $bypass -eq 0 ]]; then
|
2017-03-10 14:57:56 +01:00
|
|
|
echo "Configure Monarc (config/autoload/local.php)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-03-10 14:28:47 +01:00
|
|
|
phpcommand=`command -v php`
|
|
|
|
if [[ -z "$phpcommand" ]]; then
|
|
|
|
echo "PHP must be installed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-03-10 11:57:24 +01:00
|
|
|
gitcommand=`command -v git`
|
|
|
|
if [[ -z "$gitcommand" ]]; then
|
|
|
|
echo "Git must be installed"
|
2017-03-10 14:28:47 +01:00
|
|
|
exit 1
|
2017-03-10 11:57:24 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
$gitcommand pull
|
2016-04-27 16:59:05 +02:00
|
|
|
|
2019-06-11 10:47:32 +02:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "A problem occurred while retrieving remote files from repository."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-03-10 11:57:24 +01:00
|
|
|
composercommand=`command -v composer`
|
|
|
|
if [[ -z "$composercommand" ]]; then
|
|
|
|
if [[ ! -f "composer.phar" ]]; then
|
|
|
|
# https://getcomposer.org/download/
|
2017-03-10 14:28:47 +01:00
|
|
|
# https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
|
|
|
|
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
|
|
|
|
$phpcommand -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
|
|
|
ACTUAL_SIGNATURE=$($phpcommand -r "echo hash_file('SHA384', 'composer-setup.php');")
|
|
|
|
if [[ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]]; then
|
2017-03-10 14:40:13 +01:00
|
|
|
echo "Error download composer (different hash)"
|
2017-03-10 14:28:47 +01:00
|
|
|
rm composer-setup.php
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
rm composer-setup.php
|
2017-03-10 14:40:13 +01:00
|
|
|
$phpcommand composer-setup.php --quiet
|
2017-03-10 11:57:24 +01:00
|
|
|
fi
|
2017-03-10 14:28:47 +01:00
|
|
|
$phpcommand composer.phar update -o
|
2017-03-10 11:57:24 +01:00
|
|
|
else
|
|
|
|
$composercommand update -o
|
|
|
|
fi
|
2016-04-27 16:59:05 +02:00
|
|
|
|
2016-06-02 12:16:03 +02:00
|
|
|
|
2017-03-01 09:14:00 +01:00
|
|
|
currentPath=`pwd`
|
|
|
|
pathCore="module/MonarcCore"
|
|
|
|
if [ -d $pathCore ]; then
|
|
|
|
pull_if_exists $pathCore
|
|
|
|
else
|
|
|
|
pathCore="vendor/monarc/core"
|
|
|
|
fi
|
|
|
|
pathBO="module/MonarcBO"
|
|
|
|
if [ -d $pathBO ]; then
|
|
|
|
pull_if_exists $pathBO
|
|
|
|
else
|
|
|
|
pathBO="vendor/monarc/backoffice"
|
|
|
|
fi
|
|
|
|
pathFO="module/MonarcFO"
|
|
|
|
if [ -d $pathFO ]; then
|
|
|
|
pull_if_exists $pathFO
|
|
|
|
else
|
|
|
|
pathFO="vendor/monarc/frontoffice"
|
|
|
|
fi
|
|
|
|
|
2017-03-01 10:26:21 +01:00
|
|
|
if [[ -d node_modules && -d node_modules/ng_anr ]]; then
|
|
|
|
if [[ -d node_modules/ng_anr/.git ]]; then
|
|
|
|
pull_if_exists node_modules/ng_backoffice
|
|
|
|
pull_if_exists node_modules/ng_client
|
|
|
|
pull_if_exists node_modules/ng_anr
|
|
|
|
else
|
|
|
|
npm update
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
npm install
|
|
|
|
fi
|
|
|
|
|
2017-03-17 11:38:37 +01:00
|
|
|
if [[ $bypass -eq 0 ]]; then
|
2017-08-08 09:38:30 +02:00
|
|
|
if [ -e data/backup/credentialsmysql.cnf ]; then
|
2017-08-07 12:15:03 +02:00
|
|
|
backupdir=data/backup/$(date +"%Y%m%d_%H%M%S")
|
|
|
|
mkdir $backupdir
|
2017-08-08 09:38:30 +02:00
|
|
|
echo -e "\e[32mDumping database to $backupdir...\e[0m"
|
2017-08-11 11:05:29 +02:00
|
|
|
mysqldump --defaults-file=data/backup/credentialsmysql.cnf --databases monarc_common > $backupdir/dump-common.sql
|
|
|
|
mysqldump --defaults-file=data/backup/credentialsmysql.cnf --databases monarc_cli > $backupdir/dump-cli.sql
|
2017-08-07 12:13:56 +02:00
|
|
|
else
|
2017-08-08 09:38:30 +02:00
|
|
|
echo -e "\e[93mDatabase backup not configured. Skipping.\e[0m"
|
2017-08-07 12:13:56 +02:00
|
|
|
fi
|
|
|
|
|
2017-03-17 11:38:37 +01:00
|
|
|
migrate_module $phpcommand $pathCore
|
|
|
|
migrate_module $phpcommand $pathBO
|
|
|
|
migrate_module $phpcommand $pathFO
|
2016-08-25 15:42:05 +02:00
|
|
|
fi
|
2016-06-02 12:16:03 +02:00
|
|
|
|
2016-04-27 16:59:05 +02:00
|
|
|
if [ -d node_modules/ng_backoffice ]; then
|
|
|
|
cd node_modules/ng_backoffice
|
|
|
|
npm install
|
|
|
|
cd ../..
|
|
|
|
fi
|
|
|
|
|
2016-08-25 15:42:05 +02:00
|
|
|
if [ -d node_modules/ng_client ]; then
|
|
|
|
cd node_modules/ng_client
|
|
|
|
npm install
|
|
|
|
cd ../..
|
|
|
|
fi
|
|
|
|
|
2016-04-27 16:59:05 +02:00
|
|
|
./scripts/link_modules_resources.sh
|
2016-06-28 10:02:53 +02:00
|
|
|
./scripts/compile_translations.sh
|
2016-12-16 15:47:38 +01:00
|
|
|
|
2017-03-17 11:38:37 +01:00
|
|
|
if [[ $forceClearCache -eq 1 ]]; then
|
|
|
|
# Clear doctrine cache
|
|
|
|
# Move to MonarcCore Module.php
|
|
|
|
$phpcommand ./public/index.php orm:clear-cache:metadata
|
|
|
|
$phpcommand ./public/index.php orm:clear-cache:query
|
|
|
|
$phpcommand ./public/index.php orm:clear-cache:result
|
|
|
|
|
|
|
|
# Clear ZF2 cache
|
|
|
|
touch ./data/cache/upgrade && chmod 777 ./data/cache/upgrade
|
|
|
|
fi
|
2016-12-16 16:31:24 +01:00
|
|
|
|
2017-03-17 11:38:37 +01:00
|
|
|
if [[ $forceClearCache -eq 0 && $bypass -eq 0 ]]; then
|
|
|
|
# Clear ZF2 cache
|
|
|
|
touch ./data/cache/upgrade && chmod 777 ./data/cache/upgrade
|
|
|
|
fi
|