2017-08-18 09:54:27 +02:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
# Variables
|
|
|
|
GITHUB_AUTH_TOKEN=$1
|
|
|
|
|
|
|
|
TAG=''
|
|
|
|
|
|
|
|
PATH_TO_MONARC='/home/ubuntu/monarc'
|
|
|
|
ENVIRONMENT='PRODUCTION'
|
|
|
|
|
|
|
|
DBHOST='localhost'
|
|
|
|
DBNAME_COMMON='monarc_common'
|
|
|
|
DBNAME_CLI='monarc_cli'
|
2018-01-15 13:45:06 +01:00
|
|
|
DBUSER_ADMIN='root'
|
|
|
|
DBPASSWORD_ADMIN="$(openssl rand -hex 32)"
|
2017-08-18 09:54:27 +02:00
|
|
|
DBUSER_MONARC='sqlmonarcuser'
|
|
|
|
DBPASSWORD_MONARC="$(openssl rand -hex 32)"
|
|
|
|
|
|
|
|
upload_max_filesize=200M
|
|
|
|
post_max_size=50M
|
|
|
|
max_execution_time=100
|
|
|
|
max_input_time=223
|
|
|
|
memory_limit=512M
|
2018-08-23 08:45:12 +02:00
|
|
|
PHP_INI=/etc/php/7.2/apache2/php.ini
|
2019-08-23 08:41:26 +02:00
|
|
|
X_DEBUG_CFG=/etc/php/7.2/apache2/conf.d/20-xdebug.ini
|
|
|
|
MARIA_DB_CFG=/etc/mysql/mariadb.conf.d/50-server.cnf
|
2017-08-18 09:54:27 +02:00
|
|
|
|
2018-01-26 07:34:36 +01:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
export LANGUAGE=en_US.UTF-8
|
|
|
|
export LANG=en_US.UTF-8
|
|
|
|
export LC_ALL=en_US.UTF-8
|
|
|
|
locale-gen en_US.UTF-8
|
|
|
|
dpkg-reconfigure locales
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-26 08:30:39 +01:00
|
|
|
echo -e "\n--- Installing now… ---\n"
|
2017-08-18 09:54:27 +02:00
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Updating packages list… ---\n"
|
2018-01-25 22:57:11 +01:00
|
|
|
apt-get update
|
2017-08-18 09:54:27 +02:00
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Install base packages… ---\n"
|
2019-05-14 10:28:27 +02:00
|
|
|
apt-get -y install vim zip unzip git gettext curl gsfonts > /dev/null
|
2017-08-18 09:54:27 +02:00
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Install MariaDB specific packages and settings… ---\n"
|
2018-09-05 14:30:35 +02:00
|
|
|
# echo "mysql-server mysql-server/root_password password $DBPASSWORD_ADMIN" | debconf-set-selections
|
|
|
|
# echo "mysql-server mysql-server/root_password_again password $DBPASSWORD_ADMIN" | debconf-set-selections
|
2018-01-25 22:57:11 +01:00
|
|
|
apt-get -y install mariadb-server mariadb-client > /dev/null
|
2018-09-05 14:30:35 +02:00
|
|
|
# Secure the MariaDB installation (especially by setting a strong root password)
|
2018-01-26 08:08:57 +01:00
|
|
|
systemctl restart mariadb.service > /dev/null
|
2018-01-25 22:57:11 +01:00
|
|
|
sleep 5
|
2018-09-05 14:30:35 +02:00
|
|
|
apt-get -y install expect > /dev/null
|
|
|
|
## do we need to spawn mysql_secure_install with sudo in future?
|
|
|
|
expect -f - <<-EOF
|
|
|
|
set timeout 10
|
|
|
|
spawn mysql_secure_installation
|
|
|
|
expect "Enter current password for root (enter for none):"
|
|
|
|
send -- "\r"
|
|
|
|
expect "Set root password?"
|
|
|
|
send -- "y\r"
|
|
|
|
expect "New password:"
|
|
|
|
send -- "${DBPASSWORD_ADMIN}\r"
|
|
|
|
expect "Re-enter new password:"
|
|
|
|
send -- "${DBPASSWORD_ADMIN}\r"
|
|
|
|
expect "Remove anonymous users?"
|
|
|
|
send -- "y\r"
|
|
|
|
expect "Disallow root login remotely?"
|
|
|
|
send -- "y\r"
|
|
|
|
expect "Remove test database and access to it?"
|
|
|
|
send -- "y\r"
|
|
|
|
expect "Reload privilege tables now?"
|
|
|
|
send -- "y\r"
|
|
|
|
expect eof
|
|
|
|
EOF
|
|
|
|
sudo apt-get purge -y expect > /dev/null 2>&1
|
2017-08-18 09:54:27 +02:00
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
echo -e "\n--- Configuring… ---\n"
|
2019-08-23 08:41:26 +02:00
|
|
|
sed -i "s/skip-external-locking/#skip-external-locking/g" $MARIA_DB_CFG
|
|
|
|
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" $MARIA_DB_CFG
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
echo -e "\n--- Setting up our MariaDB user for MONARC… ---\n"
|
|
|
|
mysql -u root -p$DBPASSWORD_ADMIN -e "CREATE USER '$DBUSER_MONARC'@'%' IDENTIFIED BY '$DBPASSWORD_MONARC';"
|
|
|
|
mysql -u root -p$DBPASSWORD_ADMIN -e "GRANT ALL PRIVILEGES ON * . * TO '$DBUSER_MONARC'@'%';"
|
|
|
|
mysql -u root -p$DBPASSWORD_ADMIN -e "FLUSH PRIVILEGES;"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Installing PHP-specific packages… ---\n"
|
2019-08-23 08:41:26 +02:00
|
|
|
apt-get -y install php apache2 libapache2-mod-php php-curl php-gd php-mysql php-pear php-apcu php-xml php-mbstring php-intl php-imagick php-zip php-xdebug > /dev/null
|
2017-08-18 09:54:27 +02:00
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Configuring PHP… ---\n"
|
2017-08-18 09:54:27 +02:00
|
|
|
for key in upload_max_filesize post_max_size max_execution_time max_input_time memory_limit
|
|
|
|
do
|
|
|
|
sed -i "s/^\($key\).*/\1 = $(eval echo \${$key})/" $PHP_INI
|
|
|
|
done
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
echo -e "\n--- Configuring Xdebug for development ---\n"
|
2019-08-23 08:41:26 +02:00
|
|
|
cat > $X_DEBUG_CFG <<EOF
|
|
|
|
xdebug.remote_enable=1
|
|
|
|
xdebug.remote_connect_back=1
|
|
|
|
xdebug.idekey=IDEKEY
|
|
|
|
EOF
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Enabling mod-rewrite and ssl… ---\n"
|
2017-08-18 09:54:27 +02:00
|
|
|
a2enmod rewrite > /dev/null 2>&1
|
|
|
|
a2enmod ssl > /dev/null 2>&1
|
2019-04-04 13:54:23 +02:00
|
|
|
a2enmod headers > /dev/null 2>&1
|
2017-08-18 09:54:27 +02:00
|
|
|
|
|
|
|
echo -e "\n--- Allowing Apache override to all ---\n"
|
|
|
|
sudo sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf
|
|
|
|
|
2019-08-23 09:10:09 +02:00
|
|
|
#echo -e "\n--- We want to see the PHP errors, turning them on ---\n"
|
2019-08-23 11:49:16 +02:00
|
|
|
#sed -i "s/.*error_reporting.*/error_reporting = E_ALL/g" $PHP_INI
|
|
|
|
#sed -i "s/.*display_errors.*/display_errors = On/g" $PHP_INI
|
|
|
|
|
|
|
|
|
2017-08-18 09:54:27 +02:00
|
|
|
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Installing composer… ---\n"
|
2017-08-18 09:54:27 +02:00
|
|
|
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "\nERROR: unable to install composer\n"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
composer self-update
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Installing MONARC… ---\n"
|
2017-08-18 09:54:27 +02:00
|
|
|
cd $PATH_TO_MONARC
|
|
|
|
git config core.fileMode false
|
|
|
|
if [ "$TAG" != '' ]; then
|
|
|
|
# Checkout the latest tag
|
|
|
|
#latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
|
|
|
|
git checkout $TAG
|
|
|
|
fi
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Retrieving MONARC libraries… ---\n"
|
2017-08-18 09:54:27 +02:00
|
|
|
composer config -g github-oauth.github.com $GITHUB_AUTH_TOKEN
|
|
|
|
composer install -o
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
# Back-end
|
2017-08-18 09:54:27 +02:00
|
|
|
mkdir module
|
|
|
|
cd module
|
|
|
|
ln -s ./../vendor/monarc/core MonarcCore
|
|
|
|
ln -s ./../vendor/monarc/frontoffice MonarcFO
|
|
|
|
cd $PATH_TO_MONARC
|
|
|
|
cd module/MonarcFO/
|
|
|
|
git config core.fileMode false
|
|
|
|
cd $PATH_TO_MONARC
|
|
|
|
cd module/MonarcCore/
|
|
|
|
git config core.fileMode false
|
|
|
|
cd $PATH_TO_MONARC
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
# Front-end
|
2017-08-18 09:54:27 +02:00
|
|
|
mkdir node_modules
|
|
|
|
cd node_modules
|
2019-08-23 08:41:26 +02:00
|
|
|
git clone --config core.fileMode=false https://github.com/monarc-project/ng-client.git ng_client > /dev/null 2>&1
|
2017-08-18 09:54:27 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "\nERROR: unable to clone the ng-client repository\n"
|
|
|
|
exit 1;
|
|
|
|
fi
|
2019-08-23 08:41:26 +02:00
|
|
|
git clone --config core.fileMode=false https://github.com/monarc-project/ng-anr.git ng_anr > /dev/null 2>&1
|
2017-08-18 09:54:27 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "\nERROR: unable to clone the ng-anr repository\n"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
chown -R www-data $PATH_TO_MONARC
|
|
|
|
chgrp -R www-data $PATH_TO_MONARC
|
|
|
|
chmod -R 700 $PATH_TO_MONARC
|
|
|
|
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
2017-08-18 09:54:27 +02:00
|
|
|
echo -e "\n--- Add a VirtualHost for MONARC ---\n"
|
|
|
|
cat > /etc/apache2/sites-enabled/000-default.conf <<EOF
|
|
|
|
<VirtualHost *:80>
|
|
|
|
ServerName localhost
|
|
|
|
DocumentRoot $PATH_TO_MONARC/public
|
|
|
|
|
|
|
|
<Directory $PATH_TO_MONARC/public>
|
|
|
|
DirectoryIndex index.php
|
|
|
|
AllowOverride All
|
|
|
|
Require all granted
|
|
|
|
</Directory>
|
|
|
|
|
2019-04-04 13:54:23 +02:00
|
|
|
<IfModule mod_headers.c>
|
|
|
|
Header always set X-Content-Type-Options nosniff
|
|
|
|
Header always set X-XSS-Protection "1; mode=block"
|
|
|
|
Header always set X-Robots-Tag none
|
|
|
|
Header always set X-Frame-Options SAMEORIGIN
|
|
|
|
</IfModule>
|
|
|
|
|
2017-08-18 09:54:27 +02:00
|
|
|
SetEnv APPLICATION_ENV $ENVIRONMENT
|
2017-12-06 16:01:45 +01:00
|
|
|
SetEnv APP_DIR $PATH_TO_MONARC
|
2017-08-18 09:54:27 +02:00
|
|
|
</VirtualHost>
|
|
|
|
EOF
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Restarting Apache… ---\n"
|
2018-01-26 08:08:57 +01:00
|
|
|
systemctl restart apache2.service > /dev/null
|
2017-08-18 09:54:27 +02:00
|
|
|
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
2017-08-18 09:54:27 +02:00
|
|
|
echo -e "\n--- Configuration of MONARC data base connection ---\n"
|
|
|
|
cat > config/autoload/local.php <<EOF
|
|
|
|
<?php
|
2017-12-15 15:19:00 +01:00
|
|
|
\$appdir = getenv('APP_DIR') ? getenv('APP_DIR') : '$PATH_TO_MONARC';
|
|
|
|
\$string = file_get_contents(\$appdir.'/package.json');
|
|
|
|
if(\$string === FALSE) {
|
|
|
|
\$string = file_get_contents('./package.json');
|
2017-12-06 16:01:45 +01:00
|
|
|
}
|
2017-12-15 15:19:00 +01:00
|
|
|
\$package_json = json_decode(\$string, true);
|
2017-12-06 16:01:45 +01:00
|
|
|
|
2017-08-18 09:54:27 +02:00
|
|
|
return array(
|
|
|
|
'doctrine' => array(
|
|
|
|
'connection' => array(
|
|
|
|
'orm_default' => array(
|
|
|
|
'params' => array(
|
|
|
|
'host' => '$DBHOST',
|
|
|
|
'user' => '$DBUSER_MONARC',
|
|
|
|
'password' => '$DBPASSWORD_MONARC',
|
|
|
|
'dbname' => '$DBNAME_COMMON',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'orm_cli' => array(
|
|
|
|
'params' => array(
|
|
|
|
'host' => '$DBHOST',
|
|
|
|
'user' => '$DBUSER_MONARC',
|
|
|
|
'password' => '$DBPASSWORD_MONARC',
|
|
|
|
'dbname' => '$DBNAME_CLI',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
2017-10-20 22:26:05 +02:00
|
|
|
/* Link with (ModuleCore)
|
2017-08-18 09:54:27 +02:00
|
|
|
config['languages'] = [
|
|
|
|
'fr' => array(
|
|
|
|
'index' => 1,
|
|
|
|
'label' => 'Français'
|
|
|
|
),
|
|
|
|
'en' => array(
|
|
|
|
'index' => 2,
|
|
|
|
'label' => 'English'
|
|
|
|
),
|
|
|
|
'de' => array(
|
|
|
|
'index' => 3,
|
|
|
|
'label' => 'Deutsch'
|
|
|
|
),
|
|
|
|
]
|
|
|
|
*/
|
2019-04-24 11:04:12 +02:00
|
|
|
'activeLanguages' => array('fr','en','de','nl',),
|
2017-10-20 22:26:05 +02:00
|
|
|
|
2017-12-15 15:19:00 +01:00
|
|
|
'appVersion' => \$package_json['version'],
|
|
|
|
|
2018-07-04 14:54:46 +02:00
|
|
|
'checkVersion' => false,
|
2018-07-17 23:36:11 +02:00
|
|
|
'appCheckingURL' => 'https://version.monarc.lu/check/MONARC',
|
2018-07-04 14:54:46 +02:00
|
|
|
|
2017-10-20 22:26:05 +02:00
|
|
|
'email' => [
|
|
|
|
'name' => 'MONARC',
|
|
|
|
'from' => 'info@monarc.lu',
|
|
|
|
],
|
2017-08-18 09:54:27 +02:00
|
|
|
|
2019-04-04 07:56:39 +02:00
|
|
|
'mospApiUrl' => 'https://objects.monarc.lu/api/v1/',
|
|
|
|
|
2017-08-18 09:54:27 +02:00
|
|
|
'monarc' => array(
|
2018-01-15 15:24:20 +01:00
|
|
|
'ttl' => 60, // timeout
|
2019-04-04 07:56:39 +02:00
|
|
|
'salt' => '', // private salt for password encryption
|
2017-08-18 09:54:27 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Creation of the data bases… ---\n"
|
2018-01-25 22:57:11 +01:00
|
|
|
mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC -e "CREATE DATABASE monarc_cli DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" > /dev/null
|
|
|
|
mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC -e "CREATE DATABASE monarc_common DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" > /dev/null
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Populating MONARC DB… ---\n"
|
2018-01-25 22:57:11 +01:00
|
|
|
mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC monarc_common < db-bootstrap/monarc_structure.sql > /dev/null
|
2018-01-26 07:25:49 +01:00
|
|
|
mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC monarc_common < db-bootstrap/monarc_data.sql > /dev/null
|
2017-08-18 09:54:27 +02:00
|
|
|
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Installation of Grunt… ---\n"
|
2018-10-02 10:14:48 +02:00
|
|
|
sudo apt-get -y install npm > /dev/null
|
2018-01-25 22:57:11 +01:00
|
|
|
npm install -g grunt-cli > /dev/null
|
2017-08-18 09:54:27 +02:00
|
|
|
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Update the project… ---\n"
|
2017-08-25 15:32:39 +02:00
|
|
|
/bin/bash ./scripts/update-all.sh > /dev/null
|
2017-08-18 09:54:27 +02:00
|
|
|
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
2017-08-18 09:54:27 +02:00
|
|
|
echo -e "\n--- Create initial user and client ---\n"
|
|
|
|
php ./vendor/robmorgan/phinx/bin/phinx seed:run -c ./module/MonarcFO/migrations/phinx.php
|
|
|
|
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
2018-01-26 07:25:49 +01:00
|
|
|
echo -e "\n--- Restarting Apache… ---\n"
|
2018-01-25 22:57:11 +01:00
|
|
|
systemctl restart apache2.service > /dev/null
|
2017-08-18 09:54:27 +02:00
|
|
|
|
|
|
|
|
2019-08-23 11:49:16 +02:00
|
|
|
|
|
|
|
|
2017-08-18 09:54:27 +02:00
|
|
|
echo -e "\n--- MONARC is ready! Point your Web browser to http://127.0.0.1:5001 ---\n"
|