#!/bin/bash set -eo pipefail gpg_private_key=/var/www/passbolt/config/gpg/serverkey.private.asc gpg_public_key=/var/www/passbolt/config/gpg/serverkey.asc core_config='/var/www/passbolt/app/Config/core.php' db_config='/var/www/passbolt/app/Config/database.php' app_config='/var/www/passbolt/app/Config/app.php' email_config='/var/www/passbolt/app/Config/email.php' ssl_key='/etc/ssl/certs/certificate.key' ssl_cert='/etc/ssl/certs/certificate.crt' gpg_gen_key() { gpg --batch --gen-key < "$gpg_private_key" gpg --armor --export "$KEY_EMAIL" > "$gpg_public_key" gpg_auto_fingerprint=$(gpg --fingerprint "$KEY_EMAIL" | grep fingerprint | awk '{for(i=4;i<=NF;++i)printf \$i}') } gpg_import_key() { local key_id="" key_id=$(su -m -c "gpg --with-colons $gpg_private_key | grep sec |cut -f5 -d:" -ls /bin/bash nginx) su -m -c "gpg --batch --import $gpg_public_key" -ls /bin/bash nginx su -m -c "gpg -K $key_id" -ls /bin/bash nginx || su -m -c "gpg --batch --import $gpg_private_key" -ls /bin/bash nginx } gen_ssl_cert() { openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 \ -subj "/C=FR/ST=Denial/L=Springfield/O=Dis/CN=www.passbolt.local" \ -keyout $ssl_key -out $ssl_cert } install() { tables=$(mysql -u "$DATABASE_USER" -h "$DB_HOST" -P "$DB_HOST" -p -BN -e "SHOW TABLES FROM $DB_NAME" -p"$DB_PASS" |wc -l) if [ "$tables" -eq 0 ]; then su -c "/var/www/passbolt/app/Console/cake install --send-anonymous-statistics true --no-admin" -ls /bin/bash nginx else echo "Enjoy! ☮" fi } email_cron_job() { local root_crontab='/etc/crontabs/root' local cron_task_dir='/etc/periodic/1min' local cron_task='/etc/periodic/1min/email_queue_processing' local process_email="/var/www/passbolt/app/Console/cake EmailQueue.sender --quiet" mkdir -p $cron_task_dir echo "* * * * * run-parts $cron_task_dir" >> $root_crontab echo "#!/bin/sh" > $cron_task chmod +x $cron_task echo "su -c \"$process_email\" -ls /bin/bash nginx" >> $cron_task crond -f -c /etc/crontabs } if [ ! -f $gpg_private_key ] && [ ! -L $gpg_private_key ] || \ [ ! -f $gpg_public_key ] && [ ! -L $gpg_public_key ]; then echo 'not yet implemented' su -c "gpg --list-keys" -ls /bin/bash nginx gpg_gen_key gpg_import_key else echo 'not yet implemented' #gpg_import_key fi if [ ! -f $core_config ] && [ ! -L $core_config ]; then echo 'not yet implemented' #core_setup fi if [ ! -f $db_config ] && [ ! -L $db_config ]; then echo 'not yet implemented' #db_setup fi if [ ! -f $app_config ] && [ ! -L $app_config ]; then echo 'not yet implemented' #app_setup fi if [ ! -f $email_config ] && [ ! -L $email_config ]; then echo 'not yet implemented' #email_setup fi if [ ! -f $ssl_key ] && [ ! -L $ssl_key ] && \ [ ! -f $ssl_cert ] && [ ! -L $ssl_cert ]; then gen_ssl_cert fi php_fpm_setup # not yet implemented #install php-fpm7 nginx -g "pid /tmp/nginx.pid; daemon off;" # not yet implemented #email_cron_job