From 48580d3df0f7238708cef065a83e563d91b710a3 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 17 Feb 2019 14:46:43 +0100 Subject: [PATCH 01/20] Normalization from example_ynh --- README.md | 74 +++++++++++++++---- check_process | 2 +- conf/app.src | 2 + conf/nginx.conf | 11 ++- manifest.json | 9 ++- scripts/_common.sh | 51 ++++--------- scripts/backup | 19 ++--- scripts/install | 134 ++++++++++++++++------------------ scripts/remove | 15 ++-- scripts/restore | 47 +++++------- scripts/upgrade | 174 +++++++++++++++++++++------------------------ 11 files changed, 266 insertions(+), 272 deletions(-) diff --git a/README.md b/README.md index 597840f..0e7a7cf 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,69 @@ -opensondage_ynh -=============== +# OpenSondage for YunoHost -OpenSondage for YunoHost +[![Integration level](https://dash.yunohost.org/integration/opensondage.svg)](https://dash.yunohost.org/appci/app/opensondage) +[![Install OpenSondage with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=opensondage) -OpenSondage is used to poll people invite for a meeting. +> *This package allow you to install OpenSondage quickly and simply on a YunoHost server. +If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* -## Change done from original sources -This package contains a custom version of Framadate (fork of OpenSondage and Studs), the sources are here: https://git.framasoft.org/framasoft/framadate/. +## Overview -## Broken things +Framadate is an online service for planning an appointment or making a decision quickly and easily. It's a community free/libre software alternative to Doodle. - 1. There is no way to configure mail, either with smtp or with sendmail. See https://framagit.org/framasoft/framadate/merge_requests/184 - 2. There is no way to use SSOWAT to identify current user. See https://framagit.org/framasoft/framadate/issues/177 +**Shipped version:** 1.0.3 -## Screenshot +## Screenshots -Screen containing a meeting poll -Screen containing a vote poll to choose a restaurant +![](https://framadate.org/images/date.png) + +## Demo + +* [YunoHost demo](https://demo.yunohost.org/date/) +* [Official demo](https://framadate.org/) + +## Configuration + +## Documentation + + * Official documentation: https://framagit.org/framasoft/framadate/framadate/wikis/home + * YunoHost documentation: If specific documentation is needed, feel free to contribute. + +## YunoHost specific features + +#### Multi-users support + +#### Supported architectures + +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/opensondage%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/opensondage/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/opensondage%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/opensondage/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/opensondage%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/opensondage/) + +## Limitations + +* There is no way to configure mail, either with smtp or with sendmail. See https://framagit.org/framasoft/framadate/merge_requests/184 +* There is no way to use SSOWAT to identify current user. See https://framagit.org/framasoft/framadate/issues/177 + +## Additional information + +* This package contains a custom version of Framadate (fork of OpenSondage and Studs), the sources are here: https://git.framasoft.org/framasoft/framadate/. + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/opensondage_ynh/issues + * OpenSondage website: https://git.framasoft.org/framasoft/framadate/framadate + * YunoHost website: https://yunohost.org/ + +--- + +Developers info +---------------- + +**Only if you want to use a testing branch for coding, instead of merging directly into master.** +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/opensondage_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/opensondage_ynh/tree/testing --debug +or +sudo yunohost app upgrade opensondage -u https://github.com/YunoHost-Apps/opensondage_ynh/tree/testing --debug +``` diff --git a/check_process b/check_process index 563bd04..fb9e10c 100644 --- a/check_process +++ b/check_process @@ -1,5 +1,4 @@ ;; Test complet - auto_remove=1 ; Manifest domain="domain.tld" (DOMAIN) path="/path" (PATH) @@ -19,6 +18,7 @@ multi_instance=1 incorrect_path=1 port_already_use=0 + change_url=0 ;;; Levels Level 1=auto Level 2=auto diff --git a/conf/app.src b/conf/app.src index 9b3e0db..788ffd4 100644 --- a/conf/app.src +++ b/conf/app.src @@ -2,3 +2,5 @@ SOURCE_URL=https://git.framasoft.org/framasoft/framadate/framadate/repository/1. SOURCE_SUM=aa372ac8b7f0f7b0ad4ab973a5cfb7db5aa3b95a1ea584e3c57c8929d3766169 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.bz2 +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/nginx.conf b/conf/nginx.conf index 1c07aeb..7063aba 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,10 +1,14 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; - location __PATH__/ { + + # Path to source alias __FINALPATH__/; + + # Force usage of https if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } + index index.php; try_files $uri $uri/ /index.php; location ~ [^/]\.php(/|$) { @@ -16,8 +20,9 @@ location __PATH__/ { fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param HTTPS on; } - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } location ~ ^__PATH__/(data|config|\.ht|db_structure\.xml|README) { diff --git a/manifest.json b/manifest.json index 40cc0c4..0929b68 100644 --- a/manifest.json +++ b/manifest.json @@ -2,14 +2,14 @@ "name": "OpenSondage", "id": "opensondage", "packaging_format": 1, - "url": "https://git.framasoft.org/framasoft/framadate", - "version": "1.0.3", - "license": "CECILL-B", "description": { "en": "OpenSondage is an online service for planning an appointment or making a decision quickly and easily. No registration is required.", "fr": "OpenSondage sert à faire des sondages sans authentification pour trouver une date de réunion qui convienne à toutes les personnes concernées.", "de": "OpenSondage ist ein Online-Dienst, der Ihnen bei der Absprache von Terminen oder der Entscheidungsfindung hilft." }, + "version": "1.0.3~ynh1", + "url": "https://git.framasoft.org/framasoft/framadate", + "license": "CECILL-B", "maintainer": { "name": "ljf", "email": "ljf+yunohost@grimaud.me" @@ -58,6 +58,7 @@ }, { "name": "language", + "type": "string", "ask": { "en": "Choose the default language of this OpenSondage", "fr": "Choisissez la langue par défault d'OpenSondage", @@ -76,8 +77,6 @@ }, "default": true } - - ] } } diff --git a/scripts/_common.sh b/scripts/_common.sh index 54a038c..e5b02a2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,43 +1,18 @@ #!/bin/bash +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +# Execute a command as another user +# usage: exec_as USER COMMAND [ARG ...] exec_as() { - local USER=$1 - shift 1 + local USER=$1 + shift 1 - if [[ $USER = $(whoami) ]] - then - eval $@ - else - sudo -u "$USER" $@ - fi -} - -# Execute a composer command from a given directory -# usage: composer_exec AS_USER WORKDIR COMMAND [ARG ...] -exec_composer() { - local AS_USER=$1 - local WORKDIR=$2 - shift 2 - - exec_as "$AS_USER" COMPOSER_HOME="${WORKDIR}/.composer" \ - php "${WORKDIR}/composer.phar" $@ \ - -d "${WORKDIR}" --quiet --no-interaction -} - -# Install and initialize Composer in the given directory -# usage: init_composer destdir -init_composer() { - local AS_USER=$1 - local WORKDIR=$2 - - # install composer - curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="${WORKDIR}/.composer" \ - php -- --quiet --install-dir="$WORKDIR" \ - || ynh_die "Unable to install Composer" - - - # update dependencies to create composer.lock - exec_composer "$AS_USER" "$WORKDIR" install --no-dev \ - || ynh_die "Unable to update core dependencies with Composer" + if [[ $USER = $(whoami) ]]; then + eval "$@" + else + sudo -u "$USER" "$@" + fi } diff --git a/scripts/backup b/scripts/backup index a3efda0..f7090cb 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,12 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= @@ -25,12 +20,11 @@ ynh_abort_if_errors # LOAD SETTINGS #================================================= -# See comments in install script app=$YNH_APP_INSTANCE_NAME -db_name=$(ynh_app_setting_get "$app" db_name) -dbuser=$app -dbpass=$(ynh_app_setting_get "$app" mysqlpwd) -domain=$(ynh_app_setting_get "$app" domain) + +final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get $app domain) +db_name=$(ynh_app_setting_get $app db_name) #================================================= # STANDARD BACKUP STEPS @@ -38,8 +32,7 @@ domain=$(ynh_app_setting_get "$app" domain) # BACKUP THE APP MAIN DIR #================================================= -# Backup sources & data -ynh_backup "/var/www/$app" +ynh_backup "$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/install b/scripts/install index 0dee5b2..b51675f 100644 --- a/scripts/install +++ b/scripts/install @@ -20,15 +20,14 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -app=$YNH_APP_INSTANCE_NAME - -# Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN language=$YNH_APP_ARG_LANGUAGE is_public=$YNH_APP_ARG_IS_PUBLIC +app=$YNH_APP_INSTANCE_NAME + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -37,22 +36,20 @@ 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") +path_url=$(ynh_normalize_url_path $path_url) -# Check web path availability -ynh_webpath_available "$domain" "$path_url" # Register (book) web path -ynh_webpath_register "$app" "$domain" "$path_url" +ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set "$app" domain "$domain" -ynh_app_setting_set "$app" path_url "$path_url" -ynh_app_setting_set "$app" admin "$admin" -ynh_app_setting_set "$app" language "$language" -ynh_app_setting_set "$app" is_public "$is_public" +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 language $language +ynh_app_setting_set $app is_public $is_public #================================================= # STANDARD MODIFICATIONS @@ -60,25 +57,21 @@ ynh_app_setting_set "$app" is_public "$is_public" # INSTALL DEPENDENCIES #================================================= -ynh_install_app_dependencies php-fpdf +ynh_install_app_dependencies php-fpdf php-cli #================================================= # CREATE A MYSQL DATABASE #================================================= -# Generate MySQL password and create database -dbuser=$app -db_name=$app -dbpass=$(ynh_string_random 12) -ynh_app_setting_set "$app" mysqlpwd "$dbpass" -ynh_app_setting_set "$app" db_name "$db_name" -ynh_mysql_create_db "$db_name" "$dbuser" "$dbpass" +db_name=$(ynh_sanitize_dbid $app) +ynh_app_setting_set $app db_name $db_name +ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_app_setting_set "$app" final_path "$final_path" +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" @@ -86,15 +79,6 @@ ynh_setup_source "$final_path" # NGINX CONFIGURATION #================================================= -if [ "$path_url" == "/" ] -then - # ynh panel is only for non-root installs - ynh_replace_string " include conf.d/" " #include conf.d/" "../conf/nginx.conf" -else - # add rewrite for alias_traversal protection - ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" -fi - # Create a dedicated nginx config ynh_add_nginx_config @@ -103,7 +87,7 @@ ynh_add_nginx_config #================================================= # Create a system user -ynh_system_user_create "$app" +ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION @@ -115,78 +99,79 @@ ynh_add_fpm_config #================================================= # SPECIFIC SETUP #================================================= -# Create config.php +# CREATE CONFIG.PHP #================================================= config="$final_path/app/inc/config.php" -admin_mail=$(ynh_user_get_info "$admin" mail) + +admin_mail=$(ynh_user_get_info $admin mail) + cp ../conf/config.php "$config" # Change variables in configuration -ynh_replace_string "__DBUSER__" "$dbuser" "$config" -ynh_replace_string "__DBPWD__" "$dbpass" "$config" -ynh_replace_string "__DBNAME__" "$db_name" "$config" -ynh_replace_string "__ADMINMAIL__" "$admin_mail" "$config" -ynh_replace_string "__LANGUAGE__" "$language" "$config" -ynh_replace_string "__DOMAIN__" "$domain" "$config" -ynh_replace_string "__PATH__" "$path_url" "$config" - -#================================================= -# Replace logo image (default is FramaDate) -#================================================= - -cp ../img/logo.png "$final_path/images" - -#================================================= -# STORE THE CHECKSUM OF THE CONFIG FILE -#================================================= +ynh_replace_string "__DBUSER__" $db_name "$config" +ynh_replace_string "__DBPWD__" $db_pwd "$config" +ynh_replace_string "__DBNAME__" $db_name "$config" +ynh_replace_string "__ADMINMAIL__" $admin_mail "$config" +ynh_replace_string "__LANGUAGE__" $language "$config" +ynh_replace_string "__DOMAIN__" $domain "$config" +ynh_replace_string "__PATH__" $path_url "$config" # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$config" #================================================= -# Create log file +# REPLACE LOGO IMAGE (DEFAULT IS FRAMADATE) +#================================================= + +cp ../img/logo.png "$final_path/images" + +#================================================= +# CREATE LOG FILE #================================================= -# Create log file touch "$final_path/admin/stdout.log" +#================================================= +# RUN DATABASE INITILIZATION +#================================================= + +# Set permissions for initilization +chown -R $app: "$final_path" + +# Install composer +curl -sS https://getcomposer.org/installer \ + | COMPOSER_HOME="$final_path/.composer" \ + php -- --quiet --install-dir="$final_path" \ + || ynh_die "Unable to install Composer" + +# Update dependencies to create composer.lock +exec_as $app COMPOSER_HOME="$final_path/.composer" \ + php "$final_path/composer.phar" install --no-dev \ + -d "$final_path" --quiet --no-interaction \ + || ynh_die "Unable to update core dependencies with Composer" + +ynh_exec_warn_less exec_as $app php "$final_path/admin/migration.php" #================================================= # GENERIC FINALIZATION -#================================================= -# Run database initilization -#================================================= - -# Set initial permissions of initilization -chown -R "$app": "$final_path" - -init_composer "$app" "$final_path" - -sudo -u "$app" php "$final_path/admin/migration.php" - #================================================= # SECURE FILES AND DIRECTORIES #================================================= chown -R root: "$final_path" -chown -R "$app": "$final_path/tpl_c" -chown -R "$app": "$final_path/admin/stdout.log" +chown -R $app: "$final_path/"{tpl_c,admin/stdout.log} #================================================= # SETUP SSOWAT #================================================= -ynh_app_setting_set "$app" skipped_uris "/" - -if [ $is_public -eq 0 ]; +# Make app public if necessary +if [ $is_public -eq 1 ] then - ynh_app_setting_set "$app" protected_uris "/" -else - ynh_app_setting_set "$app" protected_uris "/admin" - ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf" - - ynh_store_file_checksum "$finalnginxconf" + ynh_app_setting_set $app skipped_uris "/" + # Keep /admin private + ynh_app_setting_set $app protected_uris "/admin" fi #================================================= @@ -194,3 +179,4 @@ fi #================================================= systemctl reload nginx + diff --git a/scripts/remove b/scripts/remove index f9d1c93..45e44d7 100644 --- a/scripts/remove +++ b/scripts/remove @@ -15,8 +15,9 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME -# Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) +domain=$(ynh_app_setting_get $app domain) +db_name=$(ynh_app_setting_get $app db_name) +final_path=$(ynh_app_setting_get $app final_path) #================================================= # STANDARD REMOVE @@ -32,15 +33,14 @@ ynh_remove_app_dependencies #================================================= # Remove a database if it exists, along with the associated user -db_name=$app -dbuser=$app -ynh_mysql_remove_db "$db_name" "$dbuser" +ynh_mysql_remove_db $db_name $db_name #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_secure_remove "/var/www/$app" +# Remove the app directory securely +ynh_secure_remove "$final_path" #================================================= # REMOVE NGINX CONFIGURATION @@ -63,4 +63,5 @@ ynh_remove_fpm_config #================================================= # Delete a system user -ynh_system_user_delete "$app" +ynh_system_user_delete $app + diff --git a/scripts/restore b/scripts/restore index 1d82ae8..0944350 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,12 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= @@ -29,22 +24,19 @@ ynh_abort_if_errors app=$YNH_APP_INSTANCE_NAME # Retrieve old app settings -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) -db_name=$(ynh_app_setting_get "$app" db_name) -dbuser=$app -final_path=$(ynh_app_setting_get "$app" final_path) +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +final_path=$(ynh_app_setting_get $app final_path) +db_name=$(ynh_app_setting_get $app db_name) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================ -ynh_webpath_available "$domain" "$path_url" \ +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" + || ynh_die "There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -61,19 +53,18 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file "$final_path" #================================================= -# CREATE DEDICATED USER +# RECREATE THE DEDICATED USER #================================================= -# Create a system user -ynh_system_user_create "$app" +# Create the dedicated user (if not existing) +ynh_system_user_create $app #================================================= # RESTORE USER RIGHTS #================================================= -# Set permissions -chown -R "$app": "$final_path/tpl_c" -chown -R "$app": "$final_path/admin/stdout.log" +# Restore permissions on app files +chown -R $app: "$final_path/"{tpl_c,admin/stdout.log} #================================================= # RESTORE THE PHP-FPM CONFIGURATION @@ -85,9 +76,9 @@ ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" # RESTORE THE MYSQL DATABASE #================================================= -db_pwd=$(ynh_app_setting_get "$app" mysqlpwd) -ynh_mysql_setup_db "$db_name" "$db_name" "$db_pwd" -ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql +db_pwd=$(ynh_app_setting_get $app mysqlpwd) +ynh_mysql_setup_db $db_name $db_name $db_pwd +ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql #================================================= # SPECIFIC RESTORATION @@ -95,7 +86,7 @@ ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql # REINSTALL DEPENDENCIES #================================================= -# Dependences +# Define and install dependencies ynh_install_app_dependencies php-fpdf #================================================= @@ -104,6 +95,6 @@ ynh_install_app_dependencies php-fpdf # RELOAD NGINX AND PHP-FPM #================================================= -# Reload Nginx -service php5-fpm restart -service nginx reload +systemctl reload php7.0-fpm +systemctl reload nginx + diff --git a/scripts/upgrade b/scripts/upgrade index ea6424c..5dfe127 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,28 +10,18 @@ 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 +# LOAD SETTINGS #================================================= app=$YNH_APP_INSTANCE_NAME -# Retrieve arguments -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) -db_name=$(ynh_app_setting_get "$app" db_name) -dbuser=$app -dbpass=$(ynh_app_setting_get "$app" mysqlpwd) -final_path=$(ynh_app_setting_get "$app" final_path) -language=$(ynh_app_setting_get "$app" language) +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) +language=$(ynh_app_setting_get $app language) +db_name=$(ynh_app_setting_get $app db_name) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -39,38 +29,46 @@ language=$(ynh_app_setting_get "$app" language) if [ -z "$is_public" ]; then - is_public=$(ynh_app_setting_get "$app" public_site) - ynh_app_setting_set "$app" is_public "$is_public" - ynh_app_setting_delete "$app" public_site + is_public=$(ynh_app_setting_get $app public_site) + ynh_app_setting_set $app is_public $is_public + ynh_app_setting_delete $app public_site fi # 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 is_public 1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set "$app" is_public 0 + ynh_app_setting_set $app is_public 0 is_public=0 fi # If db_name doesn't exist, create it -if [ -z "$db_name" ]; then - db_name=$(ynh_sanitize_dbid "$app") - ynh_app_setting_set "$app" db_name "$db_name" +if [ -z $db_name ]; then + db_name=$(ynh_sanitize_dbid $app) + ynh_app_setting_set $app db_name $db_name fi # If final_path doesn't exist, create it -if [ -z "$final_path" ]; then +if [ -z $final_path ]; then final_path=/var/www/$app - ynh_app_setting_set "$app" final_path "$final_path" + ynh_app_setting_set $app final_path $final_path fi -# make sure default language is set -if [ -z "$language" ]; +# Make sure default language is set +if [ -z "$language" ] then language=$(grep LANGUE "/var/www/$app/variables.php" | grep -Po "'.*?'" | cut -d"'" -f2) fi +# Use path instead of path_url in settings.yml... +if [ -z "$path_url" ] +then + path_url=$(ynh_app_setting_get $app path_url) + ynh_app_setting_set $app path $path_url + ynh_app_setting_delete $app path_url +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -89,10 +87,7 @@ ynh_abort_if_errors #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path "$path_url") - -# Check web path availability -ynh_webpath_available "$domain" "$path_url" +path_url=$(ynh_normalize_url_path $path_url) #================================================= # STANDARD UPGRADE STEPS @@ -107,24 +102,21 @@ ynh_setup_source "$final_path" # NGINX CONFIGURATION #================================================= -if [ "$path_url" == "/" ] -then - # ynh panel is only for non-root installs - ynh_replace_string " include conf.d/" " #include conf.d/" "../conf/nginx.conf" -else - # add rewrite for alias_traversal protection - ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" -fi - # Create a dedicated nginx config ynh_add_nginx_config +#================================================= +# UPGRADE DEPENDENCIES +#================================================= + +ynh_install_app_dependencies php-fpdf php-cli + #================================================= # CREATE DEDICATED USER #================================================= -# Create a system user -ynh_system_user_create "$app" +# Create a dedicated user (if not existing) +ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION @@ -136,85 +128,84 @@ ynh_add_fpm_config #================================================= # SPECIFIC UPGRADE #================================================= +# UPGRADE CONFIG.PHP +#================================================= -#================================================= -# STORE THE CHECKSUM OF THE CONFIG FILE -#================================================= config="$final_path/app/inc/config.php" + # Verify the checksum and backup the file if it's different ynh_backup_if_checksum_is_different "$config" -#================================================= -# Create config.php -#================================================= +admin_mail=$(ynh_user_get_info $admin mail) -admin_mail=$(ynh_user_get_info "$admin" mail) cp ../conf/config.php "$config" # Change variables in configuration -ynh_replace_string "__DBUSER__" "$dbuser" "$config" -ynh_replace_string "__DBPWD__" "$dbpass" "$config" -ynh_replace_string "__DBNAME__" "$db_name" "$config" -ynh_replace_string "__ADMINMAIL__" "$admin_mail" "$config" -ynh_replace_string "__LANGUAGE__" "$language" "$config" -ynh_replace_string "__DOMAIN__" "$domain" "$config" -ynh_replace_string "__PATH__" "$path_url" "$config" +ynh_replace_string "__DBUSER__" $db_name "$config" +db_pwd=$(ynh_app_setting_get $app mysqlpwd) +ynh_replace_string "__DBPWD__" $db_pwd "$config" +ynh_replace_string "__DBNAME__" $db_name "$config" +ynh_replace_string "__ADMINMAIL__" $admin_mail "$config" +ynh_replace_string "__LANGUAGE__" $language "$config" +ynh_replace_string "__DOMAIN__" $domain "$config" +ynh_replace_string "__PATH__" $path_url "$config" + +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum "$config" #================================================= -# Replace logo image (default is FramaDate) +# REPLACE LOGO IMAGE (DEFAULT IS FRAMADATE) #================================================= cp ../img/logo.png "$final_path/images" #================================================= -# STORE THE CHECKSUM OF THE CONFIG FILE +# CREATE LOG FILE #================================================= -# Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum "$config" - -#================================================= -# Create log file -#================================================= - -# Create log file touch "$final_path/admin/stdout.log" +#================================================= +# RUN DATABASE UPGRADE +#================================================= +#================================================= + +# Set permissions for initilization +chown -R $app: "$final_path" + +# Install composer +curl -sS https://getcomposer.org/installer \ + | COMPOSER_HOME="$final_path/.composer" \ + php -- --quiet --install-dir="$final_path" \ + || ynh_die "Unable to install Composer" + +# Update dependencies to create composer.lock +exec_as $app COMPOSER_HOME="$final_path/.composer" \ + php "$final_path/composer.phar" install --no-dev \ + -d "$final_path" --quiet --no-interaction \ + || ynh_die "Unable to update core dependencies with Composer" + +ynh_exec_warn_less exec_as $app php "$final_path/admin/migration.php" + #================================================= # GENERIC FINALIZATION -#================================================= -# Run database initilization -#================================================= - -# Set initial permissions for initilization -chown -R "$app": "$final_path" - -init_composer "$app" "$final_path" - -sudo -u "$app" php "$final_path/admin/migration.php" - #================================================= # SECURE FILES AND DIRECTORIES #================================================= chown -R root: "$final_path" -chown -R "$app": "$final_path/tpl_c" -chown -R "$app": "$final_path/admin/stdout.log" +chown -R $app: "$final_path/"{tpl_c,admin/stdout.log} #================================================= # SETUP SSOWAT #================================================= -ynh_app_setting_set "$app" skipped_uris "/" - -if [ $is_public -eq 0 ]; +# Make app public if necessary +if [ $is_public -eq 1 ] then - ynh_app_setting_set "$app" protected_uris "/" -else - ynh_app_setting_set "$app" protected_uris "/admin" - ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf" - - ynh_store_file_checksum "$finalnginxconf" + ynh_app_setting_set $app skipped_uris "/" + # Keep /admin private + ynh_app_setting_set $app protected_uris "/admin" fi #================================================= @@ -222,3 +213,4 @@ fi #================================================= systemctl reload nginx + From e438f6b8b0364c942512cbf9f44fffa9fdbde69c Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 17 Feb 2019 14:47:55 +0100 Subject: [PATCH 02/20] Use php7 --- conf/nginx.conf | 2 +- conf/php-fpm.conf | 315 +++++++++++++++++++++++++++++++++++++--------- manifest.json | 4 +- scripts/backup | 2 +- scripts/restore | 2 +- 5 files changed, 258 insertions(+), 67 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 7063aba..1950475 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -13,7 +13,7 @@ location __PATH__/ { try_files $uri $uri/ /index.php; location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; + fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; include fastcgi_params; fastcgi_param REMOTE_USER $remote_user; fastcgi_param PATH_INFO $fastcgi_path_info; diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index 8ef1ddb..ade62e3 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -1,10 +1,11 @@ ; Start a new pool named 'www'. -; the variable $pool can we used in any directive and will be replaced by the +; the variable $pool can be used in any directive and will be replaced by the ; pool name ('www' here) [__NAMETOCHANGE__] ; Per pool prefix ; It only applies on the following directives: +; - 'access.log' ; - 'slowlog' ; - 'listen' (unixsocket) ; - 'chroot' @@ -16,21 +17,43 @@ ; Default Value: none ;prefix = /path/to/pools/$pool +; Unix user/group of processes +; Note: The user is mandatory. If the group is not set, the default user's group +; will be used. +user = __USER__ +group = __USER__ + ; The address on which to accept FastCGI requests. ; Valid syntaxes are: -; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on +; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on ; a specific port; -; 'port' - to listen on a TCP socket to all addresses on a -; specific port; +; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on +; a specific port; +; 'port' - to listen on a TCP socket to all addresses +; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock +listen = /var/run/php/php7.0-fpm-__NAMETOCHANGE__.sock -; Set listen(2) backlog. A value of '-1' means unlimited. -; Default Value: 128 (-1 on FreeBSD and OpenBSD) -;listen.backlog = -1 +; Set listen(2) backlog. +; Default Value: 511 (-1 on FreeBSD and OpenBSD) +;listen.backlog = 511 -; List of ipv4 addresses of FastCGI clients which are allowed to connect. +; Set permissions for unix socket, if one is used. In Linux, read/write +; permissions must be set in order to allow connections from a web server. Many +; BSD-derived systems allow connections regardless of permissions. +; Default Values: user and group are set as the running user +; mode is set to 0660 +listen.owner = www-data +listen.group = www-data +;listen.mode = 0660 +; When POSIX Access Control Lists are supported you can set them using +; these options, value is a comma separated list of user/group names. +; When set, listen.owner and listen.group are ignored +;listen.acl_users = +;listen.acl_groups = + +; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect. ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address ; must be separated by a comma. If this value is left blank, connections will be @@ -38,26 +61,26 @@ listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock ; Default Value: any ;listen.allowed_clients = 127.0.0.1 -; Set permissions for unix socket, if one is used. In Linux, read/write -; permissions must be set in order to allow connections from a web server. Many -; BSD-derived systems allow connections regardless of permissions. -; Default Values: user and group are set as the running user -; mode is set to 0666 -listen.owner = www-data -listen.group = www-data -listen.mode = 0600 +; Specify the nice(2) priority to apply to the pool processes (only if set) +; The value can vary from -19 (highest priority) to 20 (lower priority) +; Note: - It will only work if the FPM master process is launched as root +; - The pool processes will inherit the master process priority +; unless it specified otherwise +; Default Value: no set +; process.priority = -19 -; Unix user/group of processes -; Note: The user is mandatory. If the group is not set, the default user's group -; will be used. -user = __USER__ -group = __USER__ +; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user +; or group is differrent than the master process user. It allows to create process +; core dump and ptrace the process for the pool user. +; Default Value: no +; process.dumpable = yes ; Choose how the process manager will control the number of child processes. ; Possible Values: ; static - a fixed number (pm.max_children) of child processes; ; dynamic - the number of child processes are set dynamically based on the -; following directives: +; following directives. With this process management, there will be +; always at least 1 children. ; pm.max_children - the maximum number of children that can ; be alive at the same time. ; pm.start_servers - the number of children created on startup. @@ -69,73 +92,150 @@ group = __USER__ ; state (waiting to process). If the number ; of 'idle' processes is greater than this ; number then some children will be killed. +; ondemand - no children are created at startup. Children will be forked when +; new requests will connect. The following parameter are used: +; pm.max_children - the maximum number of children that +; can be alive at the same time. +; pm.process_idle_timeout - The number of seconds after which +; an idle process will be killed. ; Note: This value is mandatory. pm = dynamic ; The number of child processes to be created when pm is set to 'static' and the -; maximum number of child processes to be created when pm is set to 'dynamic'. +; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. ; This value sets the limit on the number of simultaneous requests that will be ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP -; CGI. -; Note: Used when pm is set to either 'static' or 'dynamic' +; CGI. The below defaults are based on a server without much resources. Don't +; forget to tweak pm.* to fit your needs. +; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' ; Note: This value is mandatory. -pm.max_children = 6 +pm.max_children = 5 ; The number of child processes created on startup. ; Note: Used only when pm is set to 'dynamic' ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 -pm.start_servers = 3 +pm.start_servers = 2 ; The desired minimum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = 3 +pm.min_spare_servers = 1 ; The desired maximum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = 5 +pm.max_spare_servers = 3 + +; The number of seconds after which an idle process will be killed. +; Note: Used only when pm is set to 'ondemand' +; Default Value: 10s +;pm.process_idle_timeout = 10s; ; The number of requests each child process should execute before respawning. ; This can be useful to work around memory leaks in 3rd party libraries. For ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. ; Default Value: 0 -pm.max_requests = 500 +;pm.max_requests = 500 ; The URI to view the FPM status page. If this value is not set, no URI will be -; recognized as a status page. By default, the status page shows the following -; information: -; accepted conn - the number of request accepted by the pool; +; recognized as a status page. It shows the following informations: ; pool - the name of the pool; -; process manager - static or dynamic; +; process manager - static, dynamic or ondemand; +; start time - the date and time FPM has started; +; start since - number of seconds since FPM has started; +; accepted conn - the number of request accepted by the pool; +; listen queue - the number of request in the queue of pending +; connections (see backlog in listen(2)); +; max listen queue - the maximum number of requests in the queue +; of pending connections since FPM has started; +; listen queue len - the size of the socket queue of pending connections; ; idle processes - the number of idle processes; ; active processes - the number of active processes; -; total processes - the number of idle + active processes. +; total processes - the number of idle + active processes; +; max active processes - the maximum number of active processes since FPM +; has started; ; max children reached - number of times, the process limit has been reached, ; when pm tries to start more children (works only for -; pm 'dynamic') -; The values of 'idle processes', 'active processes' and 'total processes' are -; updated each second. The value of 'accepted conn' is updated in real time. +; pm 'dynamic' and 'ondemand'); +; Value are updated in real time. ; Example output: -; accepted conn: 12073 ; pool: www ; process manager: static -; idle processes: 35 -; active processes: 65 -; total processes: 100 -; max children reached: 1 +; start time: 01/Jul/2011:17:53:49 +0200 +; start since: 62636 +; accepted conn: 190460 +; listen queue: 0 +; max listen queue: 1 +; listen queue len: 42 +; idle processes: 4 +; active processes: 11 +; total processes: 15 +; max active processes: 12 +; max children reached: 0 +; ; By default the status page output is formatted as text/plain. Passing either -; 'html' or 'json' as a query string will return the corresponding output -; syntax. Example: +; 'html', 'xml' or 'json' in the query string will return the corresponding +; output syntax. Example: ; http://www.foo.bar/status ; http://www.foo.bar/status?json ; http://www.foo.bar/status?html +; http://www.foo.bar/status?xml +; +; By default the status page only outputs short status. Passing 'full' in the +; query string will also return status for each pool process. +; Example: +; http://www.foo.bar/status?full +; http://www.foo.bar/status?json&full +; http://www.foo.bar/status?html&full +; http://www.foo.bar/status?xml&full +; The Full status returns for each process: +; pid - the PID of the process; +; state - the state of the process (Idle, Running, ...); +; start time - the date and time the process has started; +; start since - the number of seconds since the process has started; +; requests - the number of requests the process has served; +; request duration - the duration in µs of the requests; +; request method - the request method (GET, POST, ...); +; request URI - the request URI with the query string; +; content length - the content length of the request (only with POST); +; user - the user (PHP_AUTH_USER) (or '-' if not set); +; script - the main script called (or '-' if not set); +; last request cpu - the %cpu the last request consumed +; it's always 0 if the process is not in Idle state +; because CPU calculation is done when the request +; processing has terminated; +; last request memory - the max amount of memory the last request consumed +; it's always 0 if the process is not in Idle state +; because memory calculation is done when the request +; processing has terminated; +; If the process is in Idle state, then informations are related to the +; last request the process has served. Otherwise informations are related to +; the current request being served. +; Example output: +; ************************ +; pid: 31330 +; state: Running +; start time: 01/Jul/2011:17:53:49 +0200 +; start since: 63087 +; requests: 12808 +; request duration: 1250261 +; request method: GET +; request URI: /test_mem.php?N=10000 +; content length: 0 +; user: - +; script: /home/fat/web/docs/php/test_mem.php +; last request cpu: 0.00 +; last request memory: 0 +; +; Note: There is a real-time FPM status monitoring sample web page available +; It's available in: /usr/share/php/7.0/fpm/status.html +; ; Note: The value must start with a leading slash (/). The value can be ; anything, but it may not be a good idea to use the .php extension or it ; may conflict with a real PHP file. ; Default Value: not set -; pm.status_path = /fpm-status +;pm.status_path = /status ; The ping URI to call the monitoring page of FPM. If this value is not set, no ; URI will be recognized as a ping page. This could be used to test from outside @@ -147,39 +247,102 @@ pm.max_requests = 500 ; anything, but it may not be a good idea to use the .php extension or it ; may conflict with a real PHP file. ; Default Value: not set -; ping.path = /ping +;ping.path = /ping ; This directive may be used to customize the response of a ping request. The ; response is formatted as text/plain with a 200 response code. ; Default Value: pong ;ping.response = pong -; The timeout for serving a single request after which the worker process will -; be killed. This option should be used when the 'max_execution_time' ini option -; does not stop script execution for some reason. A value of '0' means 'off'. -; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) -; Default Value: 0 -request_terminate_timeout = 120s +; The access log file +; Default: not set +;access.log = log/$pool.access.log + +; The access log format. +; The following syntax is allowed +; %%: the '%' character +; %C: %CPU used by the request +; it can accept the following format: +; - %{user}C for user CPU only +; - %{system}C for system CPU only +; - %{total}C for user + system CPU (default) +; %d: time taken to serve the request +; it can accept the following format: +; - %{seconds}d (default) +; - %{miliseconds}d +; - %{mili}d +; - %{microseconds}d +; - %{micro}d +; %e: an environment variable (same as $_ENV or $_SERVER) +; it must be associated with embraces to specify the name of the env +; variable. Some exemples: +; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e +; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e +; %f: script filename +; %l: content-length of the request (for POST request only) +; %m: request method +; %M: peak of memory allocated by PHP +; it can accept the following format: +; - %{bytes}M (default) +; - %{kilobytes}M +; - %{kilo}M +; - %{megabytes}M +; - %{mega}M +; %n: pool name +; %o: output header +; it must be associated with embraces to specify the name of the header: +; - %{Content-Type}o +; - %{X-Powered-By}o +; - %{Transfert-Encoding}o +; - .... +; %p: PID of the child that serviced the request +; %P: PID of the parent of the child that serviced the request +; %q: the query string +; %Q: the '?' character if query string exists +; %r: the request URI (without the query string, see %q and %Q) +; %R: remote IP address +; %s: status (response code) +; %t: server time the request was received +; it can accept a strftime(3) format: +; %d/%b/%Y:%H:%M:%S %z (default) +; The strftime(3) format must be encapsuled in a %{}t tag +; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t +; %T: time the log has been written (the request has finished) +; it can accept a strftime(3) format: +; %d/%b/%Y:%H:%M:%S %z (default) +; The strftime(3) format must be encapsuled in a %{}t tag +; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t +; %u: remote user +; +; Default: "%R - %u %t \"%m %r\" %s" +;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" + +; The log file for slow requests +; Default Value: not set +; Note: slowlog is mandatory if request_slowlog_timeout is set +;slowlog = log/$pool.log.slow ; The timeout for serving a single request after which a PHP backtrace will be ; dumped to the 'slowlog' file. A value of '0s' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 -request_slowlog_timeout = 5s +;request_slowlog_timeout = 0 -; The log file for slow requests -; Default Value: not set -; Note: slowlog is mandatory if request_slowlog_timeout is set -slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log +; The timeout for serving a single request after which the worker process will +; be killed. This option should be used when the 'max_execution_time' ini option +; does not stop script execution for some reason. A value of '0' means 'off'. +; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) +; Default Value: 0 +request_terminate_timeout = 1d ; Set open file descriptor rlimit. ; Default Value: system defined value -rlimit_files = 4096 +;rlimit_files = 1024 ; Set max core size rlimit. ; Possible Values: 'unlimited' or an integer greater or equal to 0 ; Default Value: system defined value -rlimit_core = 0 +;rlimit_core = 0 ; Chroot to this directory at the start. This value must be defined as an ; absolute path. When this value is not set, chroot is not used. @@ -202,7 +365,24 @@ chdir = __FINALPATH__ ; Note: on highloaded environement, this can cause some delay in the page ; process time (several ms). ; Default Value: no -catch_workers_output = yes +;catch_workers_output = yes + +; Clear environment in FPM workers +; Prevents arbitrary environment variables from reaching FPM worker processes +; by clearing the environment in workers before env vars specified in this +; pool configuration are added. +; Setting to "no" will make all environment variables available to PHP code +; via getenv(), $_ENV and $_SERVER. +; Default Value: yes +;clear_env = no + +; Limits the extensions of the main script FPM will allow to parse. This can +; prevent configuration mistakes on the web server side. You should only limit +; FPM to .php extensions to prevent malicious users to use other extensions to +; execute php code. +; Note: set an empty value to allow all extensions. +; Default Value: .php +;security.limit_extensions = .php .php3 .php4 .php5 .php7 ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from ; the current environment. @@ -238,5 +418,16 @@ catch_workers_output = yes ;php_admin_flag[log_errors] = on ;php_admin_value[memory_limit] = 32M +; Common values to change to increase file upload limit +; php_admin_value[upload_max_filesize] = 50M +; php_admin_value[post_max_size] = 50M +; php_admin_flag[mail.add_x_header] = Off + +; Other common parameters +; php_admin_value[max_execution_time] = 600 +; php_admin_value[max_input_time] = 300 +; php_admin_value[memory_limit] = 256M +; php_admin_flag[short_open_tag] = On + php_admin_value[upload_max_filesize] = 10G php_admin_value[post_max_size] = 10G diff --git a/manifest.json b/manifest.json index 0929b68..890b1e1 100644 --- a/manifest.json +++ b/manifest.json @@ -15,12 +15,12 @@ "email": "ljf+yunohost@grimaud.me" }, "requirements": { - "yunohost": ">= 2.7" + "yunohost": ">= 3.0" }, "multi_instance": true, "services": [ "nginx", - "php5-fpm", + "php7.0-fpm", "mysql" ], "arguments": { diff --git a/scripts/backup b/scripts/backup index f7090cb..0ddd5b0 100644 --- a/scripts/backup +++ b/scripts/backup @@ -44,7 +44,7 @@ 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/php/7.0/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE diff --git a/scripts/restore b/scripts/restore index 0944350..6145a14 100644 --- a/scripts/restore +++ b/scripts/restore @@ -70,7 +70,7 @@ chown -R $app: "$final_path/"{tpl_c,admin/stdout.log} # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" +ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # RESTORE THE MYSQL DATABASE From e61d152f8790f0d2f875d8a679adee95e32d14a1 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 17 Feb 2019 20:57:54 +0100 Subject: [PATCH 03/20] Add progression with ynh_print_info --- scripts/backup | 11 +++++++++++ scripts/install | 19 ++++++++++++++++++- scripts/remove | 12 ++++++++++++ scripts/restore | 12 ++++++++++++ scripts/upgrade | 17 ++++++++++++++++- 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/scripts/backup b/scripts/backup index 0ddd5b0..271844f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -31,23 +32,33 @@ db_name=$(ynh_app_setting_get $app db_name) #================================================= # BACKUP THE APP MAIN DIR #================================================= +ynh_print_info "Backing up the main app directory..." ynh_backup "$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= +ynh_print_info "Backing up nginx web server configuration..." ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Backing up php-fpm configuration..." ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= +ynh_print_info "Backing up the MySQL database..." ynh_mysql_dump_db "$db_name" > db.sql + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index b51675f..3e26d0c 100644 --- a/scripts/install +++ b/scripts/install @@ -31,6 +31,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_print_info "Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -44,6 +45,7 @@ ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_print_info "Storing installation settings..." ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url @@ -56,12 +58,14 @@ ynh_app_setting_set $app is_public $is_public #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_print_info "Installing dependencies..." ynh_install_app_dependencies php-fpdf php-cli #================================================= # CREATE A MYSQL DATABASE #================================================= +ynh_print_info "Creating a MySQL database..." db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name @@ -70,6 +74,7 @@ ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_print_info "Setting up source files..." ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src @@ -78,6 +83,7 @@ ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config @@ -85,6 +91,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Configuring system user..." # Create a system user ynh_system_user_create $app @@ -92,6 +99,7 @@ ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Configuring php-fpm..." # Create a dedicated php-fpm config ynh_add_fpm_config @@ -101,6 +109,7 @@ ynh_add_fpm_config #================================================= # CREATE CONFIG.PHP #================================================= +ynh_print_info "Configuring opensondage..." config="$final_path/app/inc/config.php" @@ -135,8 +144,9 @@ touch "$final_path/admin/stdout.log" #================================================= # RUN DATABASE INITILIZATION #================================================= +ynh_print_info "Initializing database..." -# Set permissions for initilization +# Set permissions for initialization chown -R $app: "$final_path" # Install composer @@ -165,6 +175,7 @@ chown -R $app: "$final_path/"{tpl_c,admin/stdout.log} #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -177,6 +188,12 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_print_info "Reloading nginx web server..." systemctl reload nginx +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 45e44d7..94679f2 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -24,6 +25,7 @@ final_path=$(ynh_app_setting_get $app final_path) #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_print_info "Removing dependencies" # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -31,6 +33,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE THE MYSQL DATABASE #================================================= +ynh_print_info "Removing the MySQL database" # Remove a database if it exists, along with the associated user ynh_mysql_remove_db $db_name $db_name @@ -38,6 +41,7 @@ ynh_mysql_remove_db $db_name $db_name #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_print_info "Removing app main directory" # Remove the app directory securely ynh_secure_remove "$final_path" @@ -45,6 +49,7 @@ ynh_secure_remove "$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_print_info "Removing nginx web server configuration" # Remove the dedicated nginx config ynh_remove_nginx_config @@ -52,6 +57,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Removing php-fpm configuration" # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -61,7 +67,13 @@ ynh_remove_fpm_config #================================================= # REMOVE DEDICATED USER #================================================= +ynh_print_info "Removing the dedicated system user" # Delete a system user ynh_system_user_delete $app +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 6145a14..b31e13e 100644 --- a/scripts/restore +++ b/scripts/restore @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading settings..." # See comments in install script app=$YNH_APP_INSTANCE_NAME @@ -32,6 +33,7 @@ db_name=$(ynh_app_setting_get $app db_name) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================ +ynh_print_info "Validating restoration parameters..." ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" @@ -49,12 +51,14 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= +ynh_print_info "Restoring the app main directory..." ynh_restore_file "$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_print_info "Recreating the dedicated system user..." # Create the dedicated user (if not existing) ynh_system_user_create $app @@ -75,6 +79,7 @@ ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # RESTORE THE MYSQL DATABASE #================================================= +ynh_print_info "Restoring the MySQL database..." db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_mysql_setup_db $db_name $db_name $db_pwd @@ -85,6 +90,7 @@ ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_print_info "Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies php-fpdf @@ -94,7 +100,13 @@ ynh_install_app_dependencies php-fpdf #================================================= # RELOAD NGINX AND PHP-FPM #================================================= +ynh_print_info "Reloading nginx web server and php-fpm..." systemctl reload php7.0-fpm systemctl reload nginx +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 5dfe127..030ec26 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -26,6 +27,7 @@ db_name=$(ynh_app_setting_get $app db_name) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_print_info "Ensuring downward compatibility..." if [ -z "$is_public" ]; then @@ -72,6 +74,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_print_info "Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -94,6 +97,7 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # 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" @@ -101,6 +105,7 @@ ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config @@ -108,12 +113,14 @@ ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= +ynh_print_info "Upgrading dependencies..." ynh_install_app_dependencies php-fpdf php-cli #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Making sure dedicated system user exists..." # Create a dedicated user (if not existing) ynh_system_user_create $app @@ -130,6 +137,7 @@ ynh_add_fpm_config #================================================= # UPGRADE CONFIG.PHP #================================================= +ynh_print_info "Reconfiguring opensondage..." config="$final_path/app/inc/config.php" @@ -168,7 +176,7 @@ touch "$final_path/admin/stdout.log" #================================================= # RUN DATABASE UPGRADE #================================================= -#================================================= +ynh_print_info "Upgrading database..." # Set permissions for initilization chown -R $app: "$final_path" @@ -199,6 +207,7 @@ chown -R $app: "$final_path/"{tpl_c,admin/stdout.log} #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Upgrading SSOwat configuration..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -211,6 +220,12 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_print_info "Reloading nginx web server..." systemctl reload nginx +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Upgrade of $app completed" From 79bde0a6980405dc52f21239e23702961dc16505 Mon Sep 17 00:00:00 2001 From: ljf Date: Sun, 11 Nov 2018 00:41:45 +0100 Subject: [PATCH 04/20] [enh] Remove me from maintainer --- manifest.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 40cc0c4..3a6d85b 100644 --- a/manifest.json +++ b/manifest.json @@ -11,9 +11,13 @@ "de": "OpenSondage ist ein Online-Dienst, der Ihnen bei der Absprache von Terminen oder der Entscheidungsfindung hilft." }, "maintainer": { - "name": "ljf", - "email": "ljf+yunohost@grimaud.me" + "name": "YunoHost Contributors", + "email": "apps@yunohost.org" }, + "previous_maintainers": [{ + "name": "ljf", + "email": "ljf+opensondage_ynh@grimaud.me" + }], "requirements": { "yunohost": ">= 2.7" }, From c810a91b482f77b92cffa588354cd24967c8233d Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 28 Feb 2019 00:01:26 +0100 Subject: [PATCH 05/20] Use composer helpers --- scripts/_common.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ scripts/install | 16 ++-------------- scripts/upgrade | 16 ++-------------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index e5b02a2..54f3ad5 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,3 +16,46 @@ exec_as() { sudo -u "$USER" "$@" fi } + +# Execute a command with Composer +# +# usage: ynh_composer_exec [--workdir=$final_path] --commands="commands" +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +# | arg: -c, --commands - Commands to execute. +ynh_composer_exec () { + # Declare an array to define the options of this helper. + local legacy_args=wc + declare -Ar args_array=( [w]=workdir= [c]=commands= ) + local workdir + local commands + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + + COMPOSER_HOME="$workdir/.composer" \ + php "$workdir/composer.phar" $commands \ + -d "$workdir" --quiet --no-interaction +} + +# Install and initialize Composer in the given directory +# +# usage: ynh_install_composer [--workdir=$final_path] +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +ynh_install_composer () { + # Declare an array to define the options of this helper. + local legacy_args=w + declare -Ar args_array=( [w]=workdir= ) + local workdir + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + + curl -sS https://getcomposer.org/installer \ + | COMPOSER_HOME="$workdir/.composer" \ + php -- --quiet --install-dir="$workdir" \ + || ynh_die "Unable to install Composer." + + # update dependencies to create composer.lock + ynh_composer_exec --workdir="$workdir" --commands="install --no-dev" \ + || ynh_die "Unable to update core dependencies with Composer." +} diff --git a/scripts/install b/scripts/install index 3e26d0c..084ec89 100644 --- a/scripts/install +++ b/scripts/install @@ -146,22 +146,10 @@ touch "$final_path/admin/stdout.log" #================================================= ynh_print_info "Initializing database..." -# Set permissions for initialization -chown -R $app: "$final_path" - # Install composer -curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="$final_path/.composer" \ - php -- --quiet --install-dir="$final_path" \ - || ynh_die "Unable to install Composer" +ynh_install_composer -# Update dependencies to create composer.lock -exec_as $app COMPOSER_HOME="$final_path/.composer" \ - php "$final_path/composer.phar" install --no-dev \ - -d "$final_path" --quiet --no-interaction \ - || ynh_die "Unable to update core dependencies with Composer" - -ynh_exec_warn_less exec_as $app php "$final_path/admin/migration.php" +ynh_exec_warn_less php "$final_path/admin/migration.php" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 030ec26..331e3e8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -178,22 +178,10 @@ touch "$final_path/admin/stdout.log" #================================================= ynh_print_info "Upgrading database..." -# Set permissions for initilization -chown -R $app: "$final_path" - # Install composer -curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="$final_path/.composer" \ - php -- --quiet --install-dir="$final_path" \ - || ynh_die "Unable to install Composer" +ynh_install_composer -# Update dependencies to create composer.lock -exec_as $app COMPOSER_HOME="$final_path/.composer" \ - php "$final_path/composer.phar" install --no-dev \ - -d "$final_path" --quiet --no-interaction \ - || ynh_die "Unable to update core dependencies with Composer" - -ynh_exec_warn_less exec_as $app php "$final_path/admin/migration.php" +ynh_exec_warn_less php "$final_path/admin/migration.php" #================================================= # GENERIC FINALIZATION From 2f54c3f32bcb1245cd05b24e4965c2d70d18ee18 Mon Sep 17 00:00:00 2001 From: Kayou Date: Fri, 1 Mar 2019 12:16:59 +0100 Subject: [PATCH 06/20] Acces to "adminstuds.php" when app is in public --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 0dee5b2..66a55ed 100644 --- a/scripts/install +++ b/scripts/install @@ -183,7 +183,7 @@ if [ $is_public -eq 0 ]; then ynh_app_setting_set "$app" protected_uris "/" else - ynh_app_setting_set "$app" protected_uris "/admin" + ynh_app_setting_set "$app" protected_regex "/admin/" ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf" ynh_store_file_checksum "$finalnginxconf" From ec53481d68138d8d6867f4ae8609fa782e58e72d Mon Sep 17 00:00:00 2001 From: Kayou Date: Fri, 1 Mar 2019 12:19:33 +0100 Subject: [PATCH 07/20] Acces to "adminstuds.php" when app is in public --- scripts/upgrade | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index ea6424c..9eed528 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -211,7 +211,9 @@ if [ $is_public -eq 0 ]; then ynh_app_setting_set "$app" protected_uris "/" else - ynh_app_setting_set "$app" protected_uris "/admin" + ynh_app_setting_delete "$app" protected_uris + ynh_app_setting_set "$app" protected_regex "/admin/" + ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf" ynh_store_file_checksum "$finalnginxconf" From 4f3b5909877d048c975f357abfcb9a1eb6b11b77 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 24 Mar 2019 16:46:32 +0100 Subject: [PATCH 08/20] Update pull_request_template.md --- pull_request_template.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pull_request_template.md b/pull_request_template.md index cac1ac7..ed358ef 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -19,7 +19,6 @@ - [ ] **Approval (LGTM)** : - [ ] **Approval (LGTM)** : - **CI succeeded** : -[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/opensondage_ynh%20-BRANCH-%20(Official)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/opensondage_ynh%20-BRANCH-%20(Official)/) *Please replace '-BRANCH-' in this link for a PR from a local branch.* -or -[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/opensondage_ynh%20PR-NUM-%20(Official_fork)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/opensondage_ynh%20PR-NUM-%20(Official_fork)/) *Replace '-NUM-' by the PR number in this link for a PR from a forked repository.* +[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/opensondage_ynh%20PR-NUM-/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/opensondage_ynh%20PR-NUM-/) +*Please replace '-NUM-' in this link by the PR number.* When the PR is marked as ready to merge, you have to wait for 3 days before really merging it. From 26784dddbb9d57051a30de8a1437d09afc692929 Mon Sep 17 00:00:00 2001 From: Kayou Date: Wed, 27 Mar 2019 23:07:41 +0100 Subject: [PATCH 09/20] Bump version --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 890b1e1..a5ae07b 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "email": "ljf+yunohost@grimaud.me" }, "requirements": { - "yunohost": ">= 3.0" + "yunohost": ">= 3.2" }, "multi_instance": true, "services": [ From 5d3d2ff67d8724e316d0e8f27c5dfa7949df4720 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 28 Mar 2019 15:37:23 +0100 Subject: [PATCH 10/20] Fix the regex --- scripts/install | 10 +++++++++- scripts/upgrade | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 66a55ed..dd75135 100644 --- a/scripts/install +++ b/scripts/install @@ -183,7 +183,15 @@ if [ $is_public -eq 0 ]; then ynh_app_setting_set "$app" protected_uris "/" else - ynh_app_setting_set "$app" protected_regex "/admin/" + # If the app is private, viewing images stays publicly accessible. + if [ "$path_url" == "/" ]; then + # If the path is /, clear it to prevent any error with the regex. + path_url="" + fi + # Modify the domain to be used in a regex + domain_regex=$(echo "$domain" | sed 's@-@.@g') + ynh_app_setting_set $app protected_regex "$domain_regex$path_url/admin/" + ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf" ynh_store_file_checksum "$finalnginxconf" diff --git a/scripts/upgrade b/scripts/upgrade index 9eed528..2889cf0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -212,7 +212,15 @@ then ynh_app_setting_set "$app" protected_uris "/" else ynh_app_setting_delete "$app" protected_uris - ynh_app_setting_set "$app" protected_regex "/admin/" + + # If the app is private, viewing images stays publicly accessible. + if [ "$path_url" == "/" ]; then + # If the path is /, clear it to prevent any error with the regex. + path_url="" + fi + # Modify the domain to be used in a regex + domain_regex=$(echo "$domain" | sed 's@-@.@g') + ynh_app_setting_set $app protected_regex "$domain_regex$path_url/admin/" ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf" From 3a00d2815bcfc680d1ee53716a5812e14654ca37 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Mon, 15 Apr 2019 20:55:38 +0200 Subject: [PATCH 11/20] Move from ci-apps-dev to ci-apps-hq --- pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pull_request_template.md b/pull_request_template.md index ed358ef..28b67d1 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -19,6 +19,6 @@ - [ ] **Approval (LGTM)** : - [ ] **Approval (LGTM)** : - **CI succeeded** : -[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/opensondage_ynh%20PR-NUM-/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/opensondage_ynh%20PR-NUM-/) +[![Build Status](https://ci-apps-hq.yunohost.org/jenkins/job/opensondage_ynh%20PR-NUM-/badge/icon)](https://ci-apps-hq.yunohost.org/jenkins/job/opensondage_ynh%20PR-NUM-/) *Please replace '-NUM-' in this link by the PR number.* When the PR is marked as ready to merge, you have to wait for 3 days before really merging it. From 14859141daa59388331e4dcc8ad9f3cd7aeeda83 Mon Sep 17 00:00:00 2001 From: pitchum Date: Fri, 26 Apr 2019 20:14:24 +0200 Subject: [PATCH 12/20] Add explicit dependency on php-xml. Fix #44 https://github.com/YunoHost-Apps/opensondage_ynh/issues/44 --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 0dee5b2..b22d2b3 100644 --- a/scripts/install +++ b/scripts/install @@ -60,7 +60,7 @@ ynh_app_setting_set "$app" is_public "$is_public" # INSTALL DEPENDENCIES #================================================= -ynh_install_app_dependencies php-fpdf +ynh_install_app_dependencies php-fpdf php-xml #================================================= # CREATE A MYSQL DATABASE From b19385fdba93f08e2dd0163ebebd557ba43d1aff Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 28 Apr 2019 00:01:10 +0200 Subject: [PATCH 13/20] Add explicit dependency on php-xml in restore script --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index 1d82ae8..917b0f2 100644 --- a/scripts/restore +++ b/scripts/restore @@ -96,7 +96,7 @@ ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql #================================================= # Dependences -ynh_install_app_dependencies php-fpdf +ynh_install_app_dependencies php-fpdf php-xml #================================================= # GENERIC FINALIZATION From 451ea5b9404693c06258323a80da784ee2064ec0 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 18 May 2019 12:44:54 +0200 Subject: [PATCH 14/20] Normalization from example_ynh --- README.md | 7 ++- check_process | 10 ---- manifest.json | 2 +- scripts/_common.sh | 22 ++++--- scripts/backup | 26 ++++----- scripts/install | 79 +++++++++++++------------- scripts/remove | 28 ++++----- scripts/restore | 50 ++++++++-------- scripts/upgrade | 139 ++++++++++++++++++++++++++------------------- 9 files changed, 186 insertions(+), 177 deletions(-) diff --git a/README.md b/README.md index 0e7a7cf..2ad8d20 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ Framadate is an online service for planning an appointment or making a decision #### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/opensondage%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/opensondage/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/opensondage%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/opensondage/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/opensondage%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/opensondage/) +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/opensondage%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/opensondage/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/opensondage%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/opensondage/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/opensondage%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/opensondage/) ## Limitations @@ -51,6 +51,7 @@ Framadate is an online service for planning an appointment or making a decision * Report a bug: https://github.com/YunoHost-Apps/opensondage_ynh/issues * OpenSondage website: https://git.framasoft.org/framasoft/framadate/framadate + * OpenSondage repository: https://git.framasoft.org/framasoft/framadate/framadate * YunoHost website: https://yunohost.org/ --- diff --git a/check_process b/check_process index fb9e10c..386f93a 100644 --- a/check_process +++ b/check_process @@ -20,17 +20,7 @@ port_already_use=0 change_url=0 ;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto -# Niveau 4 non fonctionnel, https://framagit.org/framasoft/framadate/issues/177 - Level 4=na Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 ;;; Upgrade options ; commit=eb508660841801995fe2c66e5bf3259cdbea5922 name=Remove Framasoft signature diff --git a/manifest.json b/manifest.json index 47210c8..03170e4 100644 --- a/manifest.json +++ b/manifest.json @@ -19,7 +19,7 @@ "email": "ljf+opensondage_ynh@grimaud.me" }], "requirements": { - "yunohost": ">= 3.2" + "yunohost": ">= 3.5.0" }, "multi_instance": true, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index 54f3ad5..0f122b9 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -19,43 +19,47 @@ exec_as() { # Execute a command with Composer # -# usage: ynh_composer_exec [--workdir=$final_path] --commands="commands" +# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands" # | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. # | arg: -c, --commands - Commands to execute. ynh_composer_exec () { # Declare an array to define the options of this helper. - local legacy_args=wc - declare -Ar args_array=( [w]=workdir= [c]=commands= ) + local legacy_args=vwc + declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) + local phpversion local workdir local commands # Manage arguments with getopts ynh_handle_getopts_args "$@" workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" COMPOSER_HOME="$workdir/.composer" \ - php "$workdir/composer.phar" $commands \ + php${phpversion} "$workdir/composer.phar" $commands \ -d "$workdir" --quiet --no-interaction } # Install and initialize Composer in the given directory # -# usage: ynh_install_composer [--workdir=$final_path] +# usage: ynh_install_composer --phpversion=phpversion [--workdir=$final_path] # | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. ynh_install_composer () { # Declare an array to define the options of this helper. - local legacy_args=w - declare -Ar args_array=( [w]=workdir= ) + local legacy_args=vw + declare -Ar args_array=( [v]=phpversion= [w]=workdir= ) + local phpversion local workdir # Manage arguments with getopts ynh_handle_getopts_args "$@" workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" curl -sS https://getcomposer.org/installer \ | COMPOSER_HOME="$workdir/.composer" \ - php -- --quiet --install-dir="$workdir" \ + php${phpversion} -- --quiet --install-dir="$workdir" \ || ynh_die "Unable to install Composer." # update dependencies to create composer.lock - ynh_composer_exec --workdir="$workdir" --commands="install --no-dev" \ + ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \ || ynh_die "Unable to update core dependencies with Composer." } diff --git a/scripts/backup b/scripts/backup index 271844f..a1d85d7 100644 --- a/scripts/backup +++ b/scripts/backup @@ -19,46 +19,46 @@ 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) -db_name=$(ynh_app_setting_get $app db_name) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # 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..." -ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= -ynh_print_info "Backing up the MySQL database..." +ynh_script_progression --message="Backing up the MySQL database..." -ynh_mysql_dump_db "$db_name" > db.sql +ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= # 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/install b/scripts/install index ce5f6bd..10603fc 100644 --- a/scripts/install +++ b/scripts/install @@ -31,59 +31,56 @@ 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..." 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 language $language -ynh_app_setting_set $app is_public $is_public +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=language --value=$language +ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_print_info "Installing dependencies..." +ynh_script_progression --message="Installing dependencies..."3 ynh_install_app_dependencies php-fpdf php-cli php-xml #================================================= # CREATE A MYSQL DATABASE #================================================= -ynh_print_info "Creating a MySQL database..." +ynh_script_progression --message="Creating a MySQL database..." --weight=2 -db_name=$(ynh_sanitize_dbid $app) -ynh_app_setting_set $app db_name $db_name -ynh_mysql_setup_db $db_name $db_name +db_name=$(ynh_sanitize_dbid --db_name=$app) +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_print_info "Setting up source files..." +ynh_script_progression --message="Setting up source files..." --weight=3 -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 # Create a dedicated nginx config ynh_add_nginx_config @@ -91,15 +88,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 @@ -109,25 +106,25 @@ ynh_add_fpm_config #================================================= # CREATE CONFIG.PHP #================================================= -ynh_print_info "Configuring opensondage..." +ynh_script_progression --message="Configuring opensondage..." --weight=2 config="$final_path/app/inc/config.php" -admin_mail=$(ynh_user_get_info $admin mail) +admin_mail=$(ynh_user_get_info --username=$admin --key=mail) cp ../conf/config.php "$config" # Change variables in configuration -ynh_replace_string "__DBUSER__" $db_name "$config" -ynh_replace_string "__DBPWD__" $db_pwd "$config" -ynh_replace_string "__DBNAME__" $db_name "$config" -ynh_replace_string "__ADMINMAIL__" $admin_mail "$config" -ynh_replace_string "__LANGUAGE__" $language "$config" -ynh_replace_string "__DOMAIN__" $domain "$config" -ynh_replace_string "__PATH__" $path_url "$config" +ynh_replace_string --match_string="__DBUSER__" --replace_string=$db_name --target_file="$config" +ynh_replace_string --match_string="__DBPWD__" --replace_string="$db_pwd" --target_file="$config" +ynh_replace_string --match_string="__DBNAME__" --replace_string=$db_name --target_file="$config" +ynh_replace_string --match_string="__ADMINMAIL__" --replace_string=$admin_mail --target_file="$config" +ynh_replace_string --match_string="__LANGUAGE__" --replace_string=$language --target_file="$config" +ynh_replace_string --match_string="__DOMAIN__" --replace_string=$domain --target_file="$config" +ynh_replace_string --match_string="__PATH__" --replace_string=$path_url --target_file="$config" # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$config" +ynh_store_file_checksum --file="$config" #================================================= # REPLACE LOGO IMAGE (DEFAULT IS FRAMADATE) @@ -144,7 +141,7 @@ touch "$final_path/admin/stdout.log" #================================================= # RUN DATABASE INITILIZATION #================================================= -ynh_print_info "Initializing database..." +ynh_script_progression --message="Initializing database..."2 # Install composer ynh_install_composer @@ -163,25 +160,25 @@ chown -R $app: "$final_path/"{tpl_c,admin/stdout.log} #================================================= # SETUP SSOWAT #================================================= -ynh_print_info "Configuring SSOwat..." +ynh_script_progression --message="Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] then - ynh_app_setting_set $app skipped_uris "/" + ynh_app_setting_set --app=$app --key=skipped_uris --value="/" # Keep /admin private - ynh_app_setting_set $app protected_uris "/admin" + ynh_app_setting_set --app=$app --key=protected_uris --value="/admin" fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." --weight=2 -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 94679f2..4f937c8 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,20 +12,20 @@ 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) -db_name=$(ynh_app_setting_get $app db_name) -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_print_info "Removing dependencies" +ynh_script_progression --message="Removing dependencies..."3 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -33,23 +33,23 @@ ynh_remove_app_dependencies #================================================= # REMOVE THE MYSQL DATABASE #================================================= -ynh_print_info "Removing the MySQL database" +ynh_script_progression --message="Removing the MySQL database..." --weight=5 # Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_name $db_name +ynh_mysql_remove_db --db_user=$db_name --db_name=$db_name #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_print_info "Removing app main directory" +ynh_script_progression --message="Removing app main directory..." --weight=2 # 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..." --weight=3 # Remove the dedicated nginx config ynh_remove_nginx_config @@ -57,7 +57,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 @@ -67,13 +67,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 7888439..9da58a7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -19,26 +19,24 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading settings..." +ynh_script_progression --message="Loading settings..." --weight=2 -# See comments in install script app=$YNH_APP_INSTANCE_NAME -# Retrieve old app settings -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================ -ynh_print_info "Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." -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 @@ -46,22 +44,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 @@ -74,23 +72,23 @@ chown -R $app: "$final_path/"{tpl_c,admin/stdout.log} # 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" #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_print_info "Restoring the MySQL database..." +ynh_script_progression --message="Restoring the MySQL database..." --weight=2 -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_mysql_setup_db $db_name $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_print_info "Reinstalling dependencies..." +ynh_script_progression --message="Reinstalling dependencies..." --weight=9 # Define and install dependencies ynh_install_app_dependencies php-fpdf php-xml @@ -100,13 +98,13 @@ ynh_install_app_dependencies php-fpdf php-xml #================================================= # 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=3 -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 331e3e8..3e32dae 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,49 +12,55 @@ 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) -language=$(ynh_app_setting_get $app language) -db_name=$(ynh_app_setting_get $app db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +admin=$(ynh_app_setting_get --app=$app --key=admin) +is_public=$(ynh_app_setting_get --app=$app --key=is_public) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +language=$(ynh_app_setting_get --app=$app --key=language) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) + +#================================================= +# 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..." -if [ -z "$is_public" ]; +if [ -z "$is_public" ] then - is_public=$(ynh_app_setting_get $app public_site) - ynh_app_setting_set $app is_public $is_public - ynh_app_setting_delete $app public_site + is_public=$(ynh_app_setting_get --app=$app --key=public_site) + ynh_app_setting_set --app=$app --key=is_public --value=$is_public + ynh_app_setting_delete --app=$app --key=public_site fi # 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 db_name doesn't exist, create it -if [ -z $db_name ]; then - db_name=$(ynh_sanitize_dbid $app) - ynh_app_setting_set $app db_name $db_name +if [ -z "$db_name" ]; then + db_name=$(ynh_sanitize_dbid --db_name=$app) + ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi # If final_path doesn't exist, create it -if [ -z $final_path ]; then +if [ -z "$final_path" ]; then final_path=/var/www/$app - ynh_app_setting_set $app final_path $final_path + ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi # Make sure default language is set @@ -66,15 +72,15 @@ fi # Use path instead of path_url in settings.yml... if [ -z "$path_url" ] then - path_url=$(ynh_app_setting_get $app path_url) - ynh_app_setting_set $app path $path_url - ynh_app_setting_delete $app path_url + path_url=$(ynh_app_setting_get --app=$app --key=path_url) + ynh_app_setting_set --app=$app --key=path --value=$path_url + ynh_app_setting_delete --app=$app --key=path_url 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=3 # Backup the current version of the app ynh_backup_before_upgrade @@ -90,22 +96,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 @@ -113,21 +123,22 @@ ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_print_info "Upgrading dependencies..." +ynh_script_progression --message="Upgrading dependencies..." --weight=7 -ynh_install_app_dependencies php-fpdf php-cli +ynh_install_app_dependencies php-fpdf php-cli php-xml #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info "Making sure dedicated system user exists..." +ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=3 # Create a dedicated php-fpm config ynh_add_fpm_config @@ -137,29 +148,33 @@ ynh_add_fpm_config #================================================= # UPGRADE CONFIG.PHP #================================================= -ynh_print_info "Reconfiguring opensondage..." -config="$final_path/app/inc/config.php" +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Reconfiguring opensondage..." --weight=2 -# Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different "$config" + config="$final_path/app/inc/config.php" -admin_mail=$(ynh_user_get_info $admin mail) + # Verify the checksum and backup the file if it's different + ynh_backup_if_checksum_is_different --file="$config" -cp ../conf/config.php "$config" + admin_mail=$(ynh_user_get_info --username=$admin --key=mail) -# Change variables in configuration -ynh_replace_string "__DBUSER__" $db_name "$config" -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_replace_string "__DBPWD__" $db_pwd "$config" -ynh_replace_string "__DBNAME__" $db_name "$config" -ynh_replace_string "__ADMINMAIL__" $admin_mail "$config" -ynh_replace_string "__LANGUAGE__" $language "$config" -ynh_replace_string "__DOMAIN__" $domain "$config" -ynh_replace_string "__PATH__" $path_url "$config" + cp ../conf/config.php "$config" -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$config" + # Change variables in configuration + ynh_replace_string --match_string="__DBUSER__" --replace_string=$db_name --target_file="$config" + db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) + ynh_replace_string --match_string="__DBPWD__" --replace_string="$db_pwd" --target_file="$config" + ynh_replace_string --match_string="__DBNAME__" --replace_string=$db_name --target_file="$config" + ynh_replace_string --match_string="__ADMINMAIL__" --replace_string=$admin_mail --target_file="$config" + ynh_replace_string --match_string="__LANGUAGE__" --replace_string=$language --target_file="$config" + ynh_replace_string --match_string="__DOMAIN__" --replace_string=$domain --target_file="$config" + ynh_replace_string --match_string="__PATH__" --replace_string=$path_url --target_file="$config" + + # Calculate and store the config file checksum into the app settings + ynh_store_file_checksum --file="$config" +fi #================================================= # REPLACE LOGO IMAGE (DEFAULT IS FRAMADATE) @@ -176,12 +191,16 @@ touch "$final_path/admin/stdout.log" #================================================= # RUN DATABASE UPGRADE #================================================= -ynh_print_info "Upgrading database..." -# Install composer -ynh_install_composer +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading database..." --weight=2 -ynh_exec_warn_less php "$final_path/admin/migration.php" + # Install composer + ynh_install_composer + + ynh_exec_warn_less php "$final_path/admin/migration.php" +fi #================================================= # GENERIC FINALIZATION @@ -195,25 +214,25 @@ chown -R $app: "$final_path/"{tpl_c,admin/stdout.log} #================================================= # SETUP SSOWAT #================================================= -ynh_print_info "Upgrading SSOwat configuration..." +ynh_script_progression --message="Upgrading SSOwat configuration..." # Make app public if necessary if [ $is_public -eq 1 ] then - ynh_app_setting_set $app skipped_uris "/" + ynh_app_setting_set --app=$app --key=skipped_uris --value="/" # Keep /admin private - ynh_app_setting_set $app protected_uris "/admin" + ynh_app_setting_set --app=$app --key=protected_uris --value="/admin" 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 9b491783f07c86b8ffe0d3843cd399ff2e07a145 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 18 May 2019 13:45:14 +0200 Subject: [PATCH 15/20] Add change_url script --- check_process | 2 +- scripts/change_url | 101 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 scripts/change_url diff --git a/check_process b/check_process index 386f93a..8c5439a 100644 --- a/check_process +++ b/check_process @@ -18,7 +18,7 @@ multi_instance=1 incorrect_path=1 port_already_use=0 - change_url=0 + change_url=1 ;;; Levels Level 5=auto ;;; Upgrade options diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..dba7377 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,101 @@ +#!/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 +#================================================= +ynh_script_progression --message="Loading installation settings..." + +# Needed for helper "ynh_add_nginx_config" +final_path=$(ynh_app_setting_get --app=$app --key=final_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 +#================================================= +ynh_script_progression --message="Updating nginx web server configuration..." --weight=2 + +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 --file="$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # 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 --file="$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +# UPDATE OPENSONDAGE CONFIGURATION +#================================================= +ynh_script_progression --message="Reconfiguring opensondage..." + +ynh_replace_string --match_string="const APP_URL = '$old_domain';" --replace_string="const APP_URL = '$new_domain';" --target_file="$final_path/app/inc/config.php" + +#================================================= +# GENERIC FINALISATION +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading nginx web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --last From 7aaf18cf6487ced9d3fbb2f6fe2f871536f097aa Mon Sep 17 00:00:00 2001 From: Kayou Date: Mon, 24 Jun 2019 09:39:18 +0200 Subject: [PATCH 16/20] Update install --- scripts/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index d9f019b..c2268cb 100644 --- a/scripts/install +++ b/scripts/install @@ -167,14 +167,14 @@ if [ $is_public -eq 1 ] then ynh_app_setting_set --app=$app --key=skipped_uris --value="/" - # Keep /admin private + # Keep /admin private if [ "$path_url" == "/" ]; then # If the path is /, clear it to prevent any error with the regex. path_url="" fi # Modify the domain to be used in a regex domain_regex=$(echo "$domain" | sed 's@-@.@g') - ynh_app_setting_set $app protected_regex "$domain_regex$path_url/admin/" + ynh_app_setting_set --app=$app -key=protected_regex -value="$domain_regex$path_url/admin/" fi #================================================= From 1ceef95ce8d880e02a958ca71370b3b584c9734e Mon Sep 17 00:00:00 2001 From: Kayou Date: Mon, 24 Jun 2019 09:40:12 +0200 Subject: [PATCH 17/20] Update upgrade --- scripts/upgrade | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 5ab1fc2..e1e1a87 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -221,14 +221,14 @@ if [ $is_public -eq 1 ] then ynh_app_setting_set --app=$app --key=skipped_uris --value="/" - # Keep /admin private + # Keep /admin private if [ "$path_url" == "/" ]; then # If the path is /, clear it to prevent any error with the regex. path_url="" fi # Modify the domain to be used in a regex domain_regex=$(echo "$domain" | sed 's@-@.@g') - ynh_app_setting_set $app protected_regex "$domain_regex$path_url/admin/" + ynh_app_setting_set --app=$app -key=protected_regex -value="$domain_regex$path_url/admin/" fi #================================================= From e314e73e6759c3e16c3bfb3c2ef11897f449b80d Mon Sep 17 00:00:00 2001 From: Kayou Date: Mon, 24 Jun 2019 09:47:53 +0200 Subject: [PATCH 18/20] Fix getops --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index e1e1a87..b28d82d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -228,7 +228,7 @@ then fi # Modify the domain to be used in a regex domain_regex=$(echo "$domain" | sed 's@-@.@g') - ynh_app_setting_set --app=$app -key=protected_regex -value="$domain_regex$path_url/admin/" + ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/admin/" fi #================================================= From 2b17f5f0f259122aaad388c0c2cb8423f1767498 Mon Sep 17 00:00:00 2001 From: Kayou Date: Mon, 24 Jun 2019 09:49:09 +0200 Subject: [PATCH 19/20] Fix getops-2 --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index c2268cb..f3edb49 100644 --- a/scripts/install +++ b/scripts/install @@ -174,7 +174,7 @@ then fi # Modify the domain to be used in a regex domain_regex=$(echo "$domain" | sed 's@-@.@g') - ynh_app_setting_set --app=$app -key=protected_regex -value="$domain_regex$path_url/admin/" + ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/admin/" fi #================================================= From cef7221323c9510e7b71196d558ecc2de1ff8d0d Mon Sep 17 00:00:00 2001 From: Kayou Date: Mon, 24 Jun 2019 09:52:08 +0200 Subject: [PATCH 20/20] Make /admin private after a change url --- scripts/change_url | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/change_url b/scripts/change_url index dba7377..bb0a96f 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -29,6 +29,8 @@ ynh_script_progression --message="Loading installation settings..." # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) +is_public=$(ynh_app_setting_get --app=$app --key=is_public) + #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED #================================================= @@ -87,6 +89,26 @@ ynh_replace_string --match_string="const APP_URL = '$old_domain';" --replace_str #================================================= # GENERIC FINALISATION +#================================================= +# SETUP SSOWAT +#================================================= +ynh_script_progression --message="Upgrading SSOwat configuration..." + +# Make app public if necessary +if [ $is_public -eq 1 ] +then + ynh_app_setting_delete --app=$app --key=protected_regex + + # Keep /admin private + if [ "$path_url" == "/" ]; then + # If the path is /, clear it to prevent any error with the regex. + path_url="" + fi + # Modify the domain to be used in a regex + domain_regex=$(echo "$new_domain" | sed 's@-@.@g') + ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/admin/" +fi + #================================================= # RELOAD NGINX #=================================================