From bd578c05c33f5e9758089e93786373ed0dfb5672 Mon Sep 17 00:00:00 2001 From: Gofannon Date: Fri, 28 Sep 2018 23:01:55 +0200 Subject: [PATCH 1/9] [enh] Add variable to handle authentication backend --- conf/local.protected.php | 4 ++-- scripts/install | 21 +++++++++++++++++---- scripts/upgrade | 18 +++++++++++++++--- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/conf/local.protected.php b/conf/local.protected.php index f1b27c4..782e82d 100644 --- a/conf/local.protected.php +++ b/conf/local.protected.php @@ -2,7 +2,7 @@ /** * This file is used for configuration settings which cannot be modified by Dokuwiki admin panel * See here for explanations : https://www.dokuwiki.org/config - * + * * Yunohost dedicated settings are stored here in order to be able to upgrade the Yunohost package safely latter for Yunohost packager ( Yeah \o/ ) * * You should not modify this file direclty as it will be overwritten by Yunohost package @@ -12,7 +12,7 @@ /* Authentication Settings */ $conf['useacl'] = 1; //Use Access Control Lists to restrict access? -$conf['authtype'] = 'authldap'; //which authentication backend should be used +$conf['authtype'] = '__YNH_AUTH_BACKEND__'; //which authentication backend should be used $conf['passcrypt'] = 'sha1'; //Used crypt method (smd5,md5,sha1,ssha,crypt,mysql,my411) $conf['superuser'] = '__YNH_ADMIN_USER__'; //The admin can be user or @group or comma separated list user1,@group1,user2 $conf['manager'] = '__YNH_ADMIN_USER__'; //The manager can be user or @group or comma separated list user1,@group1,user2 diff --git a/scripts/install b/scripts/install index 046c816..8297dcb 100755 --- a/scripts/install +++ b/scripts/install @@ -63,6 +63,17 @@ ynh_app_setting_set $app admin $admin ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app language $language +#================================================= +# STORE DEFAULT VALUES FOR "ACTION SCRIPTS" +#================================================= + +# Needed for "upgrade" to know which backend to set back after overwriting "local.protected.php" +# Can be changed by action script "internal_users" +auth_backend='authldap' # Default backend is LDAP with Yunohost, 'authldap' for DokuWiki +ynh_app_setting_set $app auth_backend $auth_backend +# Disable the 'is_internal_users' feature +ynh_app_setting_set $app is_internal_users 0 + #================================================= # STANDARD MODIFICATIONS #================================================= @@ -116,22 +127,24 @@ ynh_add_fpm_config # It will only be updated by Yunohost package or directly by adventurous users cp ../conf/local.protected.php $final_path/conf +# Set the authentification backend +ynh_replace_string "__YNH_AUTH_BACKEND__" "$auth_backend" "$final_path/conf/local.protected.php" # Set the "admin" user -ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" +ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" # This file might be modified by dokuwiki admin panel or by plugins # It will not be modified by Yunohost in order to keep user settings -cp ../conf/local.php $final_path/conf +cp ../conf/local.php $final_path/conf # Set the "language" -ynh_replace_string "__YNH_LANGUAGE__" "$language" "$final_path/conf/local.php" +ynh_replace_string "__YNH_LANGUAGE__" "$language" "$final_path/conf/local.php" # Restrict user rights by enforcing "read-only" mode for all users # See https://www.dokuwiki.org/acl#background_info # Default is "8" -cp ../conf/acl.auth.php $final_path/conf +cp ../conf/acl.auth.php $final_path/conf #================================================= # CREATE DEFAULT FILES diff --git a/scripts/upgrade b/scripts/upgrade index 75be9a7..f641101 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,6 +23,9 @@ is_public=$(ynh_app_setting_get $app is_public) #language=$(ynh_app_setting_get $app language) final_path=$(ynh_app_setting_get $app final_path) +auth_backend=$(ynh_app_setting_get $app auth_backend) +#is_internal_users=$(ynh_app_setting_get $app is_internal_users) + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -55,6 +58,11 @@ if [ -z "$language" ]; then ynh_app_setting_set $app language $language fi +# 'is_internal_users' default value, if not set +if [ -z "$is_internal_users" ]; then + ynh_app_setting_set $app is_internal_users 0 +fi + # Yunohost specific configuration, if not exists @@ -78,8 +86,10 @@ fi if [ ! -f "$final_path/conf/local.protected.php" ]; then cp ../conf/local.protected.php $final_path/conf - # Set the default "admin" - ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" + # Set the authentification backend + ynh_replace_string "__YNH_AUTH_BACKEND__" "$auth_backend" "$final_path/conf/local.protected.php" + # Set the "admin" user + ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" fi # Do not overwrite existing dokuwiki configuration as it could have user customization's and settings. @@ -238,8 +248,10 @@ ynh_backup_if_checksum_is_different "$final_path/conf/local.protected.php" # Always overwrite local file with the one from package. cp ../conf/local.protected.php $final_path/conf +# Set the authentification backend +ynh_replace_string "__YNH_AUTH_BACKEND__" "$auth_backend" "$final_path/conf/local.protected.php" # Set the "admin" user -ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" +ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum "$final_path/conf/local.protected.php" From fb981af6d5a6222e0ae7b72921154e3e9642e7d3 Mon Sep 17 00:00:00 2001 From: Gofannon Date: Fri, 28 Sep 2018 23:04:24 +0200 Subject: [PATCH 2/9] [enh] initial version of "actions scripts" --- actions.json | 40 ++++++++++ scripts/actions/internal_users | 133 +++++++++++++++++++++++++++++++++ scripts/actions/public_private | 59 +++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 actions.json create mode 100644 scripts/actions/internal_users create mode 100644 scripts/actions/public_private diff --git a/actions.json b/actions.json new file mode 100644 index 0000000..58afc94 --- /dev/null +++ b/actions.json @@ -0,0 +1,40 @@ +[{ + "id": "public_private", + "name": "Move to public or private", + "command": "/bin/bash scripts/actions/public_private", + "user": "root", + "accepted_return_codes": [0], + "description": { + "en": "Change the public access of the app." + }, + "arguments": [ + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public app ? (1/0) (1=yes; 0=no)" + }, + "default": false + } + ] +}, +{ + "id": "internal_users", + "name": "Allow DokuWiki internal users storage in addition to Yunohost", + "command": "/bin/bash scripts/actions/internal_users", + "user": "root", + "accepted_return_codes": [0], + "description": { + "en": "Enable DokuWiki internal users." + }, + "arguments": [ + { + "name": "is_internal_users", + "type": "boolean", + "ask": { + "en": "Want to enable DokuWiki users too ? (1/0) (1=yes; 0=no)" + }, + "default": false + } + ] +}] diff --git a/scripts/actions/internal_users b/scripts/actions/internal_users new file mode 100644 index 0000000..743c86b --- /dev/null +++ b/scripts/actions/internal_users @@ -0,0 +1,133 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +# Get authentication backend and set as lowercase +#auth_backend=${YNH_ACTION_IS_INTERNAL_USERS,,} +# Get "is_internal_users" and set as lowercase +is_internal_users=${YNH_ACTION_IS_INTERNAL_USERS,,} + +# Get the full name of the app, Example: strut__3 +app=$YNH_APP_INSTANCE_NAME + +admin=$(ynh_app_setting_get $app admin) +is_public=$(ynh_app_setting_get $app is_public) +final_path=$(ynh_app_setting_get $app final_path) + +auth_backend_old=$(ynh_app_setting_get $app auth_backend) +is_internal_users_old=$(ynh_app_setting_get $app is_internal_users) + +#================================================= +# CHECK IF ARGUMENTS AND REQUIREMENTS ARE CORRECT +#================================================= + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +if [ $is_internal_users -eq $is_internal_users_old ] +then + ynh_die "is_internal_users is already set as $is_internal_users." 0 +fi + +# Ensure that app is public +if [ $is_public -eq 0 ]; then + ynh_die "Wiki must be public if you want your people to be able to reach it. Run 'public_private' and come back here" 1 +fi + +# Plugin "authchained" needs to be installed for this script to run +if [ ! -d $final_path/lib/plugins/authchained ]; then + ynh_die "Plugin 'authchained' is not installed and must be installed beforehand." 1 +fi + +### automatic installation of "authchained" plugin +### FIXME plugin installed this way does not work. Had to reinstall from "admin panel" +# Install "authchained" plugin. Allows to use multiple users backend storage : LDAP + internal DokuWiki users +# See https://www.dokuwiki.org/plugin:authchained?s[]=chained + +#sudo wget -nv --quiet "https://github.com/splitbrain/dokuwiki-plugin-${name_plugin}/zipball/master" -O "${name_plugin}.zip" -o /dev/null || true +#plugin_archive=dokuwiki-plugin-authchained.zip +#wget -nv --quiet 'https://github.com/rztuc/dokuwiki-plugin-authchained/archive/master.zip' -O "$plugin_archive" -o /dev/null || true +# +## if "file is not zero size" +#if [ -s "$plugin_archive" ]; then +# # path "authchained" is hardcoded and a better way should be to use the "base" field from the plugin archive +# # See https://www.dokuwiki.org/devel:plugin_info +# mkdir $final_path/lib/plugins/authchained +# +# # Extract plugin files strayed to the local plugin directory +# # Assume that the plugin name will not change in the futur +# # +# # unzip options +# # -j junk paths (do not make directories) +# # -d extract files into exdir +# unzip -j -d $final_path/lib/plugins/authchained "$plugin_archive" +# +# # Set filesystem rights for new plugin +# chown -R $app:root $final_path/lib/plugins/authchained +#fi + +#================================================= +# SPECIFIC ACTION +#================================================= + +### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. +### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. +ynh_backup_if_checksum_is_different "$final_path/conf/local.protected.php" + +# Always overwrite local file with the one from package. +cp conf/local.protected.php $final_path/conf + +if [ $is_internal_users -eq 1 ]; +then + auth_backend="authchained" + + #authchained_configuration='$conf['p lugin']['authchained']['authtypes'] = 'authldap:authplain';' + #grep -q -F '$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';' "$final_path/conf/local.protected.php" || echo 'include "/configs/projectname.conf"' >> foo.bar + + # Search if configuration in "config file" is present for plugin to work + #TODO could be added straight to 'local.protected.php' file ? + grep -q -F '$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';' "$final_path/conf/local.protected.php" + if [ $? -ne 0 ]; then + # If not found, add the setting to "local.protected.php" which can only be edited by Yunohost + # \$conf needs the "\" to espace the dollar and avoid echo to interprate it as a (void) variable + echo "\$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';" >> "$final_path/conf/local.protected.php" + fi + # source: https://stackoverflow.com/questions/3557037/appending-a-line-to-a-file-only-if-it-does-not-already-exist +else + auth_backend="authldap" +fi + +# Set the authentification backend +#ynh_replace_string "^$conf['authtype'].*" "$conf['authtype'] = '$auth_backend';" "$final_path/conf/local.protected.php" +ynh_replace_string "__YNH_AUTH_BACKEND__" "$auth_backend" "$final_path/conf/local.protected.php" +# Set the "admin" user +ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" + +# Recalculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/conf/local.protected.php" + + +# Regen ssowat configuration +yunohost app ssowatconf + +# Update the config of the app +ynh_app_setting_set $app auth_backend $auth_backend +ynh_app_setting_set $app is_internal_users $is_internal_users + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx diff --git a/scripts/actions/public_private b/scripts/actions/public_private new file mode 100644 index 0000000..0ce8a51 --- /dev/null +++ b/scripts/actions/public_private @@ -0,0 +1,59 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +# Get is_public and set as lowercase +is_public=${YNH_ACTION_IS_PUBLIC,,} + +# Get the full name of the app, Example: strut__3 +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +is_public_old=$(ynh_app_setting_get $app is_public) + +if [ $is_public -eq $is_public_old ] +then + ynh_die "is_public is already set as $is_public." 0 +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# MOVE TO PUBLIC OR PRIVATE +#================================================= + +if [ $is_public -eq 0 ]; +then + ynh_app_setting_delete $app unprotected_uris +else + ynh_app_setting_set $app unprotected_uris "/" +fi + +# Regen ssowat configuration +yunohost app ssowatconf + +# Update the config of the app +ynh_app_setting_set $app is_public $is_public + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx From 1f8f5455df25be1067da79df4e5d4885968552d5 Mon Sep 17 00:00:00 2001 From: Gofannon Date: Sun, 25 Nov 2018 13:12:22 +0100 Subject: [PATCH 3/9] Preload authchained config --- conf/local.protected.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/conf/local.protected.php b/conf/local.protected.php index 782e82d..04044c8 100644 --- a/conf/local.protected.php +++ b/conf/local.protected.php @@ -25,7 +25,11 @@ $conf['plugin']['authldap']['usertree'] = 'ou=users,dc=yunohost,dc=org'; $conf['plugin']['authldap']['userfilter'] = '(&(uid=%{user})(objectClass=posixAccount))'; # no groups #$conf['plugin']['authldap']['grouptree'] = 'ou=Group, dc=server, dc=tld'; -#$conf['plugin']['authldap']['groupfilter'] = '(&(objectClass=posixGroup)(|(gidNumber=%{gid})(memberUID=%{user})))'; +#$conf['plugin']['authldap']['groupfilter'] = '(&(objectClass=posixGroup)(|(gidNumber=%{gid})(memberUID=%{user})))'; + +// Authchained plugin preload configuration. Can be used by 'internal_users' action script +//$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain'; +// /* Advanced Settings */ $conf['updatecheck'] = 0; //automatically check for new releases? From 78c573822aec07ce37a31e7bacdf9ccac05676d9 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 11 May 2019 01:13:45 +0200 Subject: [PATCH 4/9] Normalization from example_ynh --- README.md | 7 +-- README_fr.md | 7 +-- check_process | 9 ---- manifest.json | 2 +- scripts/backup | 20 +++---- scripts/change_url | 27 ++++------ scripts/install | 55 ++++++++++--------- scripts/remove | 20 +++---- scripts/restore | 36 ++++++------- scripts/upgrade | 132 +++++++++++++++++++++++++-------------------- 10 files changed, 156 insertions(+), 159 deletions(-) diff --git a/README.md b/README.md index 328031e..fea004e 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,9 @@ DokuWiki is a simple to use and highly versatile Open Source wiki software that ### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/dokuwiki%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/dokuwiki/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/dokuwiki%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/dokuwiki/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/dokuwiki%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/dokuwiki/) +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/dokuwiki%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/dokuwiki/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/dokuwiki%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/dokuwiki/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/dokuwiki%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/dokuwiki/) ## Limitations @@ -58,6 +58,7 @@ DokuWiki is a simple to use and highly versatile Open Source wiki software that * Report a bug: https://github.com/YunoHost-Apps/dokuwiki_ynh/issues * App website: https://www.dokuwiki.org + * Upstream app repository: https://github.com/splitbrain/dokuwiki * YunoHost website: https://yunohost.org --- diff --git a/README_fr.md b/README_fr.md index a24d623..fe39537 100644 --- a/README_fr.md +++ b/README_fr.md @@ -38,9 +38,9 @@ DokuWiki est un logiciel wiki Open Source simple à utiliser et très polyvalent ### Architectures matérielles supportées -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/dokuwiki%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/dokuwiki/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/dokuwiki%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/dokuwiki/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/dokuwiki%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/dokuwiki/) +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/dokuwiki%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/dokuwiki/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/dokuwiki%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/dokuwiki/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/dokuwiki%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/dokuwiki/) ## Limitations @@ -58,6 +58,7 @@ DokuWiki est un logiciel wiki Open Source simple à utiliser et très polyvalent * Signaler un bug: https://github.com/YunoHost-Apps/dokuwiki_ynh/issues * Site de l'application:https://www.dokuwiki.org + * Dépôt de l'application principale: https://github.com/splitbrain/dokuwiki * Site web YunoHost: https://yunohost.org/ --- diff --git a/check_process b/check_process index 8e7a1e4..f6fdd01 100644 --- a/check_process +++ b/check_process @@ -21,16 +21,7 @@ port_already_use=0 change_url=1 ;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - Level 4=1 Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 ;;; Options Email= Notification=none diff --git a/manifest.json b/manifest.json index 18a16d3..8f68fac 100644 --- a/manifest.json +++ b/manifest.json @@ -22,7 +22,7 @@ "email": "opi@zeropi.net" }], "requirements": { - "yunohost": ">= 3.0" + "yunohost": ">= 3.5.0" }, "multi_instance": true, "services": [ diff --git a/scripts/backup b/scripts/backup index 4f1f855..af18011 100755 --- a/scripts/backup +++ b/scripts/backup @@ -19,38 +19,38 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= # STANDARD BACKUP STEPS #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_print_info "Backing up the main app directory..." +ynh_script_progression --message="Backing up the main app directory..." -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_print_info "Backing up nginx web server configuration..." +ynh_script_progression --message="Backing up nginx web server configuration..." -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_print_info "Backing up php-fpm configuration..." +ynh_script_progression --message="Backing up php-fpm configuration..." --weight=2 -ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last diff --git a/scripts/change_url b/scripts/change_url index e4eed90..14c221d 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,19 +24,10 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." # Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get $app final_path) - -#================================================= -# CHECK THE SYNTAX OF THE PATHS -#================================================= - -test -n "$old_path" || old_path="/" -test -n "$new_path" || new_path="/" -new_path=$(ynh_normalize_url_path $new_path) -old_path=$(ynh_normalize_url_path $old_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED @@ -59,7 +50,7 @@ fi #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_print_info "Updating nginx web server configuration..." +ynh_script_progression --message="Updating nginx web server configuration..." --weight=2 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -67,7 +58,7 @@ 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 "$nginx_conf_path" + ynh_backup_if_checksum_is_different --file="$nginx_conf_path" # Set global variables for nginx helper domain="$old_domain" path_url="$new_path" @@ -79,10 +70,10 @@ fi if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location - ynh_delete_file_checksum "$nginx_conf_path" + 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 "/etc/nginx/conf.d/$new_domain.d/$app.conf" + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= @@ -90,12 +81,12 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Change of url completed for $app" +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 6e509f6..2d7974f 100755 --- a/scripts/install +++ b/scripts/install @@ -31,43 +31,42 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_print_info "Validating installation parameters..." +ynh_script_progression --message="Validating installation parameters..." --weight=2 final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" - -# Normalize the url path syntax -path_url=$(ynh_normalize_url_path $path_url) +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_print_info "Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." --weight=2 -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app admin $admin -ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set $app language $language +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=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=language --value=$language #================================================= # STANDARD MODIFICATIONS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_print_info "Setting up source files..." +ynh_script_progression --message="Setting up source files..." --weight=2 -ynh_app_setting_set $app final_path $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 "$final_path" +ynh_setup_source --dest_dir="$final_path" #================================================= # NGINX CONFIGURATION #================================================= -ynh_print_info "Configuring nginx web server..." +ynh_script_progression --message="Configuring nginx web server..." --weight=2 + +### `ynh_add_nginx_config` will use the file conf/nginx.conf # Create a dedicated nginx config ynh_add_nginx_config @@ -75,15 +74,15 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info "Configuring system user..." +ynh_script_progression --message="Configuring system user..." --weight=2 # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_print_info "Configuring php-fpm..." +ynh_script_progression --message="Configuring php-fpm..." --weight=2 # Create a dedicated php-fpm config ynh_add_fpm_config @@ -93,7 +92,7 @@ ynh_add_fpm_config #================================================= # CUSTOMIZE DOKUWIKI #================================================= -ynh_print_info "Configuring dokuwiki..." +ynh_script_progression --message="Configuring dokuwiki..." --weight=2 # Loading order of configuration files # @@ -112,7 +111,7 @@ ynh_print_info "Configuring dokuwiki..." cp ../conf/local.protected.php $final_path/conf # Set the "admin" user -ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" +ynh_replace_string --match_string="__YNH_ADMIN_USER__" --replace_string="$admin" --target_file="$final_path/conf/local.protected.php" # This file might be modified by dokuwiki admin panel or by plugins @@ -120,7 +119,7 @@ ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.prot cp ../conf/local.php $final_path/conf # Set the "language" -ynh_replace_string "__YNH_LANGUAGE__" "$language" "$final_path/conf/local.php" +ynh_replace_string --match_string="__YNH_LANGUAGE__" --replace_string="$language" --target_file="$final_path/conf/local.php" # Restrict user rights by enforcing "read-only" mode for all users @@ -156,7 +155,7 @@ cp ../conf/plugins.local.php $final_path/conf/plugins.local.php.bak #================================================= # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/conf/local.protected.php" +ynh_store_file_checksum --file="$final_path/conf/local.protected.php" ### Files '$final_path/conf/local.php' and '$final_path/conf/acl.auth.php' can be modified by user, no need to store checksum as they cannot be overwritten safely by the upgrade script #================================================= @@ -205,24 +204,24 @@ find $final_path/lib -type d -print0 | xargs -0 chmod 0755 #================================================= # SETUP SSOWAT #================================================= -ynh_print_info "Configuring SSOwat..." +ynh_script_progression --message="Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Installation of $app completed" +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 5d7882d..e925e64 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,27 +12,27 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_print_info "Removing app main directory" +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_print_info "Removing nginx web server configuration" +ynh_script_progression --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config @@ -40,7 +40,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= -ynh_print_info "Removing php-fpm configuration" +ynh_script_progression --message="Removing php-fpm configuration..." --weight=2 # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -50,13 +50,13 @@ ynh_remove_fpm_config #================================================= # REMOVE DEDICATED USER #================================================= -ynh_print_info "Removing the dedicated system user" +ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Removal of $app completed" +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 347cfa0..0fdc450 100755 --- a/scripts/restore +++ b/scripts/restore @@ -19,23 +19,23 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading settings..." +ynh_script_progression --message="Loading settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) +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) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_print_info "Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." --weight=2 -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -43,22 +43,22 @@ test ! -d $final_path \ # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_print_info "Restoring the app main directory..." +ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file "$final_path" +ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_print_info "Recreating the dedicated system user..." +ynh_script_progression --message="Recreating the dedicated system user..." --weight=2 # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # RESTORE USER RIGHTS @@ -89,20 +89,20 @@ chown -R $app:root $final_path/lib/tpl # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_print_info "Reloading nginx web server and php-fpm..." +ynh_script_progression --message="Reloading nginx web server and php-fpm..." --weight=2 -systemctl reload php7.0-fpm -systemctl reload nginx +ynh_systemd_action --service_name=php7.0-fpm --action=reload +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 7a0fb2a..cc93890 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,47 +12,53 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) -is_public=$(ynh_app_setting_get $app is_public) -final_path=$(ynh_app_setting_get $app final_path) +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) + +#================================================= +# CHECK VERSION +#================================================= + +upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_print_info "Ensuring downward compatibility..." +ynh_script_progression --message="Ensuring downward compatibility..." # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 + ynh_app_setting_set --app=$app --key=is_public --value=1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 + ynh_app_setting_set --app=$app --key=is_public --value=0 is_public=0 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 final_path $final_path + ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi # TODO Not sure if still needed ?? # admin default value, if not set if [ -z "$admin" ]; then - admin=$(sudo yunohost user list | grep 'username' -m1 | awk '{print $2}') - sudo ynh_app_setting_set $app is_public -v "$is_public" + admin=$(yunohost user list | grep 'username' -m1 | awk '{print $2}') + ynh_app_setting_set --app=$app --key=is_public --value=$is_public fi # language default value, if not set if [ -z "$language" ]; then language='en' - ynh_app_setting_set $app language $language + ynh_app_setting_set --app=$app --key=language --value=$language fi @@ -86,7 +92,7 @@ if [ ! -f "$final_path/conf/local.php" ]; then cp ../conf/local.php $final_path/conf # Set the default "language" - ynh_replace_string "__YNH_LANGUAGE__" "$language" "$final_path/conf/local.php" + ynh_replace_string --match_string="__YNH_LANGUAGE__" --replace_string="$language" --target_file="$final_path/conf/local.php" fi # Do not overwrite existing ACL configuration file as it could have user customization's and settings. @@ -135,7 +141,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_print_info "Backing up the app before upgrading (may take a while)..." +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=9 # Backup the current version of the app ynh_backup_before_upgrade @@ -151,22 +157,26 @@ ynh_abort_if_errors #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) +path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= # STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_print_info "Upgrading source files..." -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --weight=2 + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" +fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_print_info "Upgrading nginx web server configuration..." +ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=2 # Create a dedicated nginx config ynh_add_nginx_config @@ -174,15 +184,15 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info "Making sure dedicated system user exists..." +ynh_script_progression --message="Making sure dedicated system user exists..." # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_print_info "Upgrading php-fpm configuration..." +ynh_script_progression --message="Upgrading php-fpm configuration..." # Create a dedicated php-fpm config ynh_add_fpm_config @@ -190,54 +200,58 @@ ynh_add_fpm_config #================================================= # SPECIFIC UPGRADE #================================================= -ynh_print_info "Upgrading dokuwiki..." -# Remove upgrade notification inside Dokuwiki's admin panel -# See https://www.dokuwiki.org/update_check -touch $final_path/doku.php +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading dokuwiki..." --weight=7 -# Remove files not used anymore after upgrade -# See https://www.dokuwiki.org/install:unused_files -if [ -f "$final_path/data/deleted.files" ]; then + # Remove upgrade notification inside Dokuwiki's admin panel + # See https://www.dokuwiki.org/update_check + touch $final_path/doku.php - # Use a "sub process" to start a new shell to run these commands - # Allow to use only one "cd" and to be more efficent - ( - # Move to the dokuwiki installation folder so the "official" commands can be used without adaptation - cd $final_path + # Remove files not used anymore after upgrade + # See https://www.dokuwiki.org/install:unused_files + if [ -f "$final_path/data/deleted.files" ]; then - grep --extended-regexp --invert-match '^($|#)' data/deleted.files | xargs --max-args=1 rm --force --dir || true - ) + # Use a "sub process" to start a new shell to run these commands + # Allow to use only one "cd" and to be more efficent + ( + # Move to the dokuwiki installation folder so the "official" commands can be used without adaptation + cd $final_path + + grep --extended-regexp --invert-match '^($|#)' data/deleted.files | xargs --max-args=1 rm --force --dir || true + ) + fi + + # TODO Taken from old "upgrade" script. Should check if it is needed and what it does + # Update all plugins + for name_plugin in $(sudo -s cat $final_path/lib/plugins/*/plugin.info.txt | grep url | awk -F ':' '{print $3}'); + do + # Get a official plugin for dokuwiki, not update a no-official + wget -nv --quiet "https://github.com/splitbrain/dokuwiki-plugin-$name_plugin/zipball/master" -O "${name_plugin}.zip" -o /dev/null || true + if [ -s "${name_plugin}.zip" ]; then + unzip ${name_plugin}.zip + cp -a splitbrain-dokuwiki-plugin-${name_plugin}*/. "$final_path/lib/plugins/$name_plugin/" + fi + done fi -# TODO Taken from old "upgrade" script. Should check if it is needed and what it does -# Update all plugins -for name_plugin in $(sudo -s cat $final_path/lib/plugins/*/plugin.info.txt | grep url | awk -F ':' '{print $3}'); -do - # Get a official plugin for dokuwiki, not update a no-official - sudo wget -nv --quiet "https://github.com/splitbrain/dokuwiki-plugin-${name_plugin}/zipball/master" -O "${name_plugin}.zip" -o /dev/null || true - if [ -s "${name_plugin}.zip" ]; then - sudo unzip ${name_plugin}.zip - sudo cp -a splitbrain-dokuwiki-plugin-${name_plugin}*/. "${final_path}/lib/plugins/${name_plugin}/" - fi -done - #================================================= # LDAP Configuration #================================================= ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different "$final_path/conf/local.protected.php" +ynh_backup_if_checksum_is_different --file="$final_path/conf/local.protected.php" # Always overwrite local file with the one from package. cp ../conf/local.protected.php $final_path/conf # Set the "admin" user -ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" +ynh_replace_string --match_string="__YNH_ADMIN_USER__" --replace_string="$admin" --target_file="$final_path/conf/local.protected.php" # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum "$final_path/conf/local.protected.php" +ynh_store_file_checksum --file="$final_path/conf/local.protected.php" #================================================= # GENERIC FINALIZATION @@ -285,28 +299,28 @@ find $final_path/lib -type d -print0 | xargs -0 chmod 0755 #================================================= # SETUP SSOWAT #================================================= -ynh_print_info "Upgrading SSOwat configuration..." +ynh_script_progression --message="Upgrading SSOwat configuration..." if [ $is_public -eq 0 ] then # Remove the public access - ynh_app_setting_delete $app skipped_uris + ynh_app_setting_delete --app=$app --key=skipped_uris fi # Make app public if necessary if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Upgrade of $app completed" +ynh_script_progression --message="Upgrade of $app completed" --last From a6c4196c35f3cd36b2e087fe9ff989f62470f4bd Mon Sep 17 00:00:00 2001 From: Gofannon Date: Sun, 12 May 2019 15:55:38 +0200 Subject: [PATCH 5/9] [fix] issues spotted durring review --- scripts/actions/internal_users | 18 +++++++----------- scripts/upgrade | 8 +++++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/scripts/actions/internal_users b/scripts/actions/internal_users index 743c86b..271987b 100644 --- a/scripts/actions/internal_users +++ b/scripts/actions/internal_users @@ -13,8 +13,6 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -# Get authentication backend and set as lowercase -#auth_backend=${YNH_ACTION_IS_INTERNAL_USERS,,} # Get "is_internal_users" and set as lowercase is_internal_users=${YNH_ACTION_IS_INTERNAL_USERS,,} @@ -32,6 +30,11 @@ is_internal_users_old=$(ynh_app_setting_get $app is_internal_users) # CHECK IF ARGUMENTS AND REQUIREMENTS ARE CORRECT #================================================= +# Ensure that app is public +if [ $is_public -eq 0 ]; then + ynh_die "Wiki must be public if you want your people to be able to reach it. Run 'public_private' and come back here" 1 +fi + #================================================= # CHECK IF AN ACTION HAS TO BE DONE #================================================= @@ -118,16 +121,9 @@ ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/loca # Recalculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/conf/local.protected.php" - -# Regen ssowat configuration -yunohost app ssowatconf +# Purge cache; see https://www.dokuwiki.org/faq:pluginproblems#cache +touch $final_path/conf/local.php # Update the config of the app ynh_app_setting_set $app auth_backend $auth_backend ynh_app_setting_set $app is_internal_users $is_internal_users - -#================================================= -# RELOAD NGINX -#================================================= - -systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index f641101..121df1d 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -24,7 +24,7 @@ is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) auth_backend=$(ynh_app_setting_get $app auth_backend) -#is_internal_users=$(ynh_app_setting_get $app is_internal_users) +is_internal_users=$(ynh_app_setting_get $app is_internal_users) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -58,6 +58,12 @@ if [ -z "$language" ]; then ynh_app_setting_set $app language $language fi +# 'auth_backend' default value, if not set +if [ -z "$auth_backend" ]; then + auth_backend='authldap' + ynh_app_setting_set $app auth_backend $authldap +fi + # 'is_internal_users' default value, if not set if [ -z "$is_internal_users" ]; then ynh_app_setting_set $app is_internal_users 0 From 37b76987d607407893bf2e69231e6f6bf259efad Mon Sep 17 00:00:00 2001 From: Gofannon Date: Sun, 12 May 2019 15:56:34 +0200 Subject: [PATCH 6/9] Overload default config for peace of mind Add this setting even if not use by default. Only usefull with "internal_users" script. Harmless and makes the maintenance easier --- conf/local.protected.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conf/local.protected.php b/conf/local.protected.php index 04044c8..3f5176c 100644 --- a/conf/local.protected.php +++ b/conf/local.protected.php @@ -28,8 +28,7 @@ $conf['plugin']['authldap']['userfilter'] = '(&(uid=%{user})(objectClass=posixA #$conf['plugin']['authldap']['groupfilter'] = '(&(objectClass=posixGroup)(|(gidNumber=%{gid})(memberUID=%{user})))'; // Authchained plugin preload configuration. Can be used by 'internal_users' action script -//$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain'; -// +$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain'; /* Advanced Settings */ $conf['updatecheck'] = 0; //automatically check for new releases? From 07a018ba5ecdef5319097834141d1f0e98d7f32a Mon Sep 17 00:00:00 2001 From: Gofannon Date: Sun, 12 May 2019 15:59:22 +0200 Subject: [PATCH 7/9] Add helper "ynh_smart_mktemp" --- scripts/_common.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index bb04a03..d98beaf 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,4 +10,48 @@ ynh_delete_file_checksum () { local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' ynh_app_setting_delete $app $checksum_setting_name -} \ No newline at end of file +} + + + + + + + + +# Check available space before creating a temp directory. +# +# usage: ynh_smart_mktemp --min_size="Min size" +# +# | arg: -s, --min_size= - Minimal size needed for the temporary directory, in Mb +ynh_smart_mktemp () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=min_size= ) + local min_size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + min_size="${min_size:-300}" + # Transform the minimum size from megabytes to kilobytes + min_size=$(( $min_size * 1024 )) + + # Check if there's enough free space in a directory + is_there_enough_space () { + local free_space=$(df --output=avail "$1" | sed 1d) + test $free_space -ge $min_size + } + + if is_there_enough_space /tmp; then + local tmpdir=/tmp + elif is_there_enough_space /var; then + local tmpdir=/var + elif is_there_enough_space /; then + local tmpdir=/ + elif is_there_enough_space /home; then + local tmpdir=/home + else + ynh_die "Insufficient free space to continue..." + fi + + echo "$(sudo mktemp --directory --tmpdir="$tmpdir")" +} From 1eaf2dff7c61ecf061db2187e6cfe8f143bf3d70 Mon Sep 17 00:00:00 2001 From: Gofannon Date: Sun, 12 May 2019 15:59:55 +0200 Subject: [PATCH 8/9] Cleaning --- scripts/actions/internal_users | 86 +++++++++++++++++++++++++++------- scripts/install | 3 +- 2 files changed, 72 insertions(+), 17 deletions(-) diff --git a/scripts/actions/internal_users b/scripts/actions/internal_users index 271987b..9e24ab7 100644 --- a/scripts/actions/internal_users +++ b/scripts/actions/internal_users @@ -92,28 +92,82 @@ ynh_backup_if_checksum_is_different "$final_path/conf/local.protected.php" # Always overwrite local file with the one from package. cp conf/local.protected.php $final_path/conf -if [ $is_internal_users -eq 1 ]; -then - auth_backend="authchained" - #authchained_configuration='$conf['p lugin']['authchained']['authtypes'] = 'authldap:authplain';' - #grep -q -F '$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';' "$final_path/conf/local.protected.php" || echo 'include "/configs/projectname.conf"' >> foo.bar +if [ $is_internal_users -eq 1 ]; then + auth_backend="authchained" - # Search if configuration in "config file" is present for plugin to work - #TODO could be added straight to 'local.protected.php' file ? - grep -q -F '$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';' "$final_path/conf/local.protected.php" - if [ $? -ne 0 ]; then - # If not found, add the setting to "local.protected.php" which can only be edited by Yunohost - # \$conf needs the "\" to espace the dollar and avoid echo to interprate it as a (void) variable - echo "\$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';" >> "$final_path/conf/local.protected.php" - fi - # source: https://stackoverflow.com/questions/3557037/appending-a-line-to-a-file-only-if-it-does-not-already-exist + # Automatically install "authchained" plugin + # Allows to use multiple users backend storage : LDAP + internal DokuWiki users + # See https://www.dokuwiki.org/plugin:authchained?s[]=chained + + plugin_archive=dokuwiki-plugin-authchained.tar.gz + wget -nv --quiet 'https://github.com/rztuc/dokuwiki-plugin-authchained/archive/master.tar.gz' -O "$plugin_archive" -o /dev/null || true + + # if "file is not zero size" + if [ -s "$plugin_archive" ]; then + + tmpdir="$(ynh_smart_mktemp --min_size=1)" # Create a 1mb temporary folder + tar xzf "$plugin_archive" -C "$tmpdir" # Extract plugin to the temp folder + + # Extract the "base" field from the plugin archive to create plugin folder name + # See https://www.dokuwiki.org/devel:plugin_info + # + # 'wildcard' is used to avoid having to find the name of the subfolder + # It should not change later but who knows... + plugin_folder_name=$(cat $tmpdir/*/plugin.info.txt | grep url | awk -F ':' '{print $3}') + + # Define the path where plugin has to be installed + plugin_finalpath="$final_path/lib/plugins/$plugin_folder_name" + mkdir -p $plugin_finalpath + + # Copy plugin files to DokuWiki plugin directory + # Doesn't work with "mv" so "cp" instead (taken from "upgrade" script) + cp -a $tmpdir/*/. "$plugin_finalpath/" + + # Cleaning + ynh_secure_remove --file="$tmpdir" + + # Set filesystem rights for new plugin + chown -R $app:root $plugin_finalpath + fi else - auth_backend="authldap" + auth_backend="authldap" + # TODO: Disable/remove "authchained" + + + ##$plugins['authchained'] = 0; in plugins.local.php + # + # + ## Use a "sub process" to start a new shell to run these commands + ## Allow to use only one "cd" and to be more efficent + #( + # cd $final_path/conf + # + # cp plugins.local.php plugins.local.php.bak + # + # # Search if configuration in "config file" is present for plugin to work + # ## -F, --fixed-strings + # ## Interpret PATTERN as a list of fixed strings (instead of regular expressions), separated by newlines, any of which is to + # ## be matched. + # ## -q, --quiet, --silent + # ## Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an + # ## error was detected. Also see the -s or --no-messages option. + # grep --quiet --fixed-strings '$plugins['authchained'] = 0;' "plugins.local.php" + # if [ $? -ne 0 ]; then + # echo "not found in file" + # # If not found, add the setting to "local.protected.php" which can only be edited by Yunohost + # # "\$conf" needs the "\" to espace the dollar and avoid echo to interprate it as a (void) variable + # #echo "\$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';" >> "$final_path/conf/local.protected.php" + # else + # echo "not found in file" + # fi + # # source: https://stackoverflow.com/questions/3557037/appending-a-line-to-a-file-only-if-it-does-not-already-exist + # + #) fi + # Set the authentification backend -#ynh_replace_string "^$conf['authtype'].*" "$conf['authtype'] = '$auth_backend';" "$final_path/conf/local.protected.php" ynh_replace_string "__YNH_AUTH_BACKEND__" "$auth_backend" "$final_path/conf/local.protected.php" # Set the "admin" user ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" diff --git a/scripts/install b/scripts/install index 8297dcb..855a041 100755 --- a/scripts/install +++ b/scripts/install @@ -71,7 +71,8 @@ ynh_app_setting_set $app language $language # Can be changed by action script "internal_users" auth_backend='authldap' # Default backend is LDAP with Yunohost, 'authldap' for DokuWiki ynh_app_setting_set $app auth_backend $auth_backend -# Disable the 'is_internal_users' feature + +# Force disable the 'is_internal_users' feature ynh_app_setting_set $app is_internal_users 0 #================================================= From c825710306eea5fa5f5fc6e6a74402159ed56baa Mon Sep 17 00:00:00 2001 From: Gofannon Date: Sun, 12 May 2019 16:51:10 +0200 Subject: [PATCH 9/9] cleaning 2 --- scripts/actions/internal_users | 37 ---------------------------------- 1 file changed, 37 deletions(-) diff --git a/scripts/actions/internal_users b/scripts/actions/internal_users index 9e24ab7..c69c626 100644 --- a/scripts/actions/internal_users +++ b/scripts/actions/internal_users @@ -44,43 +44,6 @@ then ynh_die "is_internal_users is already set as $is_internal_users." 0 fi -# Ensure that app is public -if [ $is_public -eq 0 ]; then - ynh_die "Wiki must be public if you want your people to be able to reach it. Run 'public_private' and come back here" 1 -fi - -# Plugin "authchained" needs to be installed for this script to run -if [ ! -d $final_path/lib/plugins/authchained ]; then - ynh_die "Plugin 'authchained' is not installed and must be installed beforehand." 1 -fi - -### automatic installation of "authchained" plugin -### FIXME plugin installed this way does not work. Had to reinstall from "admin panel" -# Install "authchained" plugin. Allows to use multiple users backend storage : LDAP + internal DokuWiki users -# See https://www.dokuwiki.org/plugin:authchained?s[]=chained - -#sudo wget -nv --quiet "https://github.com/splitbrain/dokuwiki-plugin-${name_plugin}/zipball/master" -O "${name_plugin}.zip" -o /dev/null || true -#plugin_archive=dokuwiki-plugin-authchained.zip -#wget -nv --quiet 'https://github.com/rztuc/dokuwiki-plugin-authchained/archive/master.zip' -O "$plugin_archive" -o /dev/null || true -# -## if "file is not zero size" -#if [ -s "$plugin_archive" ]; then -# # path "authchained" is hardcoded and a better way should be to use the "base" field from the plugin archive -# # See https://www.dokuwiki.org/devel:plugin_info -# mkdir $final_path/lib/plugins/authchained -# -# # Extract plugin files strayed to the local plugin directory -# # Assume that the plugin name will not change in the futur -# # -# # unzip options -# # -j junk paths (do not make directories) -# # -d extract files into exdir -# unzip -j -d $final_path/lib/plugins/authchained "$plugin_archive" -# -# # Set filesystem rights for new plugin -# chown -R $app:root $final_path/lib/plugins/authchained -#fi - #================================================= # SPECIFIC ACTION #=================================================