From bb052ef921fb211b2667554bcd6b681e3654f3a8 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Mon, 9 Sep 2019 00:27:33 +0200 Subject: [PATCH] [fix] Upgrade script ready for v0.1.0-beta.9 --- scripts/remove | 1 + scripts/upgrade | 291 ++++++++++++++++++------------------------------ 2 files changed, 107 insertions(+), 185 deletions(-) diff --git a/scripts/remove b/scripts/remove index 8a1c2de..33ae0a0 100644 --- a/scripts/remove +++ b/scripts/remove @@ -83,6 +83,7 @@ ynh_remove_logrotate # Remove a temp directory securely ynh_secure_remove --file="/tmp/$app/" +ynh_secure_remove --file="/tmp/${app}backup" # Remove the log files ynh_secure_remove --file="/var/log/$app/" diff --git a/scripts/upgrade b/scripts/upgrade index 745bddf..3b874a8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,11 @@ #================================================= source _common.sh +source ynh_add_extra_apt_repos__3 +source ynh_install_php__3 +source ynh_exec_as +source ynh_composer__2 +source ynh_send_readme_to_admin__2 source /usr/share/yunohost/helpers #================================================= @@ -27,6 +32,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) old_project_version=$(ynh_app_setting_get --app=$app --key=project_version) old_core_version=$(ynh_app_setting_get --app=$app --key=core_version) old_ssowat_version=$(ynh_app_setting_get --app=$app --key=ssowat_version) +[ -z "$old_ssowat_version" ] && old_ssowat_version="0.6" bazaar_extension=$(ynh_app_setting_get --app=$app --key=bazaar_extension) #================================================= @@ -100,6 +106,13 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 +# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 ) +if [ $path_url = "/" ]; then + ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf" +else + ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf" +fi + # Create a dedicated nginx config ynh_add_nginx_config @@ -108,14 +121,7 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 -# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 ) -if [ $path_url = "/" ]; then - ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf" -else - ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf" -fi - -ynh_install_app_dependencies $pkg_dependencies +ynh_install_php --phpversion=7.3 --package="$pkg_dependencies" #================================================= # CREATE DEDICATED USER @@ -131,7 +137,7 @@ ynh_system_user_create --username=$app ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1 # Create a dedicated php-fpm config -ynh_add_fpm_config +ynh_add_fpm_config $php_version #================================================= # SPECIFIC UPGRADE @@ -150,41 +156,101 @@ fi # Downward compatibility: remove the v before version number if [[ $old_project_version == "v*" ]]; then $old_project_version = ${old_project_version:1}; fi # Check if upgrade of Flarum core is needed -if [[ $(dpkg --compare-versions $old_project_version lt $project_version && echo true) ]]; then - # Upgrade Flarum - ynh_composer_exec $app $php_version $final_path "require -n flarum/core:$project_version" - # Database password has to be input on admin page after upgrade to 0.1.0-beta.7.2 - if [[ $project_version == "0.1.0-beta.7.2" ]]; then - curl "https://$domain$path_url/admin" -H "Accept: */*" --compressed -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" --data "databasePassword=$db_pwd" -k - fi - pushd $final_path - exec_as $app php flarum cache:clear - popd - ynh_print_info "Flarum has been updated to version $project_version." - upgraded_flarum=true -else - ynh_print_info "Flarum does not need updating." - upgraded_flarum=false + +# Database password has to be input on admin page after upgrade to 0.1.0-beta.7.2 +if [[ $project_version == "0.1.0-beta.7.2" ]]; then + curl "https://$domain$path_url/admin" -H "Accept: */*" --compressed -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" --data "databasePassword=$db_pwd" -k +fi +#================================================= +# UPGRADING TO 0.1.0-beta.8 and above +#================================================= +if [[ $(dpkg --compare-versions $old_project_version lt "0.1.0-beta.8" && echo true) ]]; then + + # Backing up the app directory + tmpbak="/tmp/${app}backup" + mkdir -p $tmpbak + cp -R $final_path/* $tmpbak + + # Deleting current app directory + ynh_secure_remove --file="$final_path" + + # Create working directory + sudo mkdir -p "$final_path/.composer" + sudo chown -R $app:www-data $final_path + sudo chmod -R 0775 $final_path + + #================================================= + # COMPOSER INSTALLATION + #================================================= + + ynh_script_progression --message="Installing Composer..." --time --weight=1 + ynh_install_composer $php_version $final_path + + #================================================= + # FLARUM INSTALLATION + #================================================= + + # Prepare Flarum temp directory + tmp=/tmp/$app + sudo mkdir -p $tmp + sudo chown -R $app:www-data $tmp + sudo chmod -R 0775 $tmp + + # Install Flarum + ynh_script_progression --message="Composer is installing Flarum and its dependencies (may take a while)..." --time --weight=3 + + # First, create the project with core and all basic extensions + ynh_composer_exec $app $php_version $final_path "create-project flarum/flarum=$project_version $tmp --stability=beta --ansi -d $tmp" + # Let's fix the core version by explicitely requiring it + ynh_composer_exec $app $php_version $final_path "require flarum/core:$core_version -n --ansi -d $tmp" + + # Copy Flarum to working directory + sudo cp -Rf $tmp/* $final_path + # Copy config.php and assets from old app versions + sudo cp -Rf $tmpbak/config.php $final_path + sudo cp -Rf $tmpbak/assets $final_path/public + # Clean temp directory + ynh_secure_remove $tmp + ynh_secure_remove $tmpbak + + # Set right permissions for the post-installation + chown -R $app: $final_path + chown -R $app:www-data $final_path/storage + sudo chmod -R 0775 $final_path fi -# Check if upgrade of SSOwat extension is needed -if [[ $(dpkg --compare-versions $old_ssowat_version lt $ssowat_version && echo true) || -z $old_ssowat_version ]]; then - # Install and activate the SSOwat auth extension - install_and_activate_extension $app $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat" - # Configure SSOwat auth extension - ssowatdomain=$(