#!/bin/bash # Exit on command errors and treat unset variables as an error set -eu # Retrieve app id app=$YNH_APP_INSTANCE_NAME # Load common variables and helpers . ./_common.sh # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) path=${path%/} # Set app specific variables dbname=$app dbuser=$app # Check destination directory DESTDIR="/var/www/$app" [[ ! -d $DESTDIR ]] && ynh_die \ "The destination directory '$DESTDIR' does not exist.\ The app is not correctly installed, you should remove it first." # Create tmp directory and fetch new app inside TMPDIR=$(ynh_mkdir_tmp) extract_baikal "$TMPDIR" # Get Specific folder from current installation # FIXME: config.php and config.system.php are not updated with possible # new or changed configurations rm -rf "${TMPDIR}/Specific/*" sudo cp -r "${DESTDIR}/Specific/"{config.php,config.system.php} "$TMPDIR/Specific" sudo chown -hR "${USER}" "${TMPDIR}/Specific" # Run Baikal upgrade from tmp directory cp -r ../sources/bin "$TMPDIR" php "${TMPDIR}/bin/upgrade.sh" \ || echo "The Baïkal upgrade failed, you should try to go to " \ "https://${domain}${path}/admin/install" # Install new app and set permissions if ! id -u $app > /dev/null 2>&1 ; then sudo useradd -c "$app system account" \ -d /var/www/$app --system --user-group $app --shell /usr/sbin/nologin \ || ynh_die "Unable to create $app system account" fi sudo rm -rf "$DESTDIR" sudo mv "$TMPDIR" "$DESTDIR" sudo chown -hR root: "$DESTDIR" sudo chown $app:root "$DESTDIR/Specific/"{config.php,config.system.php} sudo chmod 640 "$DESTDIR/Specific/"{config.php,config.system.php} # Cleanup old baikal-admin sessions # since we may have changed owner of the session file sudo grep -lr "CSRF_TOKEN|s:" /var/lib/php5/sessions | xargs sudo rm # Copy and set nginx configuration nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" sed -i "s@{PATH}@${path}@g" ../conf/nginx.conf sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf "$nginx_conf" # Copy and set php-fpm configuration phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf sed -i "s@{DESTDIR}@${DESTDIR}/@g" ../conf/php-fpm.conf sed -i "s@{USER}@${app}@g" ../conf/php-fpm.conf sed -i "s@{GROUP}@${app}@g" ../conf/php-fpm.conf sudo cp ../conf/php-fpm.conf "$phpfpm_conf" # Set SSOwat rules ynh_app_setting_set "$app" skipped_uris "/" ynh_app_setting_set "$app" protected_uris "/admin/" # Reload services sudo service php5-fpm restart || true sudo service nginx reload || true