From a526c5d4acd822549719d14bed5199962529c483 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 17 May 2019 04:23:58 +0200 Subject: [PATCH 1/2] Apply example_ynh --- scripts/change_url | 11 ++++++----- scripts/install | 27 +++++++++++---------------- scripts/remove | 12 ++++++------ scripts/restore | 21 +++++++++++---------- scripts/upgrade | 35 ++++++++++++++--------------------- 5 files changed, 48 insertions(+), 58 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index bb99a8a..32f2a28 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -31,6 +31,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Add settings here as needed by your application #db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#db_user=$db_name #db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) #================================================= @@ -89,10 +90,10 @@ ynh_print_info --message="Updating Drush alias..." cp -f "../conf/example.site.yml" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__APP__" "$app" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__PATH_URL__" "$path_url" "$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$final_path/drush/sites/$app.site.yml" #================================================= # GENERIC FINALISATION @@ -101,7 +102,7 @@ ynh_replace_string "__PATH_URL__" "$path_url" "$final_path/drush/sites/$app.site #================================================= ynh_print_info --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index fac5474..f71c1e0 100644 --- a/scripts/install +++ b/scripts/install @@ -16,10 +16,6 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { - read -p "key" - true -} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -35,7 +31,7 @@ language=$YNH_APP_ARG_LANGUAGE password=$YNH_APP_ARG_PASSWORD install_profil=$YNH_APP_ARG_INSTALL_PROFIL -admin_mail=$(ynh_user_get_info $admin 'mail') +admin_mail=$(ynh_user_get_info --username=$admin --key="mail") app=$YNH_APP_INSTANCE_NAME @@ -45,7 +41,7 @@ app=$YNH_APP_INSTANCE_NAME ynh_print_info --message="Validating installation parameters..." final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url @@ -77,7 +73,7 @@ ynh_install_php --phpversion="7.2" --package="$extra_pkg_dependencies" #================================================= ynh_print_info --message="Creating a MySQL database..." -db_name=$(ynh_sanitize_dbid $app) +db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name @@ -90,7 +86,6 @@ ynh_print_info --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" -#mkdir -p "$final_path" #================================================= # NGINX CONFIGURATION @@ -119,10 +114,10 @@ mkdir -p "$final_path/drush/sites/" cp -f "../conf/example.site.yml" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__APP__" "$app" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__PATH_URL__" "$path_url" "$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$final_path/drush/sites/$app.site.yml" #================================================= # INSTALL COMPOSER @@ -132,7 +127,7 @@ ynh_print_info --message="Installing Composer..." mkdir -p "$final_path/.composer" cp -f "../conf/composer.json" "$final_path/composer.json" -ynh_replace_string "__APP__" "$app" "$final_path/composer.json" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/composer.json" ynh_install_composer --phpversion="7.2" --workdir="$final_path" @@ -158,8 +153,8 @@ ynh_print_info --message="Setting the cron file" cp ../conf/cron /etc/cron.d/$app -ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app -ynh_replace_string "__APP__" "$app" /etc/cron.d/$app +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" -target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__APP__" --replace_string="$app" -target_file="/etc/cron.d/$app" #================================================= # PHP-FPM CONFIGURATION @@ -202,7 +197,7 @@ fi #================================================= ynh_print_info --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 00d5d58..e621e6d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -29,7 +29,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # REMOVE THE MYSQL DATABASE #================================================= -ynh_print_info --message="Removing the MySQL database" +ynh_print_info --message="Removing the MySQL database..." # Remove a database if it exists, along with the associated user ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name @@ -37,7 +37,7 @@ ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= -ynh_print_info --message="Removing php-fpm configuration" +ynh_print_info --message="Removing php-fpm configuration..." # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -45,7 +45,7 @@ ynh_remove_fpm_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_print_info --message="Removing dependencies" +ynh_print_info --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -54,7 +54,7 @@ ynh_remove_php #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_print_info --message="Removing app main directory" +ynh_print_info --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -62,7 +62,7 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_print_info --message="Removing nginx web server configuration" +ynh_print_info --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config @@ -81,7 +81,7 @@ ynh_secure_remove --file="/etc/cron.d/$app" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_print_info --message="Removing the dedicated system user" +ynh_print_info --message="Removing the dedicated system user..." # Delete a system user ynh_system_user_delete --username=$app diff --git a/scripts/restore b/scripts/restore index f7763d5..3492801 100644 --- a/scripts/restore +++ b/scripts/restore @@ -30,6 +30,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -71,12 +72,6 @@ ynh_system_user_create --username=$app --home_dir="$final_path" # Restore permissions on app files chown -R $app: $final_path -#================================================= -# RESTORE THE PHP-FPM CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/php/7.2/fpm/pool.d/$app.conf" - #================================================= # SPECIFIC RESTORATION #================================================= @@ -94,8 +89,14 @@ ynh_install_php --phpversion="7.2" --package="$extra_pkg_dependencies" ynh_print_info --message="Restoring the MySQL database..." db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd -ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + +#================================================= +# RESTORE THE PHP-FPM CONFIGURATION +#================================================= + +ynh_restore_file --origin_path="/etc/php/7.2/fpm/pool.d/$app.conf" #================================================= # RESTORE THE CRON FILE @@ -110,8 +111,8 @@ ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= ynh_print_info --message="Reloading nginx web server and php-fpm..." -systemctl reload php7.2-fpm -systemctl reload nginx +ynh_systemd_action --service_name=php7.2-fpm --action=reload +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index b5aa6e0..ec0d498 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,6 +27,12 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +##================================================= +# CHECK VERSION +#================================================= + +upgrade_type=$(ynh_check_app_version_changed) + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -42,13 +48,13 @@ elif [ "$is_public" = "No" ]; then fi # If db_name doesn't exist, create it -if [ -z $db_name ]; then +if [ -z "$db_name" ]; then db_name=$(ynh_sanitize_dbid --db_name=$app) ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi # If final_path doesn't exist, create it -if [ -z $final_path ]; then +if [ -z "$final_path" ]; then final_path=/var/www/$app ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi @@ -61,7 +67,7 @@ ynh_print_info --message="Backing up the app before upgrading (may take a while) # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - read -p "key"# restore it if the upgrade fails + # restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -69,14 +75,6 @@ ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -ynh_print_info --message="Upgrading source files..." - -# Download, check integrity, uncompress and patch the source from app.src -#ynh_setup_source --dest_dir="$final_path" - #================================================= # NGINX CONFIGURATION #================================================= @@ -159,8 +157,10 @@ ynh_print_info --message="Setting the cron file" cp -f ../conf/cron /etc/cron.d/$app -ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app -ynh_replace_string "__APP__" "$app" /etc/cron.d/$app +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" + +ynh_systemd_action --service_name=cron --action=restart #================================================= # GENERIC FINALIZATION @@ -188,14 +188,7 @@ fi #================================================= ynh_print_info --message="Reloading nginx web server..." -systemctl reload nginx - -#================================================= -# RESTART CRON -#================================================= -ynh_print_info --message="Restarting cron..." - -systemctl restart cron +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT From c9cc630e9070326f51b24592feed3582bc9969dc Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 17 May 2019 11:44:45 +0200 Subject: [PATCH 2/2] Update install --- scripts/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index f71c1e0..ca0f6d6 100644 --- a/scripts/install +++ b/scripts/install @@ -153,8 +153,8 @@ ynh_print_info --message="Setting the cron file" cp ../conf/cron /etc/cron.d/$app -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" -target_file="/etc/cron.d/$app" -ynh_replace_string --match_string="__APP__" --replace_string="$app" -target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" #================================================= # PHP-FPM CONFIGURATION