diff --git a/check_process b/check_process index ca404fa..9407579 100644 --- a/check_process +++ b/check_process @@ -1,3 +1,8 @@ +# See here for more informations +# https://github.com/YunoHost/package_check#syntax-check_process-file + +# Move this file from check_process.default to check_process when you have filled it. + ;; Test complet auto_remove=1 ; Manifest @@ -16,13 +21,9 @@ upgrade=1 from_commit=01add99d3d903ca6d07f863045edf2ba46cf18d5 backup_restore=1 multi_instance=1 - wrong_user=1 - wrong_path=1 incorrect_path=1 - corrupt_source=0 - fail_download_source=0 port_already_use=0 - final_path_already_use=0 + change_url=1 ;;; Levels Level 1=auto Level 2=auto @@ -38,3 +39,6 @@ ; commit=01add99d3d903ca6d07f863045edf2ba46cf18d5 name=Create check_process manifest_arg=domain=DOMAIN&path=PATH&admin=USER&is_public=Yes& +;;; Options +Email= +Notification=none diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..e42acb7 --- /dev/null +++ b/conf/app.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://download.dokuwiki.org/src/dokuwiki/dokuwiki-2018-04-22a.tgz +SOURCE_SUM=18765a29508f96f9882349a304bffc03 +SOURCE_SUM_PRG=md5sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/dokuwiki.php b/conf/dokuwiki.php deleted file mode 100644 index 7aac9c9..0000000 --- a/conf/dokuwiki.php +++ /dev/null @@ -1,188 +0,0 @@ - tags - // 'htmldiff' - diff as HTML table - // 'html' - the full page rendered in XHTML -$conf['rss_media'] = 'both'; //what should be listed? - // 'both' - page and media changes - // 'pages' - page changes only - // 'media' - media changes only -$conf['rss_update'] = 5*60; //Update the RSS feed every n seconds (defaults to 5 minutes) -$conf['rss_show_summary'] = 1; //Add revision summary to title? 0|1 - -/* Advanced Settings */ -$conf['updatecheck'] = 0; //automatically check for new releases? -$conf['userewrite'] = 0; //this makes nice URLs: 0: off 1: .htaccess 2: internal -$conf['useslash'] = 0; //use slash instead of colon? only when rewrite is on -$conf['sepchar'] = '_'; //word separator character in page names; may be a - // letter, a digit, '_', '-', or '.'. -$conf['canonical'] = 0; //Should all URLs use full canonical http://... style? -$conf['fnencode'] = 'url'; //encode filenames (url|safe|utf-8) -$conf['autoplural'] = 0; //try (non)plural form of nonexisting files? -$conf['compression'] = 'gz'; //compress old revisions: (0: off) ('gz': gnuzip) ('bz2': bzip) - // bz2 generates smaller files, but needs more cpu-power -$conf['gzip_output'] = 0; //use gzip content encodeing for the output xhtml (if allowed by browser) -$conf['compress'] = 1; //Strip whitespaces and comments from Styles and JavaScript? 1|0 -$conf['cssdatauri'] = 0; //Maximum byte size of small images to embed into CSS, won't work on IE<8 -$conf['send404'] = 0; //Send a HTTP 404 status for non existing pages? -$conf['broken_iua'] = 0; //Platform with broken ignore_user_abort (IIS+CGI) 0|1 -$conf['xsendfile'] = 0; //Use X-Sendfile (1 = lighttpd, 2 = standard) -$conf['renderer_xhtml'] = 'xhtml'; //renderer to use for main page generation -$conf['readdircache'] = 0; //time cache in second for the readdir operation, 0 to deactivate. - -/* Network Settings */ -$conf['dnslookups'] = 1; //disable to disallow IP to hostname lookups -// Proxy setup - if your Server needs a proxy to access the web set these -$conf['proxy']['host'] = ''; -$conf['proxy']['port'] = ''; -$conf['proxy']['user'] = ''; -$conf['proxy']['pass'] = ''; -$conf['proxy']['ssl'] = 0; -$conf['proxy']['except'] = ''; -// Safemode Hack - read http://www.dokuwiki.org/config:safemodehack ! -$conf['safemodehack'] = 0; -$conf['ftp']['host'] = 'localhost'; -$conf['ftp']['port'] = '21'; -$conf['ftp']['user'] = 'user'; -$conf['ftp']['pass'] = 'password'; -$conf['ftp']['root'] = '/home/user/htdocs'; - - diff --git a/conf/local.php b/conf/local.php new file mode 100644 index 0000000..cfa5cd6 --- /dev/null +++ b/conf/local.php @@ -0,0 +1,13 @@ +> 2.3.15" + "yunohost": ">> 2.7.14" }, "description": { "en": "DokuWiki is a simple to use and highly versatile Open Source wiki software that doesn't require a database.", @@ -12,18 +12,25 @@ "es": "DokuWiki es un sistema de Wiki de uso sencillicimo y compatible con los estándares.", "it": "DokuWiki è un Wiki aderente agli standard, semplice da usare, finalizzato principalmente alla creazione di documentazione di qualsiasi tipo." }, - "version": "1.1.0", + "version": "2018-04-22a~ynh1", "url": "https://www.dokuwiki.org", "maintainer": { - "name": "opi", - "email": "opi@zeropi.net" + "name": "Gofannon", + "email": "gofannon@riseup.net" }, + "previous_maintainers": [ + { + "name": "opi", + "email": "opi@zeropi.net", + "url": "" + } +], "multi_instance": true, "services": [ "nginx", "php5-fpm" ], - "license": "free", + "license": "GPL-2.0-or-later", "arguments": { "install" : [ { @@ -62,6 +69,15 @@ "fr": "Est-ce un site public ?" }, "default": "true" + }, + { + "name": "language", + "ask": { + "en": "Choose the application language", + "fr": "Choisissez la langue de l'application" + }, + "choices": ["en", "fr"], + "default": "en" } ] } diff --git a/scripts/.fonctions b/scripts/.fonctions deleted file mode 100644 index 4e87c5f..0000000 --- a/scripts/.fonctions +++ /dev/null @@ -1,254 +0,0 @@ -#!/bin/bash - -ynh_version="2.4" - -YNH_VERSION () { # Display number version of the YunoHost moulinette - ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) -} - -CHECK_VAR () { # Check variable is not empty -# $1 = Checking variable -# $2 = Text to display on error - test -n "$1" || (echo "$2" >&2 && false) -} - -EXIT_PROPERLY () { # Causes the script to stop in the event of an error. And clean the residue. - trap '' ERR - echo -e "\e[91m \e[1m" # Shell in light red bold - echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!" >&2 - - if type -t CLEAN_SETUP > /dev/null; then # Checks the existence of the function before executing it. - CLEAN_SETUP # Call the specific cleanup function of the install script. - fi - - sudo sed -i "\@\"$domain$path/\":@d" /etc/ssowat/conf.json - - if [ "$ynh_version" = "2.2" ]; then - /bin/bash $script_dir/remove # Call the remove script. In 2.2, this behavior is not automatic. - fi - - ynh_die -} - -TRAP_ON () { # Activate signal capture - trap EXIT_PROPERLY ERR # Capturing exit signals on error -} - -TRAP_OFF () { # Ignoring signal capture until TRAP_ON - trap '' ERR # Ignoring exit signals -} - -CHECK_USER () { # Check the validity of the user admin - # $1 = User admin variable - ynh_user_exists "$1" || (echo "Wrong admin" >&2 && false) -} - -CHECK_PATH () { # Checks / at the beginning of the path. And his absence at the end. - if [ "${path:0:1}" != "/" ]; then # If the first character is not / - path="/$path" # Add / at the beginning of path - fi - if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # If the last character is a / and it is not the only character. - path="${path:0:${#path}-1}" # Delete last character - fi -} - -CHECK_DOMAINPATH () { # Checks the availability of the path and domain. - sudo yunohost app checkurl $domain$path -a $app -} - -CHECK_FINALPATH () { # Checks that the destination folder is not already in use. - final_path=/var/www/$app - if [ -e "$final_path" ] - then - echo "This path already contains a folder" >&2 - false - fi -} - -SETUP_SOURCE () { # Download source, decompress and copu into $final_path - src=$(cat ../sources/source_md5 | awk -F' ' {'print $2'}) - sudo wget -nv -i ../sources/source_url -O $src - # Checks the checksum of the downloaded source. - md5sum -c ../sources/source_md5 --status || ynh_die "Corrupt source" - # Decompress source - if [ "$(echo ${src##*.})" == "tgz" ]; then - tar -x -f $src - elif [ "$(echo ${src##*.})" == "zip" ]; then - unzip -q $src - else - false # Unsupported archive format. - fi - # Copy file source - sudo cp -a $(cat ../sources/source_dir)/. "$final_path" - # Copy additional file and modified - if test -e "../sources/ajouts"; then - sudo cp -a ../sources/ajouts/. "$final_path" - fi -} - -POOL_FPM () { # Create the php-fpm pool configuration file and configure it. - sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf - sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf - sed -i "s@__USER__@$app@g" ../conf/php-fpm.conf - finalphpconf=/etc/php5/fpm/pool.d/$app.conf - sudo cp ../conf/php-fpm.conf $finalphpconf - sudo chown root: $finalphpconf - finalphpini=/etc/php5/fpm/conf.d/20-$app.ini - sudo cp ../conf/php-fpm.ini $finalphpini - sudo chown root: $finalphpini - sudo systemctl reload php5-fpm -} - -STORE_MD5_CONFIG () { # Saves the checksum of the config file - # $1 = Name of the conf file for storage in settings.yml - # $2 = Full name and path of the conf file. - ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1) -} - -CHECK_MD5_CONFIG () { # Created a backup of the config file if it was changed. - # $1 = Name of the conf file for storage in settings.yml - # $2 = Full name and path of the conf file.onf. - if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then - sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup. - fi -} - -FIND_PORT () { # Search free port - # $1 = Port number to start the search. - port=$1 - while ! sudo yunohost app checkport $port ; do - port=$((port+1)) - done - CHECK_VAR "$port" "port empty" -} - - -### REMOVE SCRIPT - -REMOVE_NGINX_CONF () { # Delete nginx configuration - if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then - echo "Delete nginx config" - sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" - sudo systemctl reload nginx - fi -} - -REMOVE_FPM_CONF () { # Delete pool php-fpm configuration - if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config - echo "Delete fpm config" - sudo rm "/etc/php5/fpm/pool.d/$app.conf" - fi - if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config - echo "Delete php config" - sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" - fi - sudo systemctl reload php5-fpm -} - -REMOVE_LOGROTATE_CONF () { # Delete logrotate configuration - if [ -e "/etc/logrotate.d/$app" ]; then - echo "Delete logrotate config" - sudo rm "/etc/logrotate.d/$app" - fi -} - -SECURE_REMOVE () { # Deleting a folder with variable verification - chaine="$1" # The argument must be given between simple quotes '', to avoid interpreting the variables. - no_var=0 - while (echo "$chaine" | grep -q '\$') # Loop as long as there are $ in the string - do - no_var=1 - global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole the first variable found. - only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole completely the variable by adding the $ at the beginning and keeping only the name of the variable. Mostly gets rid of / and a possible path behind. - real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` Allows to interpret a variable contained in a variable. - if test -z "$real_var" || [ "$real_var" = "/" ]; then - echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2 - return 1 - fi - chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # Replaces variable with its value in the string. - done - if [ "$no_var" -eq 1 ] - then - if [ -e "$chaine" ]; then - echo "Delete directory $chaine" - sudo rm -r "$chaine" - fi - return 0 - else - echo "No detected variable." >&2 - return 1 - fi -} - - -# Check if a YunoHost user exists -# -# example: ynh_user_exists 'toto' || exit 1 -# -# usage: ynh_user_exists username -# | arg: username - the username to check -ynh_user_exists() { - sudo yunohost user list --output-as json | grep -q "\"username\": \"${1}\"" -} - -# Retrieve a YunoHost user information -# -# example: mail=$(ynh_user_get_info 'toto' 'mail') -# -# usage: ynh_user_get_info username key -# | arg: username - the username to retrieve info from -# | arg: key - the key to retrieve -# | ret: string - the key's value -ynh_user_get_info() { - sudo yunohost user info "$1" --output-as plain | ynh_get_plain_key "$2" -} - -# Get the list of YunoHost users -# -# example: for u in $(ynh_user_list); do ... -# -# usage: ynh_user_list -# | ret: string - one username per line -ynh_user_list() { - sudo yunohost user list --output-as plain --quiet \ - | awk '/^##username$/{getline; print}' -} - -# Check if a user exists on the system -# -# usage: ynh_system_user_exists username -# | arg: username - the username to check -ynh_system_user_exists() { - getent passwd "$1" &>/dev/null -} - -# Create a system user -# -# usage: ynh_system_user_create user_name [home_dir] -# | arg: user_name - Name of the system user that will be create -# | arg: home_dir - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home -ynh_system_user_create () { - if ! ynh_system_user_exists "$1" # Check if the user exists on the system - then # If the user doesn't exist - if [ $# -ge 2 ]; then # If a home dir is mentioned - user_home_dir="-d $2" - else - user_home_dir="--no-create-home" - fi - sudo useradd $user_home_dir --system --user-group $1 --shell /usr/sbin/nologin || ynh_die "Unable to create $1 system account" - fi -} - -# Delete a system user -# -# usage: ynh_system_user_delete user_name -# | arg: user_name - Name of the system user that will be create -ynh_system_user_delete () { - if ynh_system_user_exists "$1" # Check if the user exists on the system - then - echo "Remove the user $1" >&2 - sudo userdel $1 - else - echo "The user $1 was not found" >&2 - fi -} diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..bb04a03 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# ============= FUTURE YUNOHOST HELPER ============= +# Delete a file checksum from the app settings +# +# $app should be defined when calling this helper +# +# usage: ynh_remove_file_checksum file +# | arg: file - The file for which the checksum will be deleted +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 diff --git a/scripts/backup b/scripts/backup index fe7ddd8..9c63df7 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,23 +1,52 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Get multi-instances specific variables -app=$YNH_APP_INSTANCE_NAME - -# Source app helpers +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -# Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= -# Copy the app files -final_path="/var/www/${app}" -ynh_backup "$final_path" "sources" 1 +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get $app domain) + +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup "$final_path" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# BACKUP THE PHP-FPM CONFIGURATION +#================================================= + +ynh_backup "/etc/php5/fpm/pool.d/$app.conf" +ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" + +#================================================= +# SPECIFIC BACKUP +#================================================= -# Copy the nginx conf files -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" -# Copy the php-fpm conf files -ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf" -ynh_backup "/etc/php5/fpm/conf.d/20-${app}.ini" "php-fpm.ini" \ No newline at end of file diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..2af51af --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,100 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +old_domain=$YNH_APP_OLD_DOMAIN +old_path=$YNH_APP_OLD_PATH + +new_domain=$YNH_APP_NEW_DOMAIN +new_path=$YNH_APP_NEW_PATH + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# LOAD 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) + +#================================================= +# CHECK WHICH PARTS SHOULD BE CHANGED +#================================================= + +change_domain=0 +if [ "$old_domain" != "$new_domain" ] +then + change_domain=1 +fi + +change_path=0 +if [ "$old_path" != "$new_path" ] +then + change_path=1 +fi + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= + +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# Change the path in the nginx config file +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" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Store path_url setting + ynh_app_setting_set $app path "$path_url" + # Create a dedicated 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 "$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" +fi + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +# ... +#================================================= + +#================================================= +# GENERIC FINALISATION +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx diff --git a/scripts/install b/scripts/install index a7cdf9d..6f496c4 100755 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,30 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +admin=$YNH_APP_ARG_ADMIN +is_public=$YNH_APP_ARG_IS_PUBLIC +language=$YNH_APP_ARG_LANGUAGE # This is a multi-instance app, meaning it can be installed several times independently # The id of the app as stated in the manifest is available as $YNH_APP_ID @@ -13,82 +36,209 @@ set -eu # The app instance name is probably what you are interested the most, since this is # guaranteed to be unique. This is a good unique identifier to define installation path, # db names, ... -# Retrieve arguments - -source .fonctions # Loads the generic functions usually used in the script -# Source app helpers -source /usr/share/yunohost/helpers - -TRAP_ON # Active trap for strop script if detect error. - -domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH -admin=$YNH_APP_ARG_ADMIN -is_public=$YNH_APP_ARG_IS_PUBLIC - app=$YNH_APP_INSTANCE_NAME -CHECK_VAR "$app" "app name not set" +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= -CHECK_USER "$admin" +final_path=/var/www/$app +test ! -e "$final_path" || ynh_die "This path already contains a folder" -CHECK_PATH +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) -CHECK_DOMAINPATH +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url -CHECK_FINALPATH +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= -# Save app settings ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path +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 -# Create system user dedicace for this app +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +ynh_app_setting_set $app final_path $final_path +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user ynh_system_user_create $app -# Modify dokuwiki conf -sed -i "s@YNH_ADMIN_USER@$admin@g" ../conf/dokuwiki.php +#================================================= +# PHP-FPM CONFIGURATION +#================================================= -# Copy files to the right place -sudo mkdir "$final_path" -ynh_app_setting_set $app final_path $final_path +# Create a dedicated php-fpm config +ynh_add_fpm_config -# Get source -SETUP_SOURCE +#================================================= +# SPECIFIC SETUP +#================================================= +# CUSTOMIZE DOKUWIKI +#================================================= -sudo cp ../conf/dokuwiki.php $final_path/conf -sudo cp ../conf/acl.auth.php $final_path/conf +# Set the "admin" user +ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "../conf/local.protected.php" -# Files owned by dokuwiki can just read -sudo chown -R root: $final_path +# Set the "language" +ynh_replace_string "__YNH_LANGUAGE__" "$language" "../conf/local.php" -# except for conf, data, some data subfolders, and lib/plugin, where www-data must have write permissions -sudo chown -R $app:root $final_path/{conf,data,data/attic,data/cache,data/index,data/locks,data/media*,data/meta,data/pages,data/tmp,lib/plugins,lib/tpl} -sudo chmod -R 700 $final_path/conf -sudo chmod -R 700 $final_path/data -sudo chmod -R 755 $final_path/lib/plugins -sudo chmod 755 $final_path/lib/tpl/{dokuwiki,dokuwiki/images} -# Modify Nginx configuration file and copy it to Nginx conf directory -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf -sudo sed -i "s@__PATHTOCHANGE__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf -sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf -sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf +# Copy Yunohost specific configuration -if [ "$is_public" = "Yes" ]; +# Loading order of configuration files +# +# By default DokuWiki loads its configuration files in the following order: +# +# 1. conf/dokuwiki.php +# 2. conf/local.php +# 3. conf/local.protected.php +# +# See https://www.dokuwiki.org/plugin:config#protecting_settings + +cp ../conf/local.protected.php $final_path/conf +# This File cannot be modified directly by Dokuwiki, only by hand or by Yunohost +# It will only be updated by Yunohost package or directly by adventurous users + +cp ../conf/local.php $final_path/conf +# 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 + +# 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 + +#================================================= +# CREATE DEFAULT FILES +#================================================= + +# For securing DokuWiki installation, create default files that will be writable in the "conf" folder. +# Other files will be read ony and owned by root. +# See https://www.dokuwiki.org/install:permissions + + +cp $final_path/conf/local.php.dist $final_path/conf/local.php.bak +cp $final_path/conf/users.auth.php.dist $final_path/conf/users.auth.php + +cp $final_path/inc/preload.php.dist $final_path/inc/preload.php +# This file might be used by plugins like https://www.dokuwiki.org/plugin:siteexport +# Create it to be more "user friendly" as over the top security is not the main goal here +# This file could be use for bad behaviour. +# See https://www.dokuwiki.org/devel:preload?s[]=preload + +# There is no template .dist provided inside DokuWiki installation folder +# Create "empty" files to be able to manage linux permissions +# Files content is taken from an existing DokuWiki installation +cp ../conf/plugins.local.php $final_path/conf +cp ../conf/plugins.local.php $final_path/conf/plugins.local.php.bak + +# Create file if it does not exist +if [ ! -f "$final_path/conf/local.protected.php" ]; then + # Set the default "admin" + # Replace string in order to have a functionnal configuration file + ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "../conf/local.protected.php" + + cp ../conf/local.protected.php $final_path/conf +fi + +#================================================= +# STORE THE CHECKSUM OF THE CONFIG FILE +#================================================= + +# 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 "$final_path/conf/local.php" +ynh_store_file_checksum "$final_path/conf/acl.auth.php" +#================================================= + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Try to use "least privilege" to grant minimal access +# For details, see https://www.dokuwiki.org/install:permissions + +# Files owned by DokuWiki can just read +chown -R root: $final_path + +# DokuWiki needs to write inside these folders. Do "DokuWiki" owner +chown $app:root $final_path/conf +chown $app:root $final_path/inc + +# Do "DokuWiki" owner of configuration files that must be writable +chown $app:root $final_path/conf/{local.php,local.php.bak,users.auth.php,acl.auth.php,plugins.local.php,plugins.local.php.bak} +# Usefull for some plugins like https://www.dokuwiki.org/plugin:siteexport +# See https://www.dokuwiki.org/devel:preload +chown $app:root $final_path/inc/preload.php +# Grant read-only to all files as files copied above are owned by root by defaut and nginx cannot read them +# There are only files in the folder and there is sublevels. No need to use "find" +chmod -R a+r $final_path/conf +chmod -R a+r $final_path/inc + +# Give write access to "data" and subfolders +chown -R $app:root $final_path/data +# Remove access to "other" +chmod -R o-rwx $final_path/data + +# Allow the web admin panel to run, aka "Extension Manager" +chown -R $app:root $final_path/lib/plugins +# Allow to install templates +chown -R $app:root $final_path/lib/tpl + +# Allow access to public assets like style sheets +find $final_path/lib -type f -print0 | xargs -0 chmod 0644 +find $final_path/lib -type d -print0 | xargs -0 chmod 0755 +# Using "find" instead of "chmod -R 755" so files does not become executable too +# chmod : -rwxr-xr-x 1 root root 241 May 3 08:36 index.html => BAD +# find : -rw-r--r-- 1 1001 1002 241 May 3 08:36 index.html => GOOD + +#================================================= +# SETUP SSOWAT +#================================================= + +# Not needed as no skipped_uris have been added before. +# Example : "ynh_app_setting_set $app skipped_uris ..." +# See https://github.com/YunoHost-Apps/dokuwiki_ynh/pull/37 for explanation +#if [ $is_public -eq 0 ] +#then # Remove the public access +# ynh_app_setting_delete $app skipped_uris +#fi + +# Make app public if necessary +if [ $is_public -eq 1 ] then - sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set $app unprotected_uris "/" fi -# Create the php-fpm pool config -POOL_FPM +#================================================= +# RELOAD NGINX +#================================================= -# If app is public, add url to SSOWat conf as skipped_uris -if [[ $is_public -eq 1 ]]; then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" -fi - -# Reload Nginx -sudo systemctl reload nginx \ No newline at end of file +systemctl reload nginx diff --git a/scripts/remove b/scripts/remove index 6fa841a..f453065 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,30 +1,58 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -u +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= -# Get multi-instances specific variables app=$YNH_APP_INSTANCE_NAME -# Loads the generic functions usually used in the script -source .fonctions -# Source app helpers -. /usr/share/yunohost/helpers +domain=$(ynh_app_setting_get $app domain) +final_path=$(ynh_app_setting_get $app final_path) -# Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# STANDARD REMOVE +#================================================= -# Delete app directory and configurations -sudo rm -rf "/var/www/${app}" -sudo rm -f "/etc/php5/fpm/pool.d/${app}.conf" -sudo rm -f "/etc/php5/fpm/conf.d/20-${app}.ini" -[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" +#================================================= +# REMOVE APP MAIN DIR +#================================================= -# Reload services -sudo systemctl reload php5-fpm -sudo systemctl reload nginx +# Remove the app directory securely +ynh_secure_remove "$final_path" -# Delete system user dedicace for this app +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# REMOVE PHP-FPM CONFIGURATION +#================================================= + +# Remove the dedicated php-fpm config +ynh_remove_fpm_config + +#================================================= +# SPECIFIC REMOVE +#================================================= + + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= + +# Delete a system user ynh_system_user_delete $app - -echo -e "\e[0m" # Restore normal color \ No newline at end of file diff --git a/scripts/restore b/scripts/restore index 2ee9014..754220d 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,69 +1,94 @@ #!/bin/bash -# This restore script is adapted to Yunohost >=2.4 -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# The parameter $2 is the id of the app instance ex: ynhexample__2 -app=$YNH_APP_INSTANCE_NAME - -if [ ! -e .fonctions ]; then - # Get file fonction if not been to the current directory - sudo cp ../settings/scripts/.fonctions ./.fonctions - sudo chmod a+rx .fonctions -fi -# Loads the generic functions usually used in the script -source .fonctions -# Source app helpers +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -# Get old parameter of the app +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + domain=$(ynh_app_setting_get $app domain) -path=$(ynh_app_setting_get $app path) -is_public=$(ynh_app_setting_get $app is_public) +path_url=$(ynh_app_setting_get $app path) +final_path=$(ynh_app_setting_get $app final_path) -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= -# Check $final_path -final_path="/var/www/${app}" -if [ -d $final_path ]; then - ynh_die "There is already a directory: $final_path" -fi +ynh_webpath_available $domain $path_url \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die "There is already a directory: $final_path " -# Check configuration files nginx -nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" -if [ -f $nginx_conf ]; then - ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app." -fi -# Check configuration files php-fpm -phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" -if [ -f $phpfpm_conf ]; then - ynh_die "The PHP FPM configuration already exists at '${phpfpm_conf}'. You should safely delete it before restoring this app." -fi +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= -phpfpm_ini="/etc/php5/fpm/conf.d/20-${app}.ini" -if [ -f $phpfpm_ini ]; then - ynh_die "The PHP FPM INI configuration already exists at '${phpfpm_ini}'. You should safely delete it before restoring this app." -fi +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" -# Create system user dedicace for this app +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= + +ynh_restore_file "$final_path" + +#================================================= +# RECREATE THE DEDICATED USER +#================================================= + +# Create the dedicated user (if not existing) ynh_system_user_create $app - # Restore sources & data -sudo cp -a ./sources "${final_path}" +#================================================= +# RESTORE USER RIGHTS +#================================================= -# Set permissions -sudo chown -R $app: "${final_path}" +# Restore permissions on app files +chown -R root: $final_path -# Restore nginx configuration files -sudo cp -a ./nginx.conf "${nginx_conf}" -# Restore php-fpm configuration files -sudo cp -a ./php-fpm.conf "${phpfpm_conf}" -sudo cp -a ./php-fpm.ini "${phpfpm_ini}" +# Restore permissions same as from the 'install' script +# except for conf, data, some data subfolders, and lib/plugin, where www-data must have write permissions +chown -R $app:root $final_path/{conf,data,data/attic,data/cache,data/index,data/locks,data/media*,data/meta,data/pages,data/tmp,lib/plugins,lib/tpl} +chmod -R 700 $final_path/conf +chmod -R 700 $final_path/data +chmod -R 755 $final_path/lib/plugins +chmod 755 $final_path/lib/tpl/{dokuwiki,dokuwiki/images} -# Reload services -sudo systemctl reload php5-fpm -sudo systemctl reload nginx -sudo yunohost app ssowatconf +#================================================= +# RESTORE THE PHP-FPM CONFIGURATION +#================================================= + +ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" +ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini" + +#================================================= +# SPECIFIC RESTORATION +#================================================= + + + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= + +systemctl reload php5-fpm +systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index 4f66a04..827c77f 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,128 +1,320 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -if [ ! -e .fonctions ]; then - # Get file fonction if not been to the current directory - sudo cp ../settings/scripts/.fonctions ./.fonctions - sudo chmod a+rx .fonctions -fi -# Loads the generic functions usually used in the script -source .fonctions -# Source app helpers +source _common.sh source /usr/share/yunohost/helpers -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME -# Retrieve app settings domain=$(ynh_app_setting_get $app domain) -path=$(ynh_app_setting_get $app path) +path_url=$(ynh_app_setting_get $app path) admin=$(ynh_app_setting_get $app admin) is_public=$(ynh_app_setting_get $app is_public) -multisite=$(ynh_app_setting_get $app multisite) +# Not needed during upgrade as user might have change it since installation from Dokuwiki admin panel +#language=$(ynh_app_setting_get $app language) +final_path=$(ynh_app_setting_get $app final_path) -# Remove trailing slash to path -path=${path%/} -#force location to be / or /foo -location=${path:-/} +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= -# admin default value, if not set -if [ -z "$admin" ]; -then +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set $app is_public 1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set $app is_public 0 + is_public=0 +fi + +# If final_path doesn't exist, create it +if [ -z $final_path ]; then + final_path=/var/www/$app + ynh_app_setting_set $app final_path $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" fi -# Create system user dedicace for this app +# language default value, if not set +if [ -z "$language" ]; then + language='en' + ynh_app_setting_set $app language $language +fi + + +# Yunohost specific configuration, if not exists + +# Previously, these settings were store a unique "dokuwiki.php" +# Now, they are split in multiples files to ease upgrading process (separate Yunohost config from user config) + +# Loading order of configuration files +# +# By default DokuWiki loads its configuration files in the following order: +# +# 1. conf/dokuwiki.php +# 2. conf/local.php +# 3. conf/local.protected.php +# +# See https://www.dokuwiki.org/plugin:config#protecting_settings + + +# Configuration dedicated to Yunohost (LDAP and admin mainly) +# Create file if it does not exist +if [ ! -f "$final_path/conf/local.protected.php" ]; then + # Set the default "admin" + # Replace string in order to have a functionnal configuration file + ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "../conf/local.protected.php" + + cp ../conf/local.protected.php $final_path/conf +fi + +# Do not overwrite existing dokuwiki configuration as it could have user customization's and settings. +# Cannot use helper "ynh_backup_if_checksum_is_different" +# Create file if it does not exist +if [ ! -f "$final_path/conf/local.php" ]; then + # Set the default "language" only when file does not exist beforehand + # Replace string in order to have a functionnal configuration file + ynh_replace_string "__YNH_LANGUAGE__" "$language" "../conf/local.php" + + cp ../conf/local.php $final_path/conf +fi + +# Do not overwrite existing ACL configuration file as it could have user customization's and settings. +# Cannot use helper "ynh_backup_if_checksum_is_different" +# Create file if it does not exist +# See https://www.dokuwiki.org/acl#background_info +if [ ! -f "$final_path/conf/acl.auth.php" ]; then + cp ../conf/acl.auth.php $final_path/conf +fi + +# For securing DokuWiki installation, create default files that will be writable in the "conf" folder. +# Other files will be read ony and owned by root. +# See https://www.dokuwiki.org/install:permissions + +# Create file if it does not exist +if [ ! -f "$final_path/conf/local.protected.php" ]; then + # Set the default "admin" + # Replace string in order to have a functionnal configuration file + ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "../conf/local.protected.php" + + cp ../conf/local.protected.php $final_path/conf +fi + +# If file does not exists +if [ ! -f "$final_path/conf/local.php.bak" ]; then + # if template exists + if [ -f "$final_path/conf/local.php.dist" ]; then + # Copy template to create default file + cp "$final_path/conf/local.php.dist" "$final_path/conf/local.php.bak" + fi +fi + +if [ ! -f "$final_path/conf/users.auth.php" ]; then + if [ -f "$final_path/conf/users.auth.php.dist" ]; then + cp $final_path/conf/users.auth.php.dist $final_path/conf/users.auth.php + fi +fi + +if [ ! -f "$final_path/conf/plugins.local.php" ]; then + cp ../conf/plugins.local.php $final_path/conf +fi + +if [ ! -f "$final_path/conf/plugins.local.php.bak" ]; then + cp ../conf/plugins.local.php $final_path/conf/plugins.local.php.bak +fi + + +if [ ! -f "$final_path/inc/preload.php" ]; then + # if template exists + if [ -f "$final_path/inc/preload.php.dist" ]; then + # Copy template to create default file + cp "$final_path/inc/preload.php.dist" "$final_path/inc/preload.php" + fi +fi + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user ynh_system_user_create $app -# Modify dokuwiki conf -sed -i "s@YNH_ADMIN_USER@$admin@g" ../conf/dokuwiki.php +#================================================= +# PHP-FPM CONFIGURATION +#================================================= -# Copy files to the right place -final_path=/var/www/$app -sudo mkdir -p $final_path +# Create a dedicated php-fpm config +ynh_add_fpm_config -# Get source -SETUP_SOURCE +#================================================= +# SPECIFIC UPGRADE +#================================================= -sudo cp ../conf/dokuwiki.php $final_path/conf - -# Do not override ACL configuration file -if [ ! -f "$final_path/conf/acl.auth.php" ]; then - sudo cp ../conf/acl.auth.php $final_path/conf -fi - -# Remove upgrade notification +# Remove upgrade notification inside Dokuwiki's admin panel # See https://www.dokuwiki.org/update_check -sudo touch $final_path/doku.php +touch $final_path/doku.php -# Remove deleted files +# Remove files not used anymore after upgrade # See https://www.dokuwiki.org/install:unused_files -if [ -f "../sources/data/deleted.files" ]; then - grep -Ev '^($|#)' ../sources/data/deleted.files | xargs -I {} sudo rm -vrf $final_path/{} +if [ -f "$final_path/data/deleted.files" ]; then + + # 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 + + # This command could not remove directory + #grep -Ev '^($|#)' data/deleted.files | xargs -n 1 rm -vf + # => "rm: cannot remove 'vendor/easybook/geshi': Is a directory" + + # That one works as expected + grep -Ev '^($|#)' data/deleted.files | xargs -n 1 rm -fr + ) fi -# Change owner for all plugins -sudo chmod -R 755 $final_path/lib/plugins - +# 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 + # 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 -# Files owned by www-data can just read -sudo chown -R root: $final_path +#================================================= -# except for conf, data, some data subfolders, and lib/plugin, where dokuwiki must have write permissions -if [ -d "${final_path}/data/media" ]; then - sudo chown -R $app:root $final_path/{data/attic,data/cache,data/index,data/locks,data/media*,data/meta,data/pages,data/tmp} +#================================================= +# LDAP Configuration +#================================================= + +# Verify if existing file needs to be upgraded by comparing it's size to new file from package +# If different, do a backup of existing file and overwrite with new file +# +# Safe here as this file is only used by Yunohost. Dokuwiki cannot modified it. +ynh_backup_if_checksum_is_different "$final_path/conf/local.protected.php" + +# Set the "admin" user +ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "../conf/local.protected.php" + +cp ../conf/local.protected.php $final_path/conf +# This File cannot be modified directly by Dokuwiki, only by hand or by Yunohost +# It will only be updated by Yunohost package or directly by adventurous users + +# Recalculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/conf/local.protected.php" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Try to use "least privilege" to grant minimal access +# For details, see https://www.dokuwiki.org/install:permissions + +# Files owned by DokuWiki can just read +chown -R root: $final_path + +# DokuWiki needs to write inside these folders. Do "DokuWiki" owner +chown $app:root $final_path/conf +chown $app:root $final_path/inc + +# Do "DokuWiki" owner of configuration files that must be writable +chown $app:root $final_path/conf/{local.php,local.php.bak,users.auth.php,acl.auth.php,plugins.local.php,plugins.local.php.bak} +chown $app:root $final_path/inc/preload.php +# Grant read-only to all files as files copied above are owned by root by defaut and nginx cannot read them +# There are only files in the folder and there is sublevels. No need to use "find" +chmod -R a+r $final_path/conf +chmod -R a+r $final_path/inc + +# Give write access to "data" and subfolders +chown -R $app:root $final_path/data +# Remove access to "other" +chmod -R o-rwx $final_path/data + +# Allow the web admin panel to run, aka "Extension Manager" +chown -R $app:root $final_path/lib/plugins +# Allow to install templates +chown -R $app:root $final_path/lib/tpl + +# Allow access to public assets like style sheets +find $final_path/lib -type f -print0 | xargs -0 chmod 0644 +find $final_path/lib -type d -print0 | xargs -0 chmod 0755 +# Using "find" instead of "chmod -R 755" so files does not become executable too +# chmod : -rwxr-xr-x 1 root root 241 May 3 08:36 index.html => BAD +# find : -rw-r--r-- 1 1001 1002 241 May 3 08:36 index.html => GOOD + +#================================================= +# SETUP SSOWAT +#================================================= + +if [ $is_public -eq 0 ] +then # Remove the public access + ynh_app_setting_delete $app skipped_uris fi -sudo chown -R $app:root $final_path/{conf,data,lib/plugins,lib/tpl} -sudo chmod -R 700 $final_path/conf -sudo chmod -R 700 $final_path/data -sudo chmod -R 755 $final_path/lib/plugins -sudo chmod 755 $final_path/lib/tpl/{dokuwiki,dokuwiki/images} - -# Modify Nginx configuration file and copy it to Nginx conf directory -sudo sed -i "s@__PATHTOCHANGE__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf -sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf -# sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf -sudo sed -i "s@fastcgi_pass unix:/var/run/php5-fpm.sock;@fastcgi_pass unix:/var/run/php5-fpm-${app}.sock;@g" /etc/nginx/conf.d/$domain.d/$app.conf - -if [ "$is_public" = "Yes" ]; +# Make app public if necessary +if [ $is_public -eq 1 ] then - sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf + # unprotected_uris allows SSO credentials to be passed anyway + ynh_app_setting_set $app unprotected_uris "/" fi -# Create the php-fpm pool config -POOL_FPM +#================================================= +# RELOAD NGINX +#================================================= -# Set ssowat config -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen - is_public=1 -else - ynh_app_setting_set $app is_public 0 - is_public=0 -fi - -sudo systemctl reload nginx -sudo yunohost app ssowatconf \ No newline at end of file +systemctl reload nginx diff --git a/sources/source_dir b/sources/source_dir deleted file mode 100644 index bc79cf4..0000000 --- a/sources/source_dir +++ /dev/null @@ -1 +0,0 @@ -dokuwiki-2017-02-19b \ No newline at end of file diff --git a/sources/source_md5 b/sources/source_md5 deleted file mode 100644 index c98aca2..0000000 --- a/sources/source_md5 +++ /dev/null @@ -1 +0,0 @@ -ea11e4046319710a2bc6fdf58b5cda86 dokuwiki-2017-02-19b.tgz \ No newline at end of file diff --git a/sources/source_url b/sources/source_url deleted file mode 100644 index 70951e8..0000000 --- a/sources/source_url +++ /dev/null @@ -1 +0,0 @@ -https://download.dokuwiki.org/src/dokuwiki/dokuwiki-2017-02-19b.tgz \ No newline at end of file