diff --git a/check_process b/check_process index fbd9f6d..0c55abb 100644 --- a/check_process +++ b/check_process @@ -1,13 +1,13 @@ ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - admin="john" (USER) - is_public=1 (PUBLIC|public=1|private=0) + domain="domain.tld" + path="/path" + admin="john" + is_public=1 language="fr" password="jztI4OHHr2RfhrqK5wgX" - wiki_name="MyYunoWiki" (WIKI_NAME) - port="666" (PORT) + wiki_name="MyYunoWiki" + port="666" ; Checks pkg_linter=1 setup_sub_dir=1 diff --git a/conf/app.src b/conf/app.src index 2fb283d..304a187 100644 --- a/conf/app.src +++ b/conf/app.src @@ -4,3 +4,4 @@ SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true SOURCE_FILENAME= +SOURCE_EXTRACT=true diff --git a/manifest.json b/manifest.json index 2dae114..e033036 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "A free and open source software wiki package written in PHP, originally for use on Wikipedia.", "fr": "Un wiki à base de logiciels libres Open source, développé à l’origine pour Wikipédia ." }, - "version": "1.35.1~ynh1", + "version": "1.35.1~ynh2", "url": "https://www.mediawiki.org", "license": "GPL-2.0-or-later", "maintainer": { @@ -27,38 +27,22 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain name for MediaWiki", - "fr": "Choisissez un nom de domaine pour MediaWiki" - }, "example": "example.com" }, { "name": "path", "type": "path", - "ask": { - "en": "Choose a path for MediaWiki", - "fr": "Choisissez un chemin pour MediaWiki" - }, "example": "/wiki", "default": "/wiki" }, { "name": "admin", "type": "user", - "ask": { - "en": "Choose an admin user", - "fr": "Choisissez l'administrateur" - }, "example": "johndoe" }, { "name": "is_public", "type": "boolean", - "ask": { - "en": "Is it a public wiki ?", - "fr": "Est-ce un wiki public ?" - }, "help": { "en": "Visibility of the wiki pages", "fr": "La visibilité des pages du wiki" @@ -78,10 +62,6 @@ { "name": "password", "type": "password", - "ask": { - "en": "Set the administrator password", - "fr": "Définissez le mot de passe administrateur" - }, "help": { "en": "The password for the wiki administrator. It needs to be solid or the installation process will fail.", "fr": "Le mot de passe de l'administrateur du wiki. Il doit être solide, sinon l'installation échouera." diff --git a/scripts/_common.sh b/scripts/_common.sh index ae48f39..8794b2c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,13 +1,22 @@ #!/bin/bash #================================================= -# CONSTANTS +# COMMON VARIABLES #================================================= -# shellcheck disable=SC2034 # Variable is used by other scripts -pkg_dependencies=( - diffutils - imagemagick - acl -) + +# dependencies used by the app +pkg_dependencies="diffutils imagemagick acl" YNH_PHP_VERSION="7.3" + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index b2b62a6..b93a5ca 100755 --- a/scripts/backup +++ b/scripts/backup @@ -24,21 +24,16 @@ ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -domain=$(ynh_app_setting_get --app="$app" --key=domain) -db_name=$(ynh_app_setting_get --app="$app" --key=db_name) -phpversion=$(ynh_app_setting_get --app="$app" --key=phpversion) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= ynh_print_info --message="Declaring files to be backed up..." -### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs -### to be backuped and not an actual copy of any file. The actual backup that -### creates and fill the archive with the files happens in the core after this -### script is called. Hence ynh_backups calls takes basically 0 seconds to run. - #================================================= # BACKUP THE APP MAIN DIR #================================================= @@ -62,9 +57,6 @@ ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= ynh_print_info --message="Backing up the MySQL database..." -### (However, things like MySQL dumps *do* take some time to run, though the -### copy of the generated dump to the archive still happens later) - ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= diff --git a/scripts/change_url b/scripts/change_url index c4b463e..2b56942 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -27,10 +27,10 @@ app=$YNH_APP_INSTANCE_NAME ynh_script_progression --message="Loading installation settings..." --weight=1 # Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 @@ -53,13 +53,13 @@ ynh_abort_if_errors change_domain=0 if [ "$old_domain" != "$new_domain" ] then - change_domain=1 + change_domain=1 fi change_path=0 if [ "$old_path" != "$new_path" ] then - change_path=1 + change_path=1 fi #================================================= @@ -75,26 +75,26 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf if [ $change_path -eq 1 ] then # Make a backup of the original NGINX config file if modified - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" + ynh_backup_if_checksum_is_different --file="$nginx_conf_path" # Set global variables for NGINX helper - # shellcheck disable=SC2034 # Variable is referenced by ynh_add_nginx_config - domain="$old_domain" - # shellcheck disable=SC2034 # Variable is referenced by ynh_add_nginx_config - path_url="$new_path" + domain="$old_domain" + path_url="$new_path" # Create a dedicated NGINX config - ynh_add_nginx_config + ynh_add_nginx_config fi # Change the domain for NGINX if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv "$nginx_conf_path" "/etc/nginx/conf.d/$new_domain.d/$app.conf" + ynh_delete_file_checksum --file="$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi +#================================================= +# SPECIFIC MODIFICATIONS #================================================= # SET NEW URL #================================================= diff --git a/scripts/install b/scripts/install index 4e6f18d..8ed81b4 100644 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script @@ -43,20 +42,20 @@ final_path=/var/www/$app 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" +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." --weight=1 -ynh_app_setting_set --app="$app" --key=domain --value="$domain" -ynh_app_setting_set --app="$app" --key=path --value="$path_url" -ynh_app_setting_set --app="$app" --key=admin --value="$admin" -ynh_app_setting_set --app="$app" --key=admin_password --value="$admin_password" -ynh_app_setting_set --app="$app" --key=is_public --value="$is_public" -ynh_app_setting_set --app="$app" --key=language --value="$language" -ynh_app_setting_set --app="$app" --key=wiki_name --value="$wiki_name" +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=admin --value=$admin +ynh_app_setting_set --app=$app --key=admin_password --value=$admin_password +ynh_app_setting_set --app=$app --key=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=language --value=$language +ynh_app_setting_set --app=$app --key=wiki_name --value=$wiki_name #================================================= # STANDARD MODIFICATIONS @@ -65,26 +64,32 @@ ynh_app_setting_set --app="$app" --key=wiki_name --value="$wiki_name" #================================================= ynh_script_progression --message="Installing dependencies..." --weight=15 -ynh_install_app_dependencies "${pkg_dependencies[@]}" +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=2 + +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # CREATE A MYSQL DATABASE #================================================= ynh_script_progression --message="Creating a MySQL database..." --weight=1 -db_name=$(ynh_sanitize_dbid --db_name="$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_app_setting_set --app="$app" --key=db_user --value="$db_user" -ynh_mysql_setup_db --db_user="$db_user" --db_name="$db_name" -test -n "${db_pwd:?}" # Check the variable is correctly set by ynh_mysql_setup_db +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=4 -ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" +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" ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authentication2" @@ -96,22 +101,18 @@ ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="pluggable_aut # ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_userinfo" # ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authorization" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." --weight=1 +ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=2 - -# Create a system user -ynh_system_user_create --username="$app" - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -119,7 +120,7 @@ ynh_script_progression --message="Configuring PHP-FPM..." --weight=1 # Create a dedicated PHP-FPM config ynh_add_fpm_config -phpversion=$(ynh_app_setting_get --app="$app" --key=phpversion) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC SETUP @@ -173,21 +174,24 @@ ynh_replace_string --target_file="$final_path/LocalSettings.php" --match_string= ynh_replace_string --target_file="$final_path/LocalSettings.php" --match_string="__LANGUAGE__" --replace_string="$language" secret=$(ynh_string_random 64) -ynh_app_setting_set "$app" secret "$secret" +ynh_app_setting_set $app secret "$secret" ynh_replace_string --target_file="$final_path/LocalSettings.php" --match_string="__SECRET__" --replace_string="$secret" "php$phpversion" "$final_path/maintenance/update.php" -chown -R "$app:$app" "$final_path" +chown -R $app:$app "$final_path" #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." --weight=1 +ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary -if [ "$is_public" -eq 1 ]; then - ynh_permission_update --permission "main" --add "visitors" +if [ $is_public -eq 1 ] +then + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi #================================================= diff --git a/scripts/remove b/scripts/remove index ca307f2..538519e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,11 +16,11 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app="$app" --key=domain) -port=$(ynh_app_setting_get --app="$app" --key=port) -db_name=$(ynh_app_setting_get --app="$app" --key=db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE @@ -30,7 +30,7 @@ final_path=$(ynh_app_setting_get --app="$app" --key=final_path) ynh_script_progression --message="Removing the MySQL database..." --weight=4 # Remove a database if it exists, along with the associated user -ynh_mysql_remove_db --db_user"=$db_user" --db_name="$db_name" +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE DEPENDENCIES @@ -76,7 +76,7 @@ ynh_remove_fpm_config ynh_script_progression --message="Removing the dedicated system user..." --weight=1 # Delete a system user -ynh_system_user_delete --username="$app" +ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index c7e7a1f..9834568 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -24,31 +24,40 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -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) +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 -phpversion=$(ynh_app_setting_get --app="$app" --key=phpversion) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -ynh_webpath_available --domain="$domain" --path_url="$path_url" \ - || ynh_die --message="Path not available: ${domain}${path_url}" -test ! -d "$final_path" \ - || ynh_die --message="There is already a directory: $final_path" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the NGINX configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --weight=2 + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -56,24 +65,14 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$final_path" -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=2 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username="$app" - -#================================================= -# RESTORE USER RIGHTS -#================================================= - -# Restore permissions on app files -chown -R "$app:$app" "$final_path" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the PHP-FPM configuration..." ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" @@ -85,25 +84,25 @@ ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" ynh_script_progression --message="Reinstalling dependencies..." --weight=10 # Define and install dependencies -ynh_install_app_dependencies "${pkg_dependencies[@]}" +ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE MYSQL DATABASE #================================================= ynh_script_progression --message="Restoring the MySQL database..." --weight=5 -db_pwd=$(ynh_app_setting_get --app="$app" --key=mysqlpwd) -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 +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +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 #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading nginx web server and php-fpm..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1 -ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload +ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 637afd0..e0ccd2e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -16,47 +16,27 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app="$app" --key=domain) -path_url=$(ynh_app_setting_get --app="$app" --key=path) -admin=$(ynh_app_setting_get --app="$app" --key=admin) -is_public=$(ynh_app_setting_get --app="$app" --key=is_public) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -language=$(ynh_app_setting_get --app="$app" --key=language) -wiki_name=$(ynh_app_setting_get --app="$app" --key=wiki_name) -db_name=$(ynh_app_setting_get --app="$app" --key=db_name) -db_pwd=$(ynh_app_setting_get --app="$app" --key=mysqlpwd) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +admin=$(ynh_app_setting_get --app=$app --key=admin) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +language=$(ynh_app_setting_get --app=$app --key=language) +wiki_name=$(ynh_app_setting_get --app=$app --key=wiki_name) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) # Note(decentral1se): avoid using this on upgrade for the versions # of the application that upgrade and have not stored this in their # settings (when it was not available to them). Later on, when we have # moved a few versions on, we can re-enable this -# wiki_name=$(ynh_app_setting_get --app="$app" --key=wiki_name) +# wiki_name=$(ynh_app_setting_get --app=$app --key=wiki_name) #================================================= -# ENSURE DOWNWARD COMPATIBILITY +# CHECK VERSION #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression --message="Checking version..." -# Fix is_public as a boolean value -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set --app="$app" --key=is_public --value=1 - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set --app="$app" --key=is_public --value=0 - is_public=0 -fi - -# If db_name doesn't exist, create it -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 - final_path="/var/www/$app" - ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" -fi +upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -66,8 +46,8 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup + # Restore it if the upgrade fails + ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -75,34 +55,37 @@ ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS #================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE +# ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Setting up source files..." --weight=4 +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -ynh_setup_source --dest_dir="$final_path" -ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authentication2" -ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_provider" -ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="pluggable_auth" +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set --app=$app --key=is_public --value=1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set --app=$app --key=is_public --value=0 + is_public=0 +fi -# Note(decentral1se): Disabled and unused for now ... -# ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_groups" -# ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_userinfo" -# ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authorization" +# If db_name doesn't exist, create it +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 -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 +# If final_path doesn't exist, create it +if [ -z "$final_path" ]; then + final_path="/var/www/$app" + ynh_app_setting_set --app=$app --key=final_path --value="$final_path" +fi -# Create a dedicated nginx config -ynh_add_nginx_config +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=3 - -ynh_install_app_dependencies "${pkg_dependencies[@]}" + ynh_app_setting_delete --app=$app --key=is_public +fi #================================================= # CREATE DEDICATED USER @@ -110,16 +93,56 @@ ynh_install_app_dependencies "${pkg_dependencies[@]}" ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username="$app" +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --weight=4 + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authentication2" + ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_provider" + ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="pluggable_auth" + + # Note(decentral1se): Disabled and unused for now ... + # ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_groups" + # ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_userinfo" + # ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authorization" + +fi + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --weight=3 + +ynh_install_app_dependencies $pkg_dependencies #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=1 +ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1 -# Create a dedicated php-fpm config +# Create a dedicated PHP-FPM config ynh_add_fpm_config -phpversion=$(ynh_app_setting_get --app="$app" --key=phpversion) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC UPGRADE @@ -127,17 +150,17 @@ phpversion=$(ynh_app_setting_get --app="$app" --key=phpversion) # REMOVE LEGACY LDAP USER #================================================= # Removed in dec. 2020 -ldap_user=$(ynh_app_setting_get --app="$app" --key=ldap_user) +ldap_user=$(ynh_app_setting_get --app=$app --key=ldap_user) if [[ -n "$ldap_user" ]]; then yunohost user delete "$ldap_user" - ynh_app_setting_delete --app="$app" --key=ldap_user - ynh_app_setting_delete --app="$app" --key=ldap_password + ynh_app_setting_delete --app=$app --key=ldap_user + ynh_app_setting_delete --app=$app --key=ldap_password fi #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= -ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" +ynh_backup_if_checksum_is_different --file="$final_path/LocalSettings.php" #================================================= # REPLACE CONFIGURATION SETTINGS @@ -167,11 +190,11 @@ ynh_replace_string --target_file="$final_path/LocalSettings.php" --match_string= ynh_replace_string --target_file="$final_path/LocalSettings.php" --match_string="__LANGUAGE__" --replace_string="$language" secret=$(ynh_string_random 64) -ynh_app_setting_set "$app" secret "$secret" +ynh_app_setting_set $app secret "$secret" ynh_replace_string --target_file="$final_path/LocalSettings.php" --match_string="__SECRET__" --replace_string="$secret" # Check for admin password being too short for the new mediawiki requirements -password_length=$(ynh_app_setting_get --app="$app" --key=admin_password | awk '{print length}') +password_length=$(ynh_app_setting_get --app=$app --key=admin_password | awk '{print length}') if (( password_length < 10 )); then ynh_print_warn -m "The current admin password is $password_length long. Mediawiki now requires a 10 chars minimum password." ynh_print_warn -m "We are adapting the minimum length, but that would be great to change the admin password." @@ -180,34 +203,15 @@ fi "php$phpversion" "$final_path/maintenance/update.php" -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - # Set permissions on app files -chown -R "$app:$app" "$final_path" +chown -R $app:$app "$final_path" #================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1 - -# Upgrade from the legacy permissions system -protected_uris=$(ynh_app_setting_get --app="$app" --key=protected_uris) -if [ -n "${protected_uris}" ]; then - ynh_app_setting_delete --app="$app" --key=protected_uris -fi - -# Make app public if necessary -if [ $is_public -eq 1 ]; then - # Allow public access on / - ynh_permission_update --permission "main" --add "visitors" -fi - +# GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload