From 281c79b5ea6fb6d7023d078c9566622659242bbd Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 13 Mar 2018 21:49:11 +0100 Subject: [PATCH 01/13] [enh] Upgrade to 2.7 --- README.md | 72 +++- app.src | 3 - check_process | 9 +- conf/app.src | 3 + conf/libreform.src | 3 + conf/nginx.conf.j2 | 11 +- conf/php-fpm.conf.j2 | 2 +- conf/{php-fpm.ini => php-fpm.ini.j2} | 0 hooks/post_user_delete | 2 +- manifest.json | 34 +- scripts/_common.sh | 483 ++++++++++------------- scripts/backup | 63 +-- scripts/install | 166 ++++++-- scripts/remove | 69 +++- scripts/restore | 565 ++++----------------------- scripts/upgrade | 126 ++++-- 16 files changed, 686 insertions(+), 925 deletions(-) delete mode 100644 app.src create mode 100644 conf/app.src create mode 100644 conf/libreform.src rename conf/{php-fpm.ini => php-fpm.ini.j2} (100%) diff --git a/README.md b/README.md index 0219964..fb32475 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,71 @@ -LimeSurvey for YunoHost -=============== +# LibreSurvey for YunoHost -LimeSurvey is used to create advanced poll. +[![Integration level](https://dash.yunohost.org/integration/libresurvey.svg)](https://ci-apps.yunohost.org/jenkins/job/libresurvey%20%28Community%29/lastBuild/consoleFull) +[![Install LibreSurvey with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=libresurvey) -http://www.limesurvey.org/ +> *This package allow you to install LibreSurvey 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.* -**Package by:** ljf (I will maintain this package at least until beggining of 2018) +## Overview +LibreSurvey is used to create advanced poll. -**Patches author:** Shnoulle +**Shipped version:** 2.62.5 **Categories:** Productivity, Poll -**Upgrade this package:** -`sudo yunohost app upgrade --verbose LimeSurvey -u https://github.com/YunoHost-Apps/limesurvey_ynh` +## Screenshots -**Multi-user:** Yes. +![](https://www.limesurvey.org/images/news/LimeSurvey3Beta/generalsettings.PNG) -**Private/Public mode:** In private mode, only authorized YunoHost members can create poll, with the public mode, it's possible to create account to people with no YunoHost account. +## Configuration + +Before to run the install YunoHost ask you an admin user, you can use it to connecte you on https://your_libresurvey_url/admin/ + +## Documentation + +* YunoHost documentation: There no other documentations, feel free to contribute. + +## YunoHost specific features + + +* In private mode, only authorized YunoHost members can create poll, with the public mode, it's possible to create account to people with no YunoHost account. +* SSO and LDAP are configured. +* Login secured by fail2ban + +#### Multi-users support + +Not supported. + +#### Supported architectures + +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/libresurvey%20(Community)/) +* ARMv8-A - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/libresurvey%20(Community)%20(%7EARM%7E)/) + +## Limitations + +## Additionnal informations + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/libresurvey_ynh/issues + * LibreSurvey is a fork of LimeSurvey https://www.limesurvey.org + * YunoHost website: https://yunohost.org/ + +--- + +Developers infos +---------------- + +**Package by:** ljf + +**Patches author:** Shnoulle + +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/libresurvey_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/libresurvey_ynh/tree/testing --verbose +or +sudo yunohost app upgrade leed -u https://github.com/YunoHost-Apps/libresurvey_ynh/tree/testing --verbose +``` -**SSO/LDAP:** SSO and LDAP are configured. diff --git a/app.src b/app.src deleted file mode 100644 index 6567177..0000000 --- a/app.src +++ /dev/null @@ -1,3 +0,0 @@ -SOURCE_URL=https://github.com/LimeSurvey/LimeSurvey/archive/2.64.5+170331.tar.gz -SOURCE_SUM=ede99fb149feed4a60ea83e540263c912a68fb46c7fca98cb7ff7c5d474f3dc4 -SOURCE_FILE=limesurvey2.64.5+170331.tar.gz diff --git a/check_process b/check_process index b3da0d1..b7de956 100644 --- a/check_process +++ b/check_process @@ -7,7 +7,7 @@ language="en" is_public=1 (PUBLIC|public=1|private=0) ; Checks - pkg_linter=1 + pkg_linter=0 setup_sub_dir=1 setup_root=1 setup_nourl=0 @@ -23,15 +23,18 @@ fail_download_source=0 port_already_use=0 final_path_already_use=0 + change_url=0 ;;; Levels Level 1=auto Level 2=auto Level 3=auto Level 4=1 -# https://github.com/YunoHost-Apps/limesurvey_ynh/issues/10 - Level 5=1 + Level 5=auto Level 6=auto Level 7=auto Level 8=0 Level 9=0 Level 10=0 +;;; Options +Email=ljf+libresurvey_ynh@reflexlibre.net +Notification=down diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..1c0b8b9 --- /dev/null +++ b/conf/app.src @@ -0,0 +1,3 @@ +SOURCE_URL=https://github.com/LimeSurvey/LimeSurvey/archive/2.64.5+170331.tar.gz +SOURCE_SUM=9ae345eae7443f4df7f60ac49e8514ffb30315ba9376d5464cbfe9d6aaf9469f +SOURCE_FILENAME=libresurvey2.64.5+170331.tar.gz diff --git a/conf/libreform.src b/conf/libreform.src new file mode 100644 index 0000000..1f6b0e5 --- /dev/null +++ b/conf/libreform.src @@ -0,0 +1,3 @@ +SOURCE_URL=https://github.com/zamentur/libreform/archive/40fad776c33271ecc028b9260fb7f9e300998e5f.tar.gz +SOURCE_SUM=4c0a96d610c6740ff7467cf1916a923949bf4c00e99a3cd33509335f884e138b +SOURCE_FILENAME=libreform-40fad776c33271ecc028b9260fb7f9e300998e5f.tar.gz diff --git a/conf/nginx.conf.j2 b/conf/nginx.conf.j2 index 9b741fd..608d752 100644 --- a/conf/nginx.conf.j2 +++ b/conf/nginx.conf.j2 @@ -1,9 +1,12 @@ -location {{ path }} { - alias {{ local_path }}/; +{% if path_url != "/" %} +rewrite ^{{ path_url }}$ {{ path_url }}/ permanent; +{% endif %} +location {{ path_url }}/ { + alias {{ final_path }}/; index index.php; # if (!-e $request_filename) #{ - # rewrite ^(.+)$ {{ path }}/index.php?q=$1 last; + # rewrite ^(.+)$ {{ path_url }}/index.php?q=$1 last; #} if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; @@ -24,6 +27,6 @@ location {{ path }} { include conf.d/yunohost_panel.conf.inc; } -location ~ ^{{ path }}(data|config|\.ht|db_structure\.xml|README) { +location ~ ^{{ path_url }}(data|config|\.ht|db_structure\.xml|README) { deny all; } diff --git a/conf/php-fpm.conf.j2 b/conf/php-fpm.conf.j2 index 3daf747..6464423 100644 --- a/conf/php-fpm.conf.j2 +++ b/conf/php-fpm.conf.j2 @@ -340,7 +340,7 @@ request_terminate_timeout = 1d ; Chdir to this directory at the start. ; Note: relative path can be used. ; Default Value: current directory or / when chroot -chdir = {{ local_path }} +chdir = {{ final_path }} ; Redirect worker stdout and stderr into main error log. If not set, stdout and ; stderr will be redirected to /dev/null according to FastCGI specs. diff --git a/conf/php-fpm.ini b/conf/php-fpm.ini.j2 similarity index 100% rename from conf/php-fpm.ini rename to conf/php-fpm.ini.j2 diff --git a/hooks/post_user_delete b/hooks/post_user_delete index 65ee262..30a47a8 100644 --- a/hooks/post_user_delete +++ b/hooks/post_user_delete @@ -1,4 +1,4 @@ #!/bin/bash # TODO delete user with LimeSurvey cli # An action need to be added to the cli with a patch -echo "[warn] You may need to delete this user in your LimeSurvey instances" +echo "[warn] You may need to delete this user in your LibreSurvey instances" diff --git a/manifest.json b/manifest.json index ba8b605..535c4fb 100644 --- a/manifest.json +++ b/manifest.json @@ -1,21 +1,21 @@ { - "name": "LimeSurvey", - "id": "limesurvey", + "name": "LibreSurvey", + "id": "libresurvey", "packaging_format": 1, - "version": "2.62.2", + "version": "2.62.5-1", "description": { - "en": "LimeSurvey is used to create advanced poll.", - "fr": "LimeSurvey est un outil de création et diffusion de sondage en ligne." + "en": "LibreSurvey is used to create advanced poll.", + "fr": "LibreSurvey est un outil de création et diffusion de sondage en ligne." }, "license": "GPL-2.0+", "maintainer": { "name": "ljf", - "email": "ljf@grimaud.me", + "email": "ljf+libresurvey_ynh@reflexlibre.net", "url": "http://www.limesurvey.org/" }, "url": "https://www.limesurvey.org/", "requirements": { - "yunohost": ">= 2.4" + "yunohost": ">= 2.7.2" }, "multi_instance": true, "services": [ @@ -29,8 +29,8 @@ "name": "domain", "type": "domain", "ask": { - "en": "Choose a domain for LimeSurvey", - "fr": "Choisissez un nom de domaine pour LimeSurvey" + "en": "Choose a domain for LibreSurvey", + "fr": "Choisissez un nom de domaine pour LibreSurvey" }, "example": "domain.org" }, @@ -38,8 +38,8 @@ "name": "path", "type": "path", "ask": { - "en": "Choose a path for LimeSurvey", - "fr": "Choisissez l'adresse pour LimeSurvey" + "en": "Choose a path for LibreSurvey", + "fr": "Choisissez l'adresse pour LibreSurvey" }, "example": "/poll", "default": "/poll" @@ -48,16 +48,16 @@ "name": "admin", "type": "user", "ask": { - "en": "Choose the LimeSurvey administrator (must be an existing YunoHost user)", - "fr": "Choisissez l'administrateur de LimeSurvey (doit être un utilisateur YunoHost)" + "en": "Choose the LibreSurvey administrator (must be an existing YunoHost user)", + "fr": "Choisissez l'administrateur de LibreSurvey (doit être un utilisateur YunoHost)" }, "example": "john" }, { "name": "language", "ask": { - "en": "Choose the default language of this LimeSurvey", - "fr": "Choisissez la langue par défault de LimeSurvey" + "en": "Choose the default language of this LibreSurvey", + "fr": "Choisissez la langue par défault de LibreSurvey" }, "choices": ["en", "fr","es", "de"], "default": "en" @@ -66,8 +66,8 @@ "name": "is_public", "type": "boolean", "ask": { - "en": "Will people without YunoHost account have LimeSurvey account to be able to create polls ?", - "fr": "Est-ce que des personnes sans compte YunoHost aurront un compte LimeSurvey pour créer des questionnaires ?" + "en": "Will people without YunoHost account have LibreSurvey account to be able to create polls ?", + "fr": "Est-ce que des personnes sans compte YunoHost aurront un compte LibreSurvey pour créer des questionnaires ?" }, "default": 1 } diff --git a/scripts/_common.sh b/scripts/_common.sh index 9b09134..51a92e4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,85 +1,57 @@ #!/bin/bash +#================================================= +# COMMON VARIABLES +#================================================= # App package root directory should be the parent folder PKG_DIR=$(cd ../; pwd) +pkg_dependencies="php5-cli php5-imap" + +#================================================= +# SPECIFIC HELPERS +#================================================= +set_permissions () { + + ynh_set_default_perm $final_path + find $final_path -type f -name "*.php" -print0 | xargs -0 chmod 400 \ + || echo "No file to modify" + #chown root: $final_path/application/config/config.php + chmod -R u+w $final_path/tmp + chmod -R u+w $final_path/templates + chmod -R u+w $final_path/upload + chmod -R u+w $final_path/application/config/ +} + +#================================================= +# COMMON HELPERS +#================================================= +ynh_set_default_perm () { + local DIRECTORY=$1 + # Set permissions + chown -R $app:www-data $DIRECTORY + chmod -R 440 $DIRECTORY + find $DIRECTORY -type d -print0 | xargs -0 chmod 550 \ + || echo "No file to modify" + +} ynh_check_var () { test -n "$1" || ynh_die "$2" } -ynh_exit_properly () { - exit_code=$? - if [ "$exit_code" -eq 0 ]; then - exit 0 - fi - trap '' EXIT - set +eu - echo -e "\e[91m \e[1m" - err "$app script has encountered an error." - - if type -t CLEAN_SETUP > /dev/null; then - CLEAN_SETUP - fi - - ynh_die -} - -# Activate signal capture -# Exit if a command fail, and if a variable is used unset. -# Capturing exit signals on shell script -# -# example: CLEAN_SETUP () { -# # Clean residual file un remove by remove script -# } -# ynh_trap_on -ynh_trap_on () { - set -eu - trap ynh_exit_properly EXIT # Capturing exit signals on shell script -} - ynh_export () { local ynh_arg="" for var in $@; do ynh_arg=$(echo $var | awk '{print toupper($0)}') + if [ "$var" == "path_url" ]; then + ynh_arg="PATH" + fi ynh_arg="YNH_APP_ARG_$ynh_arg" export $var=${!ynh_arg} done } -# Check availability of a web path -# -# example: ynh_path_validity $domain$path -# -# usage: ynh_path_validity $domain_and_path -# | arg: domain_and_path - complete path to check -ynh_path_validity () { - sudo yunohost app checkurl $1 -a $app -} - -# Normalize the url path syntax -# Handle the slash at the beginning of path and its absence at ending -# Return a normalized url path -# -# example: url_path=$(ynh_normalize_url_path $url_path) -# ynh_normalize_url_path example -> /example -# ynh_normalize_url_path /example -> /example -# ynh_normalize_url_path /example/ -> /example -# -# usage: ynh_normalize_url_path path_to_normalize -# | arg: url_path_to_normalize - URL path to normalize before using it -ynh_normalize_url_path () { - path=$1 - test -n "$path" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing." - if [ "${path:0:1}" != "/" ]; then # If the first character is not a / - path="/$path" # Add / at begin of path variable - fi - if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # If the last character is a / and that not the only character. - path="${path:0:${#path}-1}" # Delete the last character - fi - echo $path -} - # Check the path doesn't exist # usage: ynh_local_path_available PATH ynh_local_path_available () { @@ -94,31 +66,14 @@ ynh_local_path_available () { ynh_save_args () { for var in $@; do - ynh_app_setting_set $app $var ${!var} + local setting_var="$var" + if [ "$var" == "path_url" ]; then + setting_var="path" + fi + ynh_app_setting_set $app $setting_var ${!var} done } -# Create a database, an user and its password. Then store the password in the app's config -# -# User of database will be store in db_user's variable. -# Name of database will be store in db_name's variable. -# And password in db_pwd's variable. -# -# usage: ynh_mysql_generate_db user name -# | arg: user - Proprietary of the database -# | arg: name - Name of the database -ynh_mysql_generate_db () { - export db_user=${1//[-.]/_} # Mariadb doesn't support - and . in the name of databases. It will be replace by _ - export db_name=${2//[-.]/_} - - export db_pwd=$(ynh_string_random) # Generate a random password - ynh_check_var "$db_pwd" "db_pwd empty" - - ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database - - ynh_app_setting_set $app mysqlpwd $db_pwd # Store the password in the app's config -} - # Execute a command as another user # usage: ynh_exec_as USER COMMAND [ARG ...] ynh_exec_as() { @@ -133,80 +88,20 @@ ynh_exec_as() { fi } -# Get sources, setup it into dest directory and deploy patches -# Try to find locally the sources and download it if missing. -# Check the integrity with an hash program (default: sha256sum) -# Source hash and location are get from a "SOURCE_ID.src" file, -# by default the SOURCE_ID is "app". -# Patches should be located in a "patches" dir, they should be -# named like "SOURCE_ID-*.patch". -# -# example: ynh_setup_source "/var/www/limesurvey/" "limesurvey" -# -# usage: ynh_setup_source DEST_DIR [USER [SOURCE_ID]] - -ynh_setup_source () { - local DEST=$1 - local AS_USER=${2:-admin} - local SOURCE_ID=${3:-app} - local SOURCE_FILE="$YNH_APP_ID.tar.gz" - local SUM_PRG="sha256sum" - source ../$SOURCE_ID.src - local LOCAL_SOURCE="/opt/yunohost-apps-src/$YNH_APP_ID/$SOURCE_FILE" - - if test -e $LOCAL_SOURCE; then - cp $LOCAL_SOURCE $SOURCE_FILE - else - wget -nv $SOURCE_URL -O $SOURCE_FILE - fi - echo "$SOURCE_SUM $SOURCE_FILE" |$SUM_PRG -c --status \ - || ynh_die "Corrupt source" - - sudo mkdir -p "$DEST" - sudo chown $AS_USER: "$DEST" - if [ "$(echo ${SOURCE_FILE##*.})" == "gz" ]; then - ynh_exec_as "$AS_USER" tar xf $SOURCE_FILE -C "$DEST" --strip-components 1 - elif [ "$(echo ${SOURCE_FILE##*.})" == "bz2" ]; then - ynh_exec_as "$AS_USER" tar xjf $SOURCE_FILE -C "$DEST" --strip-components 1 - elif [ "$(echo ${SOURCE_FILE##*.})" == "zip" ]; then - mkdir -p "/tmp/$SOURCE_FILE" - ynh_exec_as "$AS_USER" unzip -q $SOURCE_FILE -d "/tmp/$SOURCE_FILE" - ynh_exec_as "$AS_USER" mv "/tmp/$SOURCE_FILE"/./. "$DEST" - rmdir "$/tmp/$SOURCE_FILE" - else - false - fi - - # Apply patches - if [ -f ${PKG_DIR}/patches/$SOURCE_ID-*.patch ]; then - (cd "$DEST" \ - && for p in ${PKG_DIR}/patches/$SOURCE_ID-*.patch; do \ - ynh_exec_as "$AS_USER" patch -p1 < $p; done) \ - || ynh_die "Unable to apply patches" - - fi - - # Apply persistent modules (upgrade only) - ynh_restore_persistent modules - - # Apply persistent data (upgrade only) - ynh_restore_persistent data - -} # TODO support SOURCE_ID ynh_save_persistent () { local TYPE=$1 local DIR=/tmp/ynh-persistent/$TYPE/$app/app - sudo mkdir -p $DIR - sudo touch $DIR/dir_names + mkdir -p $DIR + touch $DIR/dir_names shift i=1 for PERSISTENT_DIR in $@; do if [ -e $local_path/$PERSISTENT_DIR ]; then - sudo mv $local_path/$PERSISTENT_DIR $DIR/$i - sudo su -c "echo -n '$PERSISTENT_DIR ' >> $DIR/dir_names" + mv $local_path/$PERSISTENT_DIR $DIR/$i + echo -n '$PERSISTENT_DIR ' >> $DIR/dir_names ((i++)) fi done @@ -224,52 +119,43 @@ ynh_restore_persistent () { if [ "$TYPE" = "modules" ]; then for updated_subdir in $(ls $local_path/$PERSISTENT_DIR); do - sudo rm -Rf $DIR/$i/$updated_subdir + ynh_secure_remove $DIR/$i/$updated_subdir done fi if [ -d $DIR/$i ]; then - sudo mv $DIR/$i/* $local_path/$PERSISTENT_DIR/ 2> /dev/null || true + mv $DIR/$i/* $local_path/$PERSISTENT_DIR/ 2> /dev/null || true else - sudo mv $DIR/$i $local_path/$PERSISTENT_DIR 2> /dev/null || true + mv $DIR/$i $local_path/$PERSISTENT_DIR 2> /dev/null || true fi ((i++)) done - sudo rm -Rf $DIR + ynh_secure_remove $DIR fi } ynh_mv_to_home () { local APP_PATH="/home/yunohost.app/$app/" local DATA_PATH="$1" - sudo mkdir -p "$APP_PATH" - sudo chown $app: "$APP_PATH" + mkdir -p "$APP_PATH" + chown $app: "$APP_PATH" ynh_exec_as "$app" mv "$DATA_PATH" "$APP_PATH" ynh_exec_as "$app" ln -s "$APP_PATH$DATA_PATH" "$DATA_PATH" } -ynh_set_default_perm () { - local DIRECTORY=$1 - # Set permissions - sudo chown -R $app:$app $DIRECTORY - sudo chmod -R 664 $DIRECTORY - sudo find $DIRECTORY -type d -print0 | xargs -0 sudo chmod 775 \ - || echo "No file to modify" - -} ynh_sso_access () { ynh_app_setting_set $app unprotected_uris "/" if [[ $is_public -eq 0 ]]; then ynh_app_setting_set $app protected_uris "$1" fi - sudo yunohost app ssowatconf + yunohost app ssowatconf } ynh_exit_if_up_to_date () { if [ "${version}" = "${last_version}" ]; then info "Up-to-date, nothing to do" - exit 0 + ynh_die "Up-to-date, nothing to do" 0 fi } @@ -311,64 +197,6 @@ ynh_read_manifest () { fi } -ynh_app_dependencies (){ - export dependencies=$1 - export project_url=$(ynh_read_manifest 'url') - export version=$(ynh_read_manifest 'version') - export dep_app=${app/__/-} - mkdir -p ../conf - cat > ../conf/app-ynh-deps.control.j2 << EOF -Section: misc -Priority: optional -Homepage: {{ project_url }} -Standards-Version: 3.9.2 - -Package: {{ dep_app }}-ynh-deps -Version: {{ version }} -Depends: {{ dependencies }} -Architecture: all -Description: meta package for {{ app }} (YunoHost app) dependencies - This meta-package is only responsible of installing its dependencies. -EOF - - ynh_configure app-ynh-deps.control ./$dep_app-ynh-deps.control - ynh_package_install_from_equivs ./$dep_app-ynh-deps.control \ - || ynh_die "Unable to install dependencies" -} - - - - -# Create a system user -# -# usage: ynh_system_user_create user_name [home_dir] -# | arg: user_name - Name of the system user that will be create -# | arg: home_dir - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home -ynh_system_user_create () { - if ! ynh_system_user_exists "$1" # Check if the user exists on the system - then # If the user doesn't exist - if [ $# -ge 2 ]; then # If a home dir is mentioned - user_home_dir="-d $2" - else - user_home_dir="--no-create-home" - fi - sudo useradd $user_home_dir --system --user-group $1 --shell /usr/sbin/nologin || ynh_die "Unable to create $1 system account" - fi -} - -# Delete a system user -# -# usage: ynh_system_user_delete user_name -# | arg: user_name - Name of the system user that will be create -ynh_system_user_delete () { - if ynh_system_user_exists "$1" # Check if the user exists on the system - then - sudo userdel $1 - else - echo "The user $1 was not found" >&2 - fi -} - ynh_configure () { local TEMPLATE=$1 @@ -378,82 +206,167 @@ ynh_configure () { sudo cp "${PKG_DIR}/conf/$TEMPLATE" "$DEST" } -ynh_configure_nginx () { - ynh_configure nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf - sudo service nginx reload +ynh_add_nginx_config () { + finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalnginxconf" + ynh_configure nginx.conf "$finalnginxconf" + ynh_store_file_checksum "$finalnginxconf" + service nginx reload } -ynh_configure_php_fpm () { - finalphpconf=/etc/php5/fpm/pool.d/$app.conf - ynh_configure php-fpm.conf /etc/php5/fpm/pool.d/$app.conf - sudo chown root: $finalphpconf - - finalphpini=/etc/php5/fpm/conf.d/20-$app.ini - sudo cp ../conf/php-fpm.ini $finalphpini - sudo chown root: $finalphpini - - sudo service php5-fpm reload +ynh_add_fpm_config () { + # Configure PHP-FPM 7.0 by default + local fpm_config_dir="/etc/php/7.0/fpm" + local fpm_service="php7.0-fpm" + # Configure PHP-FPM 5 on Debian Jessie + if is_jessie; then + fpm_config_dir="/etc/php5/fpm" + fpm_service="php5-fpm" + fi + ynh_app_setting_set $app fpm_config_dir "$fpm_config_dir" + ynh_app_setting_set $app fpm_service "$fpm_service" + finalphpconf="$fpm_config_dir/pool.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalphpconf" + ynh_configure php-fpm.conf "$finalphpconf" + sudo chown root: "$finalphpconf" + ynh_store_file_checksum "$finalphpconf" + + if [ -e "../conf/php-fpm.ini" ] + then + finalphpini="$fpm_config_dir/conf.d/20-$app.ini" + ynh_backup_if_checksum_is_different "$finalphpini" + ynh_configure php-fpm.ini "$finalphpini" + chown root: "$finalphpini" + ynh_store_file_checksum "$finalphpini" + fi + systemctl reload $fpm_service } -# Find a free port and return it +# Send an email to inform the administrator # -# example: port=$(ynh_find_port 8080) +# usage: ynh_send_readme_to_admin app_message [recipients] +# | arg: app_message - The message to send to the administrator. +# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root +# example: "root admin@domain" +# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you +# example: "root admin@domain user1 user2" +ynh_send_readme_to_admin() { + local app_message="${1:-...No specific information...}" + local recipients="${2:-root}" + + # Retrieve the email of users + find_mails () { + local list_mails="$1" + local mail + local recipients=" " + # Read each mail in argument + for mail in $list_mails + do + # Keep root or a real email address as it is + if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" + then + recipients="$recipients $mail" + else + # But replace an user name without a domain after by its email + if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) + then + recipients="$recipients $mail" + fi + fi + done + echo "$recipients" + } + recipients=$(find_mails "$recipients") + + local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!" + + local mail_message="This is an automated message from your beloved YunoHost server. +Specific information for the application $app. +$app_message +--- +Automatic diagnosis data from YunoHost +$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')" + + # Send the email to the recipients + echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" +} + +# Exit without error if the package is up to date # -# usage: ynh_find_port begin_port -# | arg: begin_port - port to start to search -ynh_find_port () { - port=$1 - test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port." - while netcat -z 127.0.0.1 $port # Check if the port is free - do - port=$((port+1)) # Else, pass to next port - done - echo $port -} - - -### REMOVE SCRIPT - -# Remove a database if it exist and the associated user +# This helper should be used to avoid an upgrade of a package +# when it's not needed. # -# usage: ynh_mysql_remove_db user name -# | arg: user - Proprietary of the database -# | arg: name - Name of the database -ynh_mysql_remove_db () { - if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $2"; then # Check if the database exist - ynh_mysql_drop_db $2 # Remove the database - ynh_mysql_drop_user $1 # Remove the associated user to database - else - echo "Database $2 not found" >&2 - fi +# To force an upgrade, even if the package is up to date, +# you have to set the variable YNH_FORCE_UPGRADE before. +# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp +# +# usage: ynh_abort_if_up_to_date +ynh_abort_if_up_to_date () { + local force_upgrade=${YNH_FORCE_UPGRADE:-0} + local package_check=${PACKAGE_CHECK_EXEC:-0} + + local version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) + local last_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0) + if [ "$version" = "$last_version" ] + then + if [ "$force_upgrade" != "0" ] + then + echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2 + unset YNH_FORCE_UPGRADE + elif [ "$package_check" != "0" ] + then + echo "Upgrade forced for package check." >&2 + else + ynh_die "Up-to-date, nothing to do" 0 + fi + fi } -ynh_rm_nginx_conf () { - if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then - sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" - sudo service nginx reload - fi +# Remove any logs for all the following commands. +# +# usage: ynh_print_OFF +# WARNING: You should be careful with this helper, and never forgot to use ynh_print_ON as soon as possible to restore the logging. +ynh_print_OFF () { + set +x } -ynh_rm_php_fpm_conf () { - if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then - sudo rm "/etc/php5/fpm/pool.d/$app.conf" - fi - if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then - sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" - fi - sudo service php5-fpm reload +# Restore the logging after ynh_print_OFF +# +# usage: ynh_print_ON +ynh_print_ON () { + set -x + # Print an echo only for the log, to be able to know that ynh_print_ON has been called. + echo ynh_print_ON > /dev/null +} +ynh_version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } + +# In upgrade script allow to test if the app is less than or equal a specific version +# +# usage: ynh_version_le "0.5" +ynh_version_le() { + local version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) + ynh_version_gt "$1" "${version}" } -REMOVE_LOGROTATE_CONF () { - if [ -e "/etc/logrotate.d/$app" ]; then - sudo rm "/etc/logrotate.d/$app" - fi +ynh_debian_release () { + lsb_release --codename --short } -ynh_secure_rm () { - [[ "/var/www /opt /home/yunohost.app" =~ $1 ]] \ - || (test -n "$1" && sudo rm -Rf $1 ) +is_stretch () { + if [ "$(ynh_debian_release)" == "stretch" ] + then + return 0 + else + return 1 + fi } +is_jessie () { + if [ "$(ynh_debian_release)" == "jessie" ] + then + return 0 + else + return 1 + fi +} diff --git a/scripts/backup b/scripts/backup index 537c86c..bb742d4 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,34 +1,53 @@ #!/bin/bash -# causes the shell to exit if any subcommand or pipeline returns a non-zero status -set -e +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +source /usr/share/yunohost/helpers -# Source YNH helpers -. /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= -backup_dir=$1 +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= -# Get app instance name app=$YNH_APP_INSTANCE_NAME -# Retrieve arguments domain=$(ynh_app_setting_get $app domain) -path=$(ynh_app_setting_get $app path) -local_path=$(ynh_app_setting_get $app local_path) +final_path=$(ynh_app_setting_get $app final_path) +db_name=$(ynh_app_setting_get $app db_name) +db_pwd=$(ynh_app_setting_get $app mysqlpwd) -my_ynh_backup () { - ynh_backup $@ - echo $2 $1 >> $backup_dir/list -} +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP OF THE MAIN DIR OF THE APP +#================================================= -# Copy the app files -my_ynh_backup "$local_path" "sources" +ynh_backup "$final_path" -# Copy the conf files -my_ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" -my_ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "conf/php-fpm.conf" -my_ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "conf/php-fpm.ini" +#================================================= +# BACKUP OF THE NGINX CONFIGURATION +#================================================= -# Save database -dbpass=$(ynh_app_setting_get "$app" mysqlpwd) -mysqldump -u "$app" -p"$dbpass" --no-create-db "$app" > ./dump.sql +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# BACKUP OF THE PHP-FPM CONFIGURATION +#================================================= + +ynh_backup "/etc/php5/fpm/pool.d/$app.conf" +ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" + +#================================================= +# BACKUP OF THE SQL BDD +#================================================= + +ynh_mysql_dump_db "$db_name" > db.sql diff --git a/scripts/install b/scripts/install index 6eef0a2..d2c9835 100755 --- a/scripts/install +++ b/scripts/install @@ -1,62 +1,166 @@ #!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + source /usr/share/yunohost/helpers source _common.sh -ynh_trap_on +#================================================= +# MANAGE FAILURE OF THE SCRIPT +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= export app=$YNH_APP_INSTANCE_NAME -user=$app # Retrieve arguments -ynh_export domain path admin is_public language -export local_path=/var/www/$app +ynh_export domain path_url admin is_public language export prefix=lime_ +export db_name=$(ynh_sanitize_dbid $app) +export db_user=$db_name #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= -ynh_check_var "$app" "app name not set" -ynh_user_exists "$admin" || ynh_die "User does not exist: $admin" -ynh_normalize_url_path "$path" -ynh_path_validity "$domain$path" -ynh_local_path_available "$local_path" + +export 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) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url #================================================= -# SETUP THE APP BY MODIFYING THE SYSTEM +# STANDARD MODIFICATIONS +#================================================= +# INSTALL DEPENDENCIES #================================================= -ynh_save_args domain path admin is_public language local_path prefix +ynh_install_app_dependencies $pkg_dependencies -ynh_app_dependencies php5-imap +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= +ynh_save_args domain admin is_public language final_path prefix path_url db_name db_user -ynh_mysql_generate_db "$user" "$app" +#================================================= +# CREATE A SQL BDD +#================================================= -ynh_system_user_create "$user" "$local_path" +ynh_mysql_setup_db $db_user $db_name +export db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_setup_source "$local_path" "$user" - -ynh_configure config.php "$local_path/application/config/config.php" +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= -# Fill LimeSurvey database -sed "s/\`prefix_/\`$prefix/g" $local_path/installer/sql/create-mysql.sql > ./structure.sql +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user +ynh_system_user_create $app + +#================================================= +# PHP-FPM CONFIGURATION +#================================================= + +# Create a dedicated php-fpm config +ynh_add_fpm_config + +#================================================= +# SPECIFIC SETUP +#================================================= +# CONFIGURE +#================================================= +ynh_configure config.php "$final_path/application/config/config.php" + +#================================================= +# LOAD SQL CONFIG +#================================================= +cp $final_path/installer/sql/create-mysql.sql ./structure.sql +ynh_replace_string "\`prefix_" "\`$prefix" ./structure.sql mysql -u $db_user -p$db_pwd $db_user < ./structure.sql ynh_configure data.sql ./data.sql mysql -u $db_user -p$db_pwd $db_user < ./data.sql -# Randomize Password user -ls_cli=$local_path/application/commands/console.php -set +x -ynh_exec_as "$user" php $ls_cli resetpassword "$admin" "$(ynh_string_random 24)" -set -x +#================================================= +# Add nice themes +#================================================= +ynh_setup_source "$final_path/upload/templates/libreform" libreform +#ynh_setup_source "$final_path/upload/templates/librepoll" librepoll + +#================================================= +# STORE THE CHECKSUM OF THE CONFIG FILE +#================================================= + +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/application/config/config.php" + +#================================================= +# GENERIC FINALISATION +#================================================= +# SECURING FILES AND DIRECTORIES +#================================================= # Set permissions -ynh_set_default_perm $local_path -sudo chmod -R u+w $local_path/tmp -sudo chmod -R u+w $local_path/upload -sudo chmod -R u+w $local_path/application/config/ +set_permissions -sudo yunohost app addaccess $app -u $admin +#================================================= +# Randomize Password user +#================================================= +# Permission should be correctly set before to do this +ls_cli=$final_path/application/commands/console.php +set +x +ynh_exec_as "$app" php $ls_cli resetpassword "$admin" "$(ynh_string_random 24)" +set -x + +#================================================= +# SETUP FAIL2BAN +#================================================= + +#ynh_add_fail2ban_config "/var/log/nginx/${domain}-error.log" "PHP message: Leed: wrong login for .* client: " 5 + +#================================================= +# SETUP SSOWAT +#================================================= +yunohost app addaccess $app -u $admin ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts" -ynh_configure_php_fpm -ynh_configure_nginx +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx + +#================================================= +# SEND A README FOR THE ADMIN +#================================================= +ynh_print_OFF +message="You can now create a poll on this address: https://${domain}${path_url}/admin/ +If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/libresurvey_ynh" + +ynh_send_readme_to_admin "$message" "$admin" +ynh_print_ON diff --git a/scripts/remove b/scripts/remove index 3b89d91..6e457e5 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,27 +1,68 @@ #!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + source /usr/share/yunohost/helpers source _common.sh +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME -user=$app -local_path=$(ynh_app_setting_get $app local_path) + +final_path=$(ynh_app_setting_get $app final_path) +final_path=${final_path:-/var/www/$app} domain=$(ynh_app_setting_get $app domain) +db_name=$(ynh_app_setting_get $app db_name) -ynh_mysql_remove_db "$user" "$app" +#================================================= +# STANDARD REMOVE +#================================================= +# REMOVE DEPENDENCIES +#================================================= +# Remove metapackage and its dependencies +ynh_remove_app_dependencies -ynh_secure_rm "$local_path" -ynh_secure_rm "/home/yunohost.app/$app" +#================================================= +# REMOVE THE SQL BDD +#================================================= -ynh_rm_nginx_conf -ynh_rm_php_fpm_conf +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db $db_name $db_name -# Delete user after php5-fpm is restarted without the app conf -# We can't delete it before because php5-fpm use it -ynh_system_user_delete "$user" +#================================================= +# REMOVE THE MAIN DIR OF THE APP +#================================================= -dep_app=${app/__/-} -ynh_package_remove $dep_app-ynh-deps +# Remove the app directory securely +ynh_secure_remove "$final_path" +ynh_secure_remove "/home/yunohost.app/$app" -sudo yunohost app ssowatconf -echo -e "\e[0m" # Restore norml color +#================================================= +# REMOVE THE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# REMOVE THE PHP-FPM CONFIGURATION +#================================================= + +# Remove the dedicated php-fpm config +ynh_remove_fpm_config + +#================================================= +# GENERIC FINALISATION +#================================================= +# REMOVE DEDICATED USER +#================================================= + +# Delete a system user +ynh_system_user_delete $app diff --git a/scripts/restore b/scripts/restore index d580474..44268e3 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,527 +1,94 @@ #!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + source /usr/share/yunohost/helpers -#source ../settings/scripts/_common.sh +source _common.sh -#================================================ +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= -# App package root directory should be the parent folder -PKG_DIR=$(cd ../; pwd) +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors -ynh_check_var () { - test -n "$1" || ynh_die "$2" -} - -ynh_exit_properly () { - exit_code=$? - if [ "$exit_code" -eq 0 ]; then - exit 0 - fi - trap '' EXIT - set +eu - echo -e "\e[91m \e[1m" - err "$app script has encountered an error." - - if type -t CLEAN_SETUP > /dev/null; then - CLEAN_SETUP - fi - - ynh_die -} - -# Activate signal capture -# Exit if a command fail, and if a variable is used unset. -# Capturing exit signals on shell script -# -# example: CLEAN_SETUP () { -# # Clean residual file un remove by remove script -# } -# ynh_trap_on -ynh_trap_on () { - set -eu - trap ynh_exit_properly EXIT # Capturing exit signals on shell script -} - -ynh_export () { - local ynh_arg="" - for var in $@; - do - ynh_arg=$(echo $var | awk '{print toupper($0)}') - ynh_arg="YNH_APP_ARG_$ynh_arg" - export $var=${!ynh_arg} - done -} - -# Check availability of a web path -# -# example: ynh_path_validity $domain$path -# -# usage: ynh_path_validity $domain_and_path -# | arg: domain_and_path - complete path to check -ynh_path_validity () { - sudo yunohost app checkurl $1 -a $app -} - -# Normalize the url path syntax -# Handle the slash at the beginning of path and its absence at ending -# Return a normalized url path -# -# example: url_path=$(ynh_normalize_url_path $url_path) -# ynh_normalize_url_path example -> /example -# ynh_normalize_url_path /example -> /example -# ynh_normalize_url_path /example/ -> /example -# -# usage: ynh_normalize_url_path path_to_normalize -# | arg: url_path_to_normalize - URL path to normalize before using it -ynh_normalize_url_path () { - path=$1 - test -n "$path" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing." - if [ "${path:0:1}" != "/" ]; then # If the first character is not a / - path="/$path" # Add / at begin of path variable - fi - if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # If the last character is a / and that not the only character. - path="${path:0:${#path}-1}" # Delete the last character - fi - echo $path -} - -# Check the path doesn't exist -# usage: ynh_local_path_available PATH -ynh_local_path_available () { - if [ -e "$1" ] - then - ynh_die "This path '$1' already contains a folder" - fi -} - -# Save listed var in YunoHost app settings -# usage: ynh_save_args VARNAME1 [VARNAME2 [...]] -ynh_save_args () { - for var in $@; - do - ynh_app_setting_set $app $var ${!var} - done -} - -# Create a database, an user and its password. Then store the password in the app's config -# -# User of database will be store in db_user's variable. -# Name of database will be store in db_name's variable. -# And password in db_pwd's variable. -# -# usage: ynh_mysql_generate_db user name -# | arg: user - Proprietary of the database -# | arg: name - Name of the database -ynh_mysql_generate_db () { - export db_user=${1//[-.]/_} # Mariadb doesn't support - and . in the name of databases. It will be replace by _ - export db_name=${2//[-.]/_} - - export db_pwd=$(ynh_string_random) # Generate a random password - ynh_check_var "$db_pwd" "db_pwd empty" - - ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database - - ynh_app_setting_set $app mysqlpwd $db_pwd # Store the password in the app's config -} - -# Execute a command as another user -# usage: ynh_exec_as USER COMMAND [ARG ...] -ynh_exec_as() { - local USER=$1 - shift 1 - - if [[ $USER = $(whoami) ]]; then - eval "$@" - else - # use sudo twice to be root and be allowed to use another user - sudo sudo -u "$USER" "$@" - fi -} - -# Get sources, setup it into dest directory and deploy patches -# Try to find locally the sources and download it if missing. -# Check the integrity with an hash program (default: sha256sum) -# Source hash and location are get from a "SOURCE_ID.src" file, -# by default the SOURCE_ID is "app". -# Patches should be located in a "patches" dir, they should be -# named like "SOURCE_ID-*.patch". -# -# example: ynh_setup_source "/var/www/limesurvey/" "limesurvey" -# -# usage: ynh_setup_source DEST_DIR [USER [SOURCE_ID]] - -ynh_setup_source () { - local DEST=$1 - local AS_USER=${2:-admin} - local SOURCE_ID=${3:-app} - local SOURCE_FILE="$YNH_APP_ID.tar.gz" - local SUM_PRG="sha256sum" - source ../$SOURCE_ID.src - local LOCAL_SOURCE="/opt/yunohost-apps-src/$YNH_APP_ID/$SOURCE_FILE" - - if test -e $LOCAL_SOURCE; then - cp $LOCAL_SOURCE $SOURCE_FILE - else - wget -nv $SOURCE_URL -O $SOURCE_FILE - fi - echo "$SOURCE_SUM $SOURCE_FILE" |$SUM_PRG -c --status \ - || ynh_die "Corrupt source" - - sudo mkdir -p "$DEST" - sudo chown $AS_USER: "$DEST" - if [ "$(echo ${SOURCE_FILE##*.})" == "gz" ]; then - ynh_exec_as "$AS_USER" tar xf $SOURCE_FILE -C "$DEST" --strip-components 1 - elif [ "$(echo ${SOURCE_FILE##*.})" == "bz2" ]; then - ynh_exec_as "$AS_USER" tar xjf $SOURCE_FILE -C "$DEST" --strip-components 1 - elif [ "$(echo ${SOURCE_FILE##*.})" == "zip" ]; then - mkdir -p "/tmp/$SOURCE_FILE" - ynh_exec_as "$AS_USER" unzip -q $SOURCE_FILE -d "/tmp/$SOURCE_FILE" - ynh_exec_as "$AS_USER" mv "/tmp/$SOURCE_FILE"/./. "$DEST" - rmdir "$/tmp/$SOURCE_FILE" - else - false - fi - - # Apply patches - if [ -f ${PKG_DIR}/patches/$SOURCE_ID-*.patch ]; then - (cd "$DEST" \ - && for p in ${PKG_DIR}/patches/$SOURCE_ID-*.patch; do \ - ynh_exec_as "$AS_USER" patch -p1 < $p; done) \ - || ynh_die "Unable to apply patches" - - fi - - # Apply persistent modules (upgrade only) - ynh_restore_persistent modules - - # Apply persistent data (upgrade only) - ynh_restore_persistent data - -} - -# TODO support SOURCE_ID -ynh_save_persistent () { - local TYPE=$1 - local DIR=/tmp/ynh-persistent/$TYPE/$app/app - sudo mkdir -p $DIR - sudo touch $DIR/dir_names - shift - i=1 - for PERSISTENT_DIR in $@; - do - if [ -e $local_path/$PERSISTENT_DIR ]; then - sudo mv $local_path/$PERSISTENT_DIR $DIR/$i - sudo su -c "echo -n '$PERSISTENT_DIR ' >> $DIR/dir_names" - ((i++)) - fi - done -} - -# TODO support SOURCE_ID -ynh_restore_persistent () { - local TYPE=$1 - local DIR=/tmp/ynh-persistent/$TYPE/$app/app - shift - if [ -d $DIR ]; then - i=1 - for PERSISTENT_DIR in $(cat $DIR/dir_names); - do - if [ "$TYPE" = "modules" ]; then - for updated_subdir in $(ls $local_path/$PERSISTENT_DIR); - do - sudo rm -Rf $DIR/$i/$updated_subdir - done - fi - if [ -d $DIR/$i ]; then - sudo mv $DIR/$i/* $local_path/$PERSISTENT_DIR/ 2> /dev/null || true - else - sudo mv $DIR/$i $local_path/$PERSISTENT_DIR 2> /dev/null || true - fi - ((i++)) - done - sudo rm -Rf $DIR - fi - -} -ynh_mv_to_home () { - local APP_PATH="/home/yunohost.app/$app/" - local DATA_PATH="$1" - sudo mkdir -p "$APP_PATH" - sudo chown $app: "$APP_PATH" - ynh_exec_as "$app" mv "$DATA_PATH" "$APP_PATH" - ynh_exec_as "$app" ln -s "$APP_PATH$DATA_PATH" "$DATA_PATH" - -} - -ynh_set_default_perm () { - local DIRECTORY=$1 - # Set permissions - sudo chown -R $app:$app $DIRECTORY - sudo chmod -R 664 $DIRECTORY - sudo find $DIRECTORY -type d -print0 | xargs -0 sudo chmod 775 \ - || echo "No file to modify" - -} -ynh_sso_access () { - ynh_app_setting_set $app unprotected_uris "/" - - if [[ $is_public -eq 0 ]]; then - ynh_app_setting_set $app protected_uris "$1" - fi - sudo yunohost app ssowatconf -} - -ynh_exit_if_up_to_date () { - if [ "${version}" = "${last_version}" ]; then - info "Up-to-date, nothing to do" - exit 0 - fi -} - -log() { - echo "${1}" -} - -info() { - log "[INFO] ${1}" -} - -warn() { - log "[WARN] ${1}" -} - -err() { - log "[ERR] ${1}" -} - -to_logs() { - - # When yunohost --verbose or bash -x - if $_ISVERBOSE; then - cat - else - cat > /dev/null - fi -} - -ynh_read_json () { - sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" -} - -ynh_read_manifest () { - if [ -f '../manifest.json' ] ; then - ynh_read_json '../manifest.json' "$1" - else - ynh_read_json '../settings/manifest.json' "$1" - fi -} - -ynh_app_dependencies (){ - export dependencies=$1 - export project_url=$(ynh_read_manifest 'url') - export version=$(ynh_read_manifest 'version') - export dep_app=${app/__/-} - mkdir -p ../conf - cat > ../conf/app-ynh-deps.control.j2 << EOF -Section: misc -Priority: optional -Homepage: {{ project_url }} -Standards-Version: 3.9.2 - -Package: {{ dep_app }}-ynh-deps -Version: {{ version }} -Depends: {{ dependencies }} -Architecture: all -Description: meta package for {{ app }} (YunoHost app) dependencies - This meta-package is only responsible of installing its dependencies. -EOF - - ynh_configure app-ynh-deps.control ./$dep_app-ynh-deps.control - ynh_package_install_from_equivs ./$dep_app-ynh-deps.control \ - || ynh_die "Unable to install dependencies" -} - - - - -# Create a system user -# -# usage: ynh_system_user_create user_name [home_dir] -# | arg: user_name - Name of the system user that will be create -# | arg: home_dir - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home -ynh_system_user_create () { - if ! ynh_system_user_exists "$1" # Check if the user exists on the system - then # If the user doesn't exist - if [ $# -ge 2 ]; then # If a home dir is mentioned - user_home_dir="-d $2" - else - user_home_dir="--no-create-home" - fi - sudo useradd $user_home_dir --system --user-group $1 --shell /usr/sbin/nologin || ynh_die "Unable to create $1 system account" - fi -} - -# Delete a system user -# -# usage: ynh_system_user_delete user_name -# | arg: user_name - Name of the system user that will be create -ynh_system_user_delete () { - if ynh_system_user_exists "$1" # Check if the user exists on the system - then - sudo userdel $1 - else - echo "The user $1 was not found" >&2 - fi -} - - -ynh_configure () { - local TEMPLATE=$1 - local DEST=$2 - type j2 2>/dev/null || sudo pip install j2cli - j2 "${PKG_DIR}/conf/$TEMPLATE.j2" > "${PKG_DIR}/conf/$TEMPLATE" - sudo cp "${PKG_DIR}/conf/$TEMPLATE" "$DEST" -} - -ynh_configure_nginx () { - ynh_configure nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf - sudo service nginx reload -} - -ynh_configure_php_fpm () { - finalphpconf=/etc/php5/fpm/pool.d/$app.conf - ynh_configure php-fpm.conf /etc/php5/fpm/pool.d/$app.conf - sudo chown root: $finalphpconf - - finalphpini=/etc/php5/fpm/conf.d/20-$app.ini - sudo cp ../conf/php-fpm.ini $finalphpini - sudo chown root: $finalphpini - - sudo service php5-fpm reload -} - -# Find a free port and return it -# -# example: port=$(ynh_find_port 8080) -# -# usage: ynh_find_port begin_port -# | arg: begin_port - port to start to search -ynh_find_port () { - port=$1 - test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port." - while netcat -z 127.0.0.1 $port # Check if the port is free - do - port=$((port+1)) # Else, pass to next port - done - echo $port -} - - -### REMOVE SCRIPT - -# Remove a database if it exist and the associated user -# -# usage: ynh_mysql_remove_db user name -# | arg: user - Proprietary of the database -# | arg: name - Name of the database -ynh_mysql_remove_db () { - if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $2"; then # Check if the database exist - ynh_mysql_drop_db $2 # Remove the database - ynh_mysql_drop_user $1 # Remove the associated user to database - else - echo "Database $2 not found" >&2 - fi -} - -ynh_rm_nginx_conf () { - if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then - sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" - sudo service nginx reload - fi -} - -ynh_rm_php_fpm_conf () { - if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then - sudo rm "/etc/php5/fpm/pool.d/$app.conf" - fi - if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then - sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" - fi - sudo service php5-fpm reload -} - -REMOVE_LOGROTATE_CONF () { - if [ -e "/etc/logrotate.d/$app" ]; then - sudo rm "/etc/logrotate.d/$app" - fi -} - -ynh_secure_rm () { - [[ "/var/www /opt /home/yunohost.app" =~ $1 ]] \ - || (test -n "$1" && sudo rm -Rf $1 ) -} - - -ynh_check_restore () { - for dest in $(cat ./list| cut -d ' ' -f2); - do - ([[ -e $dest ]] && ynh_die \ -"The destination directory '$dest' already exists.\ -You should safely delete it before restoring this app.") || true - done -} - -ynh_restore () { - while IFS= read -r instruction - do - sudo cp -a ./$instruction - done < ./list -} -#================================================ - -ynh_trap_on +#================================================= +# LOAD SETTINGS +#================================================= export app=$YNH_APP_INSTANCE_NAME -user=$app export domain=$(ynh_app_setting_get $app domain) -export path=$(ynh_app_setting_get $app path) +export path_url=$(ynh_app_setting_get $app path_url) export admin=$(ynh_app_setting_get $app admin) -dbpass=$(ynh_app_setting_get $app mysqlpwd) -export local_path=$(ynh_app_setting_get $app local_path) +export final_path=$(ynh_app_setting_get $app final_path) export is_public=$(ynh_app_setting_get $app is_public) export prefix=$(ynh_app_setting_get $app prefix) -dbname=$app -dbuser=$user +export db_name=$(ynh_app_setting_get $app db_name) +export db_user=$(ynh_app_setting_get $app db_user) +export db_pwd=$(ynh_app_setting_get $app mysqlpwd) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -#ynh_path_validity "$domain$path" -ynh_check_restore +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 " #================================================= -# RESTORE THE APP BY MODIFYING THE SYSTEM +# STANDARD RESTORE STEPS #================================================= -ynh_app_dependencies php5-imap +# INSTALL DEPENDENCIES +#================================================= +ynh_install_app_dependencies $pkg_dependencies -ynh_system_user_create "$user" "$local_path" +#================================================= +# RESTORE OF THE SQL BDD +#================================================= -# Create and restore the database -ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" -ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql +ynh_mysql_setup_db $db_name $db_name $db_pwd +ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql -# Restore file +#================================================= +# RESTORE FILES +#================================================= +# Restore files ynh_restore -# Fix app ownerships & permissions -ynh_set_default_perm $local_path -sudo chmod -R u+w $local_path/tmp -sudo chmod -R u+w $local_path/upload -sudo chmod -R u+w $local_path/application/config/ +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_system_user_create "$app" "$final_path" +#================================================= +# RESTORE USER RIGHTS +#================================================= +set_permissions + +#================================================= +# SETUP SSOWAT +#================================================= ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts" -# Reload services -sudo service php5-fpm restart || true -sudo service nginx reload || true +#================================================= +# GENERIC FINALISATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= + +ynh_system_reload php5-fpm +ynh_system_reload nginx + +#================================================= +# SEND A README FOR THE ADMIN +#================================================= + +message="If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/leed_ynh" + +ynh_send_readme_to_admin "$message" "$admin" diff --git a/scripts/upgrade b/scripts/upgrade index ab7bd87..2197b88 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,70 +1,128 @@ #!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + source /usr/share/yunohost/helpers source _common.sh -ynh_trap_on - +#================================================= +# LOAD SETTINGS +#================================================= export app=$YNH_APP_INSTANCE_NAME -user=$app export domain=$(ynh_app_setting_get $app domain) -export path=$(ynh_app_setting_get $app path) +export path_url=$(ynh_app_setting_get $app path) export admin=$(ynh_app_setting_get $app admin) -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -export local_path=$(ynh_app_setting_get $app local_path) +export final_path=$(ynh_app_setting_get $app final_path) export is_public=$(ynh_app_setting_get $app is_public) -is_public=${is_public:-0} export prefix=$(ynh_app_setting_get $app prefix) -prefix=${prefix:-prefix_} -version=$(ynh_read_json "/etc/yunohost/apps/$app/manifest.json" 'version' 2> /dev/null || echo '2.0.5') -last_version=$(ynh_read_manifest 'version') +export db_pwd=$(ynh_app_setting_get $app mysqlpwd) +export db_name=$(ynh_app_setting_get $app db_name) +export db_user=$(ynh_app_setting_get $app db_user) -ynh_exit_if_up_to_date -ynh_check_var "$app" "app name not set" -ynh_user_exists "$admin" || err "User does not exist: $admin" -ynh_normalize_url_path "$path" +#================================================= +# CHECK VERSION +#================================================= -if [ "${version}" = "2.0.5" ]; then +ynh_abort_if_up_to_date - ynh_save_args path is_public prefix +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= - ynh_app_dependencies php5-imap +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors - ynh_system_user_create "$user" "$local_path" +#================================================= +# CHECK THE PATH +#================================================= - # Move the upload dir to local_path if needed +path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path. + +#================================================= +# STEP Migrations +#================================================= +if ynh_version_le "2.0.5" ; then + is_public=${is_public:-0} + prefix=${prefix:-prefix_} + db_name=${db_name:-$app} + final_path=$(ynh_app_setting_get $app local_path) + ynh_save_args path_url is_public prefix db_name final_path db_user + + ynh_install_app_dependencies $pkg_dependencies + + # Move the upload dir to final_path if needed # The upload dir can't be symlinked in home (not supported by LS) upload_path=/home/yunohost.app/$app/upload - if [ -h $local_path/upload ]; then - sudo rm $local_path/upload - sudo mv $upload_path $local_path/ + if [ -h $final_path/upload ]; then + rm $final_path/upload + mv $upload_path $final_path/ fi ynh_app_setting_delete $app skipped_uris ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts" - ynh_configure_php_fpm - ynh_configure_nginx - ynh_configure migrations/2.0.5.sql ./2.0.5.sql - mysql -u $app -p$db_pwd $app < ./2.0.5.sql + mysql -u $app -p$db_pwd $db_name < ./2.0.5.sql fi +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + # Backup config, plugins and themes and delete previous files ynh_save_persistent modules themes plugins ynh_save_persistent data application/config/config.php upload # Copie new files and restore config, plugins, upload and themes -sudo rm -Rf $local_path -ynh_setup_source "$local_path" "$user" +ynh_secure_remove $final_path +ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path -# Set permissions -ynh_set_default_perm $local_path -sudo chmod -R u+w $local_path/tmp -sudo chmod -R u+w $local_path/upload -sudo chmod -R u+w $local_path/application/config/ +#================================================= +# NGINX CONFIGURATION +#================================================= + +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +ynh_system_user_create $app # Create the dedicated user, if not exist + +#================================================= +# PHP-FPM CONFIGURATION +#================================================= + +ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure. + +#================================================= +# SECURING FILES AND DIRECTORIES +#================================================= +set_permissions + +#================================================= +# UPGRADE DB +#================================================= # Migrate DB -cd $local_path/application/commands +cd $final_path/application/commands ynh_exec_as "$app" php console.php update +#================================================= +# RELOAD NGINX +#================================================= + +ynh_system_reload nginx From b0007adb3fa1efd6650b9fe5754805bf5cd844b3 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 01:45:08 +0100 Subject: [PATCH 02/13] [fix] Root installation --- conf/nginx.conf.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conf/nginx.conf.j2 b/conf/nginx.conf.j2 index 608d752..48d4af7 100644 --- a/conf/nginx.conf.j2 +++ b/conf/nginx.conf.j2 @@ -1,5 +1,7 @@ {% if path_url != "/" %} rewrite ^{{ path_url }}$ {{ path_url }}/ permanent; +{% else %} +{% set path_url = "" %} {% endif %} location {{ path_url }}/ { alias {{ final_path }}/; From 4b522fac7b5d054e7244a6801c89183720bc6121 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 01:54:43 +0100 Subject: [PATCH 03/13] [fix] Php fpm ini not set --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 51a92e4..94ba024 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -231,7 +231,7 @@ ynh_add_fpm_config () { sudo chown root: "$finalphpconf" ynh_store_file_checksum "$finalphpconf" - if [ -e "../conf/php-fpm.ini" ] + if [ -e "../conf/php-fpm.ini.j2" ] then finalphpini="$fpm_config_dir/conf.d/20-$app.ini" ynh_backup_if_checksum_is_different "$finalphpini" From 00cc3924559bf37913076dff725c25b3824674c9 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 02:19:52 +0100 Subject: [PATCH 04/13] [fix] Can't read manifest --- manifest.json | 2 +- scripts/_common.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index 535c4fb..ca61c03 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name": "LibreSurvey", "id": "libresurvey", "packaging_format": 1, - "version": "2.62.5-1", + "version": "2.62.5-2", "description": { "en": "LibreSurvey is used to create advanced poll.", "fr": "LibreSurvey est un outil de création et diffusion de sondage en ligne." diff --git a/scripts/_common.sh b/scripts/_common.sh index 94ba024..74184b7 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -305,8 +305,8 @@ ynh_abort_if_up_to_date () { local force_upgrade=${YNH_FORCE_UPGRADE:-0} local package_check=${PACKAGE_CHECK_EXEC:-0} - local version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) - local last_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0) + local version=$(ynh_read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) + local last_version=$(ynh_read_manifest "version" || echo 1.0) if [ "$version" = "$last_version" ] then if [ "$force_upgrade" != "0" ] From c513ef35afcd16f27a5a860557e1c9403fd144f8 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 03:32:18 +0100 Subject: [PATCH 05/13] [fix] Patch unapplied --- scripts/restore | 4 ++-- {patches => sources/patches}/app-0001-7ca4932.patch | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename {patches => sources/patches}/app-0001-7ca4932.patch (100%) diff --git a/scripts/restore b/scripts/restore index 44268e3..25ae50a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -7,7 +7,7 @@ #================================================= source /usr/share/yunohost/helpers -source _common.sh +source ../settings/scripts/_common.sh #================================================= # MANAGE SCRIPT FAILURE @@ -23,7 +23,7 @@ ynh_abort_if_errors export app=$YNH_APP_INSTANCE_NAME export domain=$(ynh_app_setting_get $app domain) -export path_url=$(ynh_app_setting_get $app path_url) +export path_url=$(ynh_app_setting_get $app path) export admin=$(ynh_app_setting_get $app admin) export final_path=$(ynh_app_setting_get $app final_path) export is_public=$(ynh_app_setting_get $app is_public) diff --git a/patches/app-0001-7ca4932.patch b/sources/patches/app-0001-7ca4932.patch similarity index 100% rename from patches/app-0001-7ca4932.patch rename to sources/patches/app-0001-7ca4932.patch From f2edb507ad8ebc8234ffa4246ee15812e5e95686 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 03:32:46 +0100 Subject: [PATCH 06/13] [fix] Restore and some error in upgrade --- scripts/_common.sh | 28 ++++++++++++++++++++-------- scripts/upgrade | 4 ++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 74184b7..5726f72 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -53,8 +53,8 @@ ynh_export () { } # Check the path doesn't exist -# usage: ynh_local_path_available PATH -ynh_local_path_available () { +# usage: ynh_final_path_available PATH +ynh_final_path_available () { if [ -e "$1" ] then ynh_die "This path '$1' already contains a folder" @@ -99,8 +99,8 @@ ynh_save_persistent () { i=1 for PERSISTENT_DIR in $@; do - if [ -e $local_path/$PERSISTENT_DIR ]; then - mv $local_path/$PERSISTENT_DIR $DIR/$i + if [ -e $final_path/$PERSISTENT_DIR ]; then + mv $final_path/$PERSISTENT_DIR $DIR/$i echo -n '$PERSISTENT_DIR ' >> $DIR/dir_names ((i++)) fi @@ -117,15 +117,15 @@ ynh_restore_persistent () { for PERSISTENT_DIR in $(cat $DIR/dir_names); do if [ "$TYPE" = "modules" ]; then - for updated_subdir in $(ls $local_path/$PERSISTENT_DIR); + for updated_subdir in $(ls $final_path/$PERSISTENT_DIR); do ynh_secure_remove $DIR/$i/$updated_subdir done fi if [ -d $DIR/$i ]; then - mv $DIR/$i/* $local_path/$PERSISTENT_DIR/ 2> /dev/null || true + mv $DIR/$i/* $final_path/$PERSISTENT_DIR/ 2> /dev/null || true else - mv $DIR/$i $local_path/$PERSISTENT_DIR 2> /dev/null || true + mv $DIR/$i $final_path/$PERSISTENT_DIR 2> /dev/null || true fi ((i++)) done @@ -344,7 +344,7 @@ ynh_version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } # # usage: ynh_version_le "0.5" ynh_version_le() { - local version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) + local version=$(ynh_read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) ynh_version_gt "$1" "${version}" } @@ -370,3 +370,15 @@ is_jessie () { fi } +# Reload (or other actions) a service and print a log in case of failure. +# +# usage: ynh_system_reload service_name [action] +# | arg: service_name - Name of the service to reload +# | arg: action - Action to perform with systemctl. Default: reload +ynh_system_reload () { + local service_name=$1 + local action=${2:-reload} + + # Reload, restart or start and print the log if the service fail to start or reload + systemctl $action $service_name || ( journalctl --lines=20 -u $service_name >&2 && false) +} diff --git a/scripts/upgrade b/scripts/upgrade index 2197b88..efbbf81 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -90,6 +90,10 @@ ynh_save_persistent data application/config/config.php upload ynh_secure_remove $final_path ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path +# Restore config, plugins and themes +ynh_restore_persistent modules +ynh_restore_persistent data + #================================================= # NGINX CONFIGURATION #================================================= From 44cf2750ae9f8caf6207586fc45c25123da06c73 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 03:33:09 +0100 Subject: [PATCH 07/13] [enh] Add YEP list --- YEP.md | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 YEP.md diff --git a/YEP.md b/YEP.md new file mode 100644 index 0000000..df930fe --- /dev/null +++ b/YEP.md @@ -0,0 +1,117 @@ +#### [Level 0](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-0) +[YEP 1.1 - Nommer son app et son dépot](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) +`Validated` +[YEP 1.2 - Inscrire l'app sur un "répertoire" connu](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-12) +`Validated` + +#### [Level 1](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-1) +[YEP 2.2 - Utiliser bash pour les scripts principaux](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-22) +`Validated` +[YEP 2.5 - Copier correctement des fichiers](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-25) +`Don't know` +[YEP 2.7 - Donner des permissions suffisantes aux instructions bash](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-27) +`Validated` +[YEP 2.15 - Suivre les instructions d'installation de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-215) +`Validated` + +#### [Level 2](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-2) +[YEP 1.5 - Mettre à jour régulièrement le statut de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) +`Validated` +[YEP 2.18.2 - Gérer l'installation à la racine d’un nom de domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2182) +`Validated` - *Automatically verified.* +[YEP 2.18.3 - Gérer l'installation sur un sous-domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2183) +`Validated` - *Automatically verified.* +[YEP 2.18.4 - Gérer l'installation sur un chemin /path](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2184) +`Validated` - *Automatically verified.* +[YEP 4.6 - Gère le multi-instance](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) +`Validated` - *Automatically verified.* + +#### [Level 3](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-3) +[YEP 2.3 - Sauvegarder les réponses lors de l'installation](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-23) +`Validated` + +#### [Level 4](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-4) +[YEP 4.1 - Lier au ldap](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-41) +`Validated` +[YEP 4.2 - Lier l'authentification au sso](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-42) +`Validated` + +#### [Level 5](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-5) +[YEP 1.3 - Indiquer la licence associée au paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-13) +`Validated` +[YEP 2.1 - Respecter le format du manifeste](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-21) +`Validated` - *Automatically verified.* +[YEP 2.12 - Utiliser les commandes pratiques (helpers)](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-212) +`Validated` +[YEP 2.18.1 - Lancer le script d'installation d'une webapp correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2181) +`Validated` + +#### [Level 6](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-6) +[YEP 1.4 - Informer sur l'intention de maintenir un paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-14) +`Validated` +[YEP 1.6 - Se tenir informé sur l'évolution du packaging d'apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-16) +`Validated` +[YEP 1.7 - Ajouter l'app à l'organisation YunoHost-Apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-17) +`Validated` - *Automatically verified.* +[YEP 1.8 - Publier des demandes de test](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-18) +`Not yet validated` +[YEP 1.9 - Documenter l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-19) +`Validated` +[YEP 1.10 - Garder un historique de version propre](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-110) +`Not yet validated` +[YEP 2.9 - Enlever toutes traces de l'app lors de la suppression](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-29) +`Validated` +[YEP 3.3 - Faciliter le contrôle de l'intégrité des sources](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-33) +`Validated` +[YEP 3.5 - Suivre les recommendations de la documentation de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-35) +`Validated` +[YEP 3.6 - Mettre à jour les versions contenant des CVE](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-36) +`Validated` +[YEP 4.3 - Fournir un script de sauvegarde YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-43) +`Validated` - *Automatically verified.* +[YEP 4.4 - Fournir un script de restauration YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-44) +`Validated` - *Automatically verified.* + +#### [Level 7](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-7) +[YEP 2.6 - Annuler l'action si les valeurs d'entrées sont incorrectes](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-26) +`Validated` +[YEP 3.2 - Ouvrir un port correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-32) +`Not applicable` + +#### [Level 8](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-8) +[YEP 2.4 - Détecter et gérer les erreurs](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-24) +`Validated` +[YEP 2.8 - Modifier correctement une configuration système](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-28) +`Validated` +[YEP 2.16 - Vérifier la disponibilité des dépendances sur ARM, x86 et x64](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-216) +`Not yet validated` - *Automatically verified.* +[YEP 2.18.5 - Gérer la tuile YunoHost pour faciliter la navigation entre les applications](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2185) +`Validated` +[YEP 3.4 - Isoler l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-34) +`Partially validated` +[YEP 4.5 - Utiliser les hooks](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-45) +`Validated` + +#### [Level 9](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-9) +[YEP 2.10 - Configurer les logs de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-210) +`Not applicable` +[YEP 2.11 - Utiliser une variable plutôt que l'app id directement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-211) +`Validated` +[YEP 2.13 - Traduire le paquet en anglais](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-213) +`Validated` +[YEP 2.14 - Remplir correctement un fichier de conf](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-214) +`Validated` +[YEP 2.17 - Prendre en compte la version d'origine lors des mises à jour](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-217) +`Validated` +[YEP 4.2.1 - Déconnexion](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-421) +`Not yet validated` + +#### Other YEP +[YEP 3.1 - Ne pas demander ou stocker de mot de passe LDAP](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-31) +`Validated` +[YEP 4.7 - Ajouter un module à la CLI](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-47) +`Not applicable` +[YEP 4.8 - Ajouter un module à l'admin web](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-48) +`Not applicable` + +State of each YEP can be one of these: `Validated`, `Partially validated`, `Not yet validated`, `Not applicable`, `Don't know`. From a451e536d79ff0d2b73f3c0d888243a567e7c77e Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 03:38:17 +0100 Subject: [PATCH 08/13] [fix] Rename in LimeSurvey --- README.md | 26 +++++++++++++------------- manifest.json | 30 +++++++++++++++--------------- scripts/install | 2 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index fb32475..7ff9f1b 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# LibreSurvey for YunoHost +# LimeSurvey for YunoHost -[![Integration level](https://dash.yunohost.org/integration/libresurvey.svg)](https://ci-apps.yunohost.org/jenkins/job/libresurvey%20%28Community%29/lastBuild/consoleFull) -[![Install LibreSurvey with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=libresurvey) +[![Integration level](https://dash.yunohost.org/integration/limesurvey.svg)](https://ci-apps.yunohost.org/jenkins/job/limesurvey%20%28Community%29/lastBuild/consoleFull) +[![Install LimeSurvey with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=limesurvey) -> *This package allow you to install LibreSurvey quickly and simply on a YunoHost server. +> *This package allow you to install LimeSurvey 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.* ## Overview -LibreSurvey is used to create advanced poll. +LimeSurvey is used to create advanced poll. **Shipped version:** 2.62.5 @@ -19,7 +19,7 @@ LibreSurvey is used to create advanced poll. ## Configuration -Before to run the install YunoHost ask you an admin user, you can use it to connecte you on https://your_libresurvey_url/admin/ +Before to run the install YunoHost ask you an admin user, you can use it to connecte you on https://your_limesurvey_url/admin/ ## Documentation @@ -38,8 +38,8 @@ Not supported. #### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/libresurvey%20(Community)/) -* ARMv8-A - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/libresurvey%20(Community)%20(%7EARM%7E)/) +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/limesurvey%20(Community)/) +* ARMv8-A - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/limesurvey%20(Community)%20(%7EARM%7E)/) ## Limitations @@ -47,8 +47,8 @@ Not supported. ## Links - * Report a bug: https://github.com/YunoHost-Apps/libresurvey_ynh/issues - * LibreSurvey is a fork of LimeSurvey https://www.limesurvey.org + * Report a bug: https://github.com/YunoHost-Apps/limesurvey_ynh/issues + * Website: https://www.limesurvey.org * YunoHost website: https://yunohost.org/ --- @@ -60,12 +60,12 @@ Developers infos **Patches author:** Shnoulle -Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/libresurvey_ynh/tree/testing). +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/limesurvey_ynh/tree/testing). To try the testing branch, please proceed like that. ``` -sudo yunohost app install https://github.com/YunoHost-Apps/libresurvey_ynh/tree/testing --verbose +sudo yunohost app install https://github.com/YunoHost-Apps/limesurvey_ynh/tree/testing --verbose or -sudo yunohost app upgrade leed -u https://github.com/YunoHost-Apps/libresurvey_ynh/tree/testing --verbose +sudo yunohost app upgrade leed -u https://github.com/YunoHost-Apps/limesurvey_ynh/tree/testing --verbose ``` diff --git a/manifest.json b/manifest.json index ca61c03..2204ba9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,16 +1,16 @@ { - "name": "LibreSurvey", - "id": "libresurvey", + "name": "LimeSurvey", + "id": "limesurvey", "packaging_format": 1, "version": "2.62.5-2", "description": { - "en": "LibreSurvey is used to create advanced poll.", - "fr": "LibreSurvey est un outil de création et diffusion de sondage en ligne." + "en": "LimeSurvey is used to create advanced poll.", + "fr": "LimeSurvey est un outil de création et diffusion de sondage en ligne." }, "license": "GPL-2.0+", "maintainer": { "name": "ljf", - "email": "ljf+libresurvey_ynh@reflexlibre.net", + "email": "ljf+limesurvey_ynh@reflexlibre.net", "url": "http://www.limesurvey.org/" }, "url": "https://www.limesurvey.org/", @@ -29,8 +29,8 @@ "name": "domain", "type": "domain", "ask": { - "en": "Choose a domain for LibreSurvey", - "fr": "Choisissez un nom de domaine pour LibreSurvey" + "en": "Choose a domain for LimeSurvey", + "fr": "Choisissez un nom de domaine pour LimeSurvey" }, "example": "domain.org" }, @@ -38,8 +38,8 @@ "name": "path", "type": "path", "ask": { - "en": "Choose a path for LibreSurvey", - "fr": "Choisissez l'adresse pour LibreSurvey" + "en": "Choose a path for LimeSurvey", + "fr": "Choisissez l'adresse pour LimeSurvey" }, "example": "/poll", "default": "/poll" @@ -48,16 +48,16 @@ "name": "admin", "type": "user", "ask": { - "en": "Choose the LibreSurvey administrator (must be an existing YunoHost user)", - "fr": "Choisissez l'administrateur de LibreSurvey (doit être un utilisateur YunoHost)" + "en": "Choose the LimeSurvey administrator (must be an existing YunoHost user)", + "fr": "Choisissez l'administrateur de LimeSurvey (doit être un utilisateur YunoHost)" }, "example": "john" }, { "name": "language", "ask": { - "en": "Choose the default language of this LibreSurvey", - "fr": "Choisissez la langue par défault de LibreSurvey" + "en": "Choose the default language of this LimeSurvey", + "fr": "Choisissez la langue par défault de LimeSurvey" }, "choices": ["en", "fr","es", "de"], "default": "en" @@ -66,8 +66,8 @@ "name": "is_public", "type": "boolean", "ask": { - "en": "Will people without YunoHost account have LibreSurvey account to be able to create polls ?", - "fr": "Est-ce que des personnes sans compte YunoHost aurront un compte LibreSurvey pour créer des questionnaires ?" + "en": "Will people without YunoHost account have LimeSurvey account to be able to create polls ?", + "fr": "Est-ce que des personnes sans compte YunoHost aurront un compte LimeSurvey pour créer des questionnaires ?" }, "default": 1 } diff --git a/scripts/install b/scripts/install index d2c9835..a737ab4 100755 --- a/scripts/install +++ b/scripts/install @@ -160,7 +160,7 @@ systemctl reload nginx #================================================= ynh_print_OFF message="You can now create a poll on this address: https://${domain}${path_url}/admin/ -If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/libresurvey_ynh" +If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/limesurvey_ynh" ynh_send_readme_to_admin "$message" "$admin" ynh_print_ON From 770b3411e4bd7bdd9ebe925108eef1b139b7069e Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 04:00:59 +0100 Subject: [PATCH 09/13] [enh] Upgrade to 3.5.0 --- check_process | 8 +- conf/app.src | 6 +- manifest.json | 4 +- scripts/_common.sh | 2 +- sources/patches/app-0001-7ca4932.patch | 106 ------------------------- 5 files changed, 10 insertions(+), 116 deletions(-) delete mode 100644 sources/patches/app-0001-7ca4932.patch diff --git a/check_process b/check_process index b7de956..ca79758 100644 --- a/check_process +++ b/check_process @@ -7,7 +7,7 @@ language="en" is_public=1 (PUBLIC|public=1|private=0) ; Checks - pkg_linter=0 + pkg_linter=1 setup_sub_dir=1 setup_root=1 setup_nourl=0 @@ -19,10 +19,10 @@ wrong_user=1 wrong_path=1 incorrect_path=1 - corrupt_source=0 - fail_download_source=0 + corrupt_source=1 + fail_download_source=1 port_already_use=0 - final_path_already_use=0 + final_path_already_use=1 change_url=0 ;;; Levels Level 1=auto diff --git a/conf/app.src b/conf/app.src index 1c0b8b9..4390102 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,3 +1,3 @@ -SOURCE_URL=https://github.com/LimeSurvey/LimeSurvey/archive/2.64.5+170331.tar.gz -SOURCE_SUM=9ae345eae7443f4df7f60ac49e8514ffb30315ba9376d5464cbfe9d6aaf9469f -SOURCE_FILENAME=libresurvey2.64.5+170331.tar.gz +SOURCE_URL=https://github.com/LimeSurvey/LimeSurvey/archive/3.5.0+180309.tar.gz +SOURCE_SUM=2e55d6123a6f53a8ae7b909fcc0bb435469e995ab4815f86d2b01990aeb76734 +SOURCE_FILENAME=limesurvey-3-5-0-180309.tar.gz diff --git a/manifest.json b/manifest.json index 2204ba9..cd9cd98 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name": "LimeSurvey", "id": "limesurvey", "packaging_format": 1, - "version": "2.62.5-2", + "version": "3.5.0-1", "description": { "en": "LimeSurvey is used to create advanced poll.", "fr": "LimeSurvey est un outil de création et diffusion de sondage en ligne." @@ -11,7 +11,7 @@ "maintainer": { "name": "ljf", "email": "ljf+limesurvey_ynh@reflexlibre.net", - "url": "http://www.limesurvey.org/" + "url": "https://reflexlibre.net" }, "url": "https://www.limesurvey.org/", "requirements": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 5726f72..0145883 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,7 +6,7 @@ # App package root directory should be the parent folder PKG_DIR=$(cd ../; pwd) -pkg_dependencies="php5-cli php5-imap" +pkg_dependencies="php5-cli php5-imap python-pip php5-gd php5-ldap" #================================================= # SPECIFIC HELPERS diff --git a/sources/patches/app-0001-7ca4932.patch b/sources/patches/app-0001-7ca4932.patch deleted file mode 100644 index 1394085..0000000 --- a/sources/patches/app-0001-7ca4932.patch +++ /dev/null @@ -1,106 +0,0 @@ -From 7ca49326dafe4d9896e67aebe414edcd3ce8c1af Mon Sep 17 00:00:00 2001 -From: Denis Chenu -Date: Thu, 19 Jan 2017 00:02:45 +0100 -Subject: [PATCH] [feature] Allow update via PHP cli - ---- - application/commands/UpdateCommand.php | 90 ++++++++++++++++++++++++++++++++++ - 1 files changed, 90 insertions(+) - create mode 100644 application/commands/UpdateCommand.php - -diff --git a/application/commands/UpdateCommand.php b/application/commands/UpdateCommand.php -new file mode 100644 -index 0000000..41ef107 ---- /dev/null -+++ b/application/commands/UpdateCommand.php -@@ -0,0 +1,90 @@ -+ -+ * @license GPL v3 -+ * @version 0.1 -+ * -+ * Copyright (C) 2017 Denis Chenu -+ * This program is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU Affero General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * This program is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ */ -+class UpdateCommand extends CConsoleCommand -+{ -+ public function run(){ -+ $this->_setConfigs(); -+ $newDbVersion = (float)Yii::app()->getConfig('dbversionnumber'); -+ $currentDbVersion = (float)Yii::app()->getConfig('DBVersion'); -+ if($newDbVersion > $currentDbVersion){ -+ echo "Update ".Yii::app()->db->connectionString.", prefix :".Yii::app()->db->tablePrefix." from {$currentDbVersion} to {$newDbVersion}\n"; -+ Yii::import('application.helpers.common_helper', true); -+ Yii::import('application.helpers.update.updatedb_helper', true); -+ $result=db_upgrade_all($currentDbVersion);/* @todo : fix bad echoing here */ -+ if ($result) { -+ //printf(gT("Database has been successfully upgraded to version %s"),$dbversionnumber)."\n"; -+ echo "Database has been successfully upgraded to version $newDbVersion \n"; -+ } else { -+ //echo gT("Please fix this error in your database and try again")."\n"; -+ echo "Please fix this error in your database and try again\n"; -+ } -+ } else { -+ echo "no need update ".$newDbVersion ." ". $currentDbVersion ."\n"; -+ } -+ } -+ -+ /** -+ * Fonction to set all needed (and unneeded) config -+ * @return void -+ */ -+ private function _setConfigs(){ -+ /* default config */ -+ $aDefaultConfigs = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config-defaults.php'); -+ foreach($aDefaultConfigs as $sConfig=>$defaultConfig){ -+ Yii::app()->setConfig($sConfig,$defaultConfig); -+ } -+ /* Fix for badly set rootdir */ -+ $sRootDir=realpath(Yii::app()->basePath. DIRECTORY_SEPARATOR . "..") ; -+ Yii::app()->setConfig('rootdir',$sRootDir); -+ Yii::app()->setConfig('publicdir',$sRootDir); -+ Yii::app()->setConfig('homedir',$sRootDir); -+ Yii::app()->setConfig('tempdir',$sRootDir.DIRECTORY_SEPARATOR."tmp"); -+ Yii::app()->setConfig('imagedir',$sRootDir.DIRECTORY_SEPARATOR."images"); -+ Yii::app()->setConfig('uploaddir',$sRootDir.DIRECTORY_SEPARATOR."upload"); -+ Yii::app()->setConfig('standardtemplaterootdir',$sRootDir.DIRECTORY_SEPARATOR."templates"); -+ Yii::app()->setConfig('usertemplaterootdir',$sRootDir.DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."templates"); -+ Yii::app()->setConfig('styledir',$sRootDir.DIRECTORY_SEPARATOR."styledir"); -+ /* version */ -+ $aVersionConfigs = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'version.php'); -+ foreach($aVersionConfigs as $sConfig=>$versionConfig){ -+ Yii::app()->setConfig($sConfig,$versionConfig); -+ } -+ /* LS 3 version */ -+ Yii::app()->setConfig('runtimedir',$sRootDir.DIRECTORY_SEPARATOR."tmp".DIRECTORY_SEPARATOR."runtime"); -+ if(file_exists(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) -+ { -+ $config = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'); -+ if(is_array($config['config']) && !empty($config['config'])) -+ { -+ foreach($config['config'] as $key=>$value) -+ Yii::app()->setConfig($key,$value); -+ } -+ } -+ $oSettings=SettingGlobal::model()->findAll(); -+ if (count($oSettings) > 0) -+ { -+ foreach ($oSettings as $oSetting) -+ { -+ Yii::app()->setConfig($oSetting->getAttribute('stg_name'), $oSetting->getAttribute('stg_value')); -+ } -+ } -+ } -+ -+} -+?> From f87a1babf79389a19f0e4d59e72be2a05edb4b78 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 14:11:46 +0100 Subject: [PATCH 10/13] [fix] Setup correctly db and disable old templates --- conf/data.sql.j2 | 3 --- scripts/_common.sh | 1 - scripts/install | 47 +++++++++++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/conf/data.sql.j2 b/conf/data.sql.j2 index b53db1f..119b65b 100644 --- a/conf/data.sql.j2 +++ b/conf/data.sql.j2 @@ -9,7 +9,6 @@ INSERT INTO `lime_plugins` (`id`, `name`, `active`) VALUES (9,'AuthLDAP',0); INSERT INTO `lime_permissions` (`id`, `entity`, `entity_id`, `uid`, `permission`, `create_p`, `read_p`, `update_p`, `delete_p`, `import_p`, `export_p`) VALUES -(1,'global',0,1,'superadmin',0,1,0,0,0,0), (2,'global',0,2,'auth_ldap',0,1,0,0,0,0), (3,'global',0,2,'surveys',1,0,0,0,0,0); @@ -41,8 +40,6 @@ INSERT INTO `lime_plugin_settings` (`id`, `plugin_id`, `model`, `model_id`, `key INSERT INTO `lime_settings_global` VALUES ('defaultlang','{{ language }}'),('AssetsVersion','2620'); -INSERT INTO `lime_users` VALUES (1,'{{ admin }}','9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08','Administrator',0,'{{ language }}','','default','default','default',NULL,1,'2017-02-02 01:03:08',NULL); - {% if is_public == "1" %} UPDATE `lime_plugin_settings` SET value='\"0\"' WHERE `id`=21; {% endif %} diff --git a/scripts/_common.sh b/scripts/_common.sh index 0145883..777f08f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -18,7 +18,6 @@ set_permissions () { || echo "No file to modify" #chown root: $final_path/application/config/config.php chmod -R u+w $final_path/tmp - chmod -R u+w $final_path/templates chmod -R u+w $final_path/upload chmod -R u+w $final_path/application/config/ } diff --git a/scripts/install b/scripts/install index a737ab4..5e8db45 100755 --- a/scripts/install +++ b/scripts/install @@ -90,6 +90,13 @@ ynh_system_user_create $app # Create a dedicated php-fpm config ynh_add_fpm_config +#================================================= +# SECURING FILES AND DIRECTORIES +#================================================= +# Set permissions +set_permissions + + #================================================= # SPECIFIC SETUP #================================================= @@ -98,19 +105,14 @@ ynh_add_fpm_config ynh_configure config.php "$final_path/application/config/config.php" #================================================= -# LOAD SQL CONFIG +# INSTALL #================================================= -cp $final_path/installer/sql/create-mysql.sql ./structure.sql -ynh_replace_string "\`prefix_" "\`$prefix" ./structure.sql -mysql -u $db_user -p$db_pwd $db_user < ./structure.sql -ynh_configure data.sql ./data.sql -mysql -u $db_user -p$db_pwd $db_user < ./data.sql +ls_cli=$final_path/application/commands/console.php +fullname=$(ynh_user_get_info "$admin" "fullname") +mail=$(ynh_user_get_info "$admin" "mail") -#================================================= -# Add nice themes -#================================================= -ynh_setup_source "$final_path/upload/templates/libreform" libreform -#ynh_setup_source "$final_path/upload/templates/librepoll" librepoll +# Permission should be correctly set before to do this +ynh_exec_as "$app" php $ls_cli install "$admin" "$(ynh_string_random 24)" "$fullname" "$mail" #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE @@ -119,24 +121,27 @@ ynh_setup_source "$final_path/upload/templates/libreform" libreform # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/application/config/config.php" +#================================================= +# LOAD SQL SPECIFIC CONFIG +#================================================= +ynh_configure data.sql ./data.sql +mysql -u $db_user -p$db_pwd $db_user < ./data.sql + +#================================================= +# Add nice themes +#================================================= +#ynh_setup_source "$final_path/upload/templates/libreform" libreform +#ynh_setup_source "$final_path/upload/templates/librepoll" librepoll + + #================================================= # GENERIC FINALISATION #================================================= # SECURING FILES AND DIRECTORIES #================================================= - # Set permissions set_permissions -#================================================= -# Randomize Password user -#================================================= -# Permission should be correctly set before to do this -ls_cli=$final_path/application/commands/console.php -set +x -ynh_exec_as "$app" php $ls_cli resetpassword "$admin" "$(ynh_string_random 24)" -set -x - #================================================= # SETUP FAIL2BAN #================================================= From c0bc01f59d6a942e386781ca9098dcd280638737 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 14:27:35 +0100 Subject: [PATCH 11/13] [enh] Test upgrade from 2.x sources --- check_process | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/check_process b/check_process index ca79758..6e03028 100644 --- a/check_process +++ b/check_process @@ -14,6 +14,7 @@ setup_private=0 setup_public=1 upgrade=1 + upgrade=1 from_commit=a451e536d79ff0d2b73f3c0d888243a567e7c77e backup_restore=1 multi_instance=1 wrong_user=1 @@ -38,3 +39,7 @@ ;;; Options Email=ljf+libresurvey_ynh@reflexlibre.net Notification=down +;;; Upgrade options + ; commit=a451e536d79ff0d2b73f3c0d888243a567e7c77e + name=2.62.5-2 a451e536d79ff0d2b73f3c0d888243a567e7c77e +manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=en&is_public=1& From 54285e1886c2940b8ca0ac4fd1ccd1579081b69c Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 14:43:51 +0100 Subject: [PATCH 12/13] [fix] Backup and remove old Limesurvey 2 templates --- scripts/upgrade | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index efbbf81..f41c2d1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -60,7 +60,6 @@ if ynh_version_le "2.0.5" ; then ynh_save_args path_url is_public prefix db_name final_path db_user ynh_install_app_dependencies $pkg_dependencies - # Move the upload dir to final_path if needed # The upload dir can't be symlinked in home (not supported by LS) upload_path=/home/yunohost.app/$app/upload @@ -75,6 +74,10 @@ if ynh_version_le "2.0.5" ; then ynh_configure migrations/2.0.5.sql ./2.0.5.sql mysql -u $app -p$db_pwd $db_name < ./2.0.5.sql fi +if ynh_version_le "2.62.2-2" ; then + # Move old templates in backup dir + mv $final_path/upload/templates /home/yunohost.backup/$app-old-templates +fi #================================================= # STANDARD UPGRADE STEPS @@ -130,3 +133,13 @@ ynh_exec_as "$app" php console.php update #================================================= ynh_system_reload nginx + +#================================================= +# Send message to the admin +#================================================= + +if ynh_version_le "2.62.2-2" ; then + message="LimeSurvey has been upgraded from version to version 3, note this new version change completely the survey themes system. If you have added or created manually some templates they won't be available in your LimeSurvey, a copy of their source code has been done in /home/yunohost.backup/$app-old-templates/. See https://manual.limesurvey.org/New_Template_System_in_LS3.x" + ynh_warn "$message" + ynh_send_readme_to_admin "$message" "$admin" +fi From 74f74e845cf3d15352461b46370e45140222a763 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Mar 2018 19:05:43 +0100 Subject: [PATCH 13/13] [fix] Upgrade --- manifest.json | 2 +- scripts/_common.sh | 69 +++++++++++++++++++++++++--------------------- scripts/upgrade | 23 ++++++++++------ 3 files changed, 54 insertions(+), 40 deletions(-) diff --git a/manifest.json b/manifest.json index cd9cd98..d20b094 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name": "LimeSurvey", "id": "limesurvey", "packaging_format": 1, - "version": "3.5.0-1", + "version": "3.5.0-4", "description": { "en": "LimeSurvey is used to create advanced poll.", "fr": "LimeSurvey est un outil de création et diffusion de sondage en ligne." diff --git a/scripts/_common.sh b/scripts/_common.sh index 777f08f..2ec6a78 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -88,45 +88,52 @@ ynh_exec_as() { } -# TODO support SOURCE_ID +# usage: ynh_save_persistent MODE RELATIVE_PATH ynh_save_persistent () { local TYPE=$1 - local DIR=/tmp/ynh-persistent/$TYPE/$app/app - mkdir -p $DIR - touch $DIR/dir_names - shift - i=1 - for PERSISTENT_DIR in $@; - do - if [ -e $final_path/$PERSISTENT_DIR ]; then - mv $final_path/$PERSISTENT_DIR $DIR/$i - echo -n '$PERSISTENT_DIR ' >> $DIR/dir_names - ((i++)) - fi - done + local DIR=/tmp/ynh-persistent/$app + set +u + i=${#YNH_PERSISTENT_DIR[@]} + i=${i:-0} + set -u + [ "$i" -eq "0" ] && ynh_secure_remove $DIR && mkdir -p $DIR + if [ -e $final_path/$2 ]; then + mv $final_path/$2 $DIR/$i + YNH_PERSISTENT_MODE[$i]=$1 + YNH_PERSISTENT_DIR[$i]=$2 + fi } -# TODO support SOURCE_ID +ynh_keep_if_no_upgrade () { + for elt in $@; + do + ynh_save_persistent KEEP_IF_NO_UPGRADE $elt + done +} +ynh_keep () { + for elt in $@; + do + ynh_save_persistent KEEP $elt + done +} +# usage: ynh_restore_persistent ynh_restore_persistent () { - local TYPE=$1 - local DIR=/tmp/ynh-persistent/$TYPE/$app/app - shift - if [ -d $DIR ]; then - i=1 - for PERSISTENT_DIR in $(cat $DIR/dir_names); + local DIR=/tmp/ynh-persistent/$app + if [ -d $DIR ]; then + i=0 + for PERSISTENT_DIR in "${YNH_PERSISTENT_DIR[@]}"; do - if [ "$TYPE" = "modules" ]; then - for updated_subdir in $(ls $final_path/$PERSISTENT_DIR); - do - ynh_secure_remove $DIR/$i/$updated_subdir - done - fi - if [ -d $DIR/$i ]; then - mv $DIR/$i/* $final_path/$PERSISTENT_DIR/ 2> /dev/null || true + if [ "${YNH_PERSISTENT_MODE[$i]}" = "KEEP_IF_NO_UPGRADE" ]; then + if [ ! -e $final_path/$PERSISTENT_DIR ]; then + mv $DIR/$i $final_path/$PERSISTENT_DIR + fi else - mv $DIR/$i $final_path/$PERSISTENT_DIR 2> /dev/null || true + if [ -e $final_path/$PERSISTENT_DIR ]; then + ynh_secure_remove $final_path/$PERSISTENT_DIR + fi + mv $DIR/$i $final_path/$PERSISTENT_DIR fi - ((i++)) + ((i+=1)) done ynh_secure_remove $DIR fi diff --git a/scripts/upgrade b/scripts/upgrade index f41c2d1..f36fbfd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -57,7 +57,6 @@ if ynh_version_le "2.0.5" ; then prefix=${prefix:-prefix_} db_name=${db_name:-$app} final_path=$(ynh_app_setting_get $app local_path) - ynh_save_args path_url is_public prefix db_name final_path db_user ynh_install_app_dependencies $pkg_dependencies # Move the upload dir to final_path if needed @@ -74,9 +73,18 @@ if ynh_version_le "2.0.5" ; then ynh_configure migrations/2.0.5.sql ./2.0.5.sql mysql -u $app -p$db_pwd $db_name < ./2.0.5.sql fi +if ynh_version_le "2.62.2-1" ; then + is_public=${is_public:-0} + prefix=${prefix:-prefix_} + db_name=${db_name:-$app} + final_path=$(ynh_app_setting_get $app local_path) + ynh_save_args path_url is_public prefix db_name final_path db_user +fi if ynh_version_le "2.62.2-2" ; then - # Move old templates in backup dir - mv $final_path/upload/templates /home/yunohost.backup/$app-old-templates + # Move old templates and themes in backup dir + mv $final_path/upload/templates /home/yunohost.backup/$app.bkp/old-templates + mkdir -p /home/yunohost.backup/$app.bkp/old-themes + mv $final_path/themes/* /home/yunohost.backup/$app.bkp/old-themes/ fi #================================================= @@ -86,16 +94,15 @@ fi #================================================= # Backup config, plugins and themes and delete previous files -ynh_save_persistent modules themes plugins -ynh_save_persistent data application/config/config.php upload +ynh_keep_if_no_upgrade themes/admin/* themes/question/* themes/survey/* plugins/* +ynh_keep application/config/config.php upload # Copie new files and restore config, plugins, upload and themes ynh_secure_remove $final_path ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path # Restore config, plugins and themes -ynh_restore_persistent modules -ynh_restore_persistent data +ynh_restore_persistent #================================================= # NGINX CONFIGURATION @@ -126,7 +133,7 @@ set_permissions # Migrate DB cd $final_path/application/commands -ynh_exec_as "$app" php console.php update +ynh_exec_as "$app" php console.php updatedb #================================================= # RELOAD NGINX