1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/limesurvey_ynh.git synced 2024-09-03 19:36:32 +02:00

[enh] Upgrade to 2.7

This commit is contained in:
ljf 2018-03-13 21:49:11 +01:00
parent 069d150bd5
commit 281c79b5ea
16 changed files with 686 additions and 925 deletions

View file

@ -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 **Categories:** Productivity, Poll
**Upgrade this package:** ## Screenshots
`sudo yunohost app upgrade --verbose LimeSurvey -u https://github.com/YunoHost-Apps/limesurvey_ynh`
**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.

View file

@ -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

View file

@ -7,7 +7,7 @@
language="en" language="en"
is_public=1 (PUBLIC|public=1|private=0) is_public=1 (PUBLIC|public=1|private=0)
; Checks ; Checks
pkg_linter=1 pkg_linter=0
setup_sub_dir=1 setup_sub_dir=1
setup_root=1 setup_root=1
setup_nourl=0 setup_nourl=0
@ -23,15 +23,18 @@
fail_download_source=0 fail_download_source=0
port_already_use=0 port_already_use=0
final_path_already_use=0 final_path_already_use=0
change_url=0
;;; Levels ;;; Levels
Level 1=auto Level 1=auto
Level 2=auto Level 2=auto
Level 3=auto Level 3=auto
Level 4=1 Level 4=1
# https://github.com/YunoHost-Apps/limesurvey_ynh/issues/10 Level 5=auto
Level 5=1
Level 6=auto Level 6=auto
Level 7=auto Level 7=auto
Level 8=0 Level 8=0
Level 9=0 Level 9=0
Level 10=0 Level 10=0
;;; Options
Email=ljf+libresurvey_ynh@reflexlibre.net
Notification=down

3
conf/app.src Normal file
View file

@ -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

3
conf/libreform.src Normal file
View file

@ -0,0 +1,3 @@
SOURCE_URL=https://github.com/zamentur/libreform/archive/40fad776c33271ecc028b9260fb7f9e300998e5f.tar.gz
SOURCE_SUM=4c0a96d610c6740ff7467cf1916a923949bf4c00e99a3cd33509335f884e138b
SOURCE_FILENAME=libreform-40fad776c33271ecc028b9260fb7f9e300998e5f.tar.gz

View file

@ -1,9 +1,12 @@
location {{ path }} { {% if path_url != "/" %}
alias {{ local_path }}/; rewrite ^{{ path_url }}$ {{ path_url }}/ permanent;
{% endif %}
location {{ path_url }}/ {
alias {{ final_path }}/;
index index.php; index index.php;
# if (!-e $request_filename) # if (!-e $request_filename)
#{ #{
# rewrite ^(.+)$ {{ path }}/index.php?q=$1 last; # rewrite ^(.+)$ {{ path_url }}/index.php?q=$1 last;
#} #}
if ($scheme = http) { if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent; rewrite ^ https://$server_name$request_uri? permanent;
@ -24,6 +27,6 @@ location {{ path }} {
include conf.d/yunohost_panel.conf.inc; 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; deny all;
} }

View file

@ -340,7 +340,7 @@ request_terminate_timeout = 1d
; Chdir to this directory at the start. ; Chdir to this directory at the start.
; Note: relative path can be used. ; Note: relative path can be used.
; Default Value: current directory or / when chroot ; 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 ; 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. ; stderr will be redirected to /dev/null according to FastCGI specs.

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
# TODO delete user with LimeSurvey cli # TODO delete user with LimeSurvey cli
# An action need to be added to the cli with a patch # 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"

View file

@ -1,21 +1,21 @@
{ {
"name": "LimeSurvey", "name": "LibreSurvey",
"id": "limesurvey", "id": "libresurvey",
"packaging_format": 1, "packaging_format": 1,
"version": "2.62.2", "version": "2.62.5-1",
"description": { "description": {
"en": "LimeSurvey is used to create advanced poll.", "en": "LibreSurvey is used to create advanced poll.",
"fr": "LimeSurvey est un outil de création et diffusion de sondage en ligne." "fr": "LibreSurvey est un outil de création et diffusion de sondage en ligne."
}, },
"license": "GPL-2.0+", "license": "GPL-2.0+",
"maintainer": { "maintainer": {
"name": "ljf", "name": "ljf",
"email": "ljf@grimaud.me", "email": "ljf+libresurvey_ynh@reflexlibre.net",
"url": "http://www.limesurvey.org/" "url": "http://www.limesurvey.org/"
}, },
"url": "https://www.limesurvey.org/", "url": "https://www.limesurvey.org/",
"requirements": { "requirements": {
"yunohost": ">= 2.4" "yunohost": ">= 2.7.2"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [
@ -29,8 +29,8 @@
"name": "domain", "name": "domain",
"type": "domain", "type": "domain",
"ask": { "ask": {
"en": "Choose a domain for LimeSurvey", "en": "Choose a domain for LibreSurvey",
"fr": "Choisissez un nom de domaine pour LimeSurvey" "fr": "Choisissez un nom de domaine pour LibreSurvey"
}, },
"example": "domain.org" "example": "domain.org"
}, },
@ -38,8 +38,8 @@
"name": "path", "name": "path",
"type": "path", "type": "path",
"ask": { "ask": {
"en": "Choose a path for LimeSurvey", "en": "Choose a path for LibreSurvey",
"fr": "Choisissez l'adresse pour LimeSurvey" "fr": "Choisissez l'adresse pour LibreSurvey"
}, },
"example": "/poll", "example": "/poll",
"default": "/poll" "default": "/poll"
@ -48,16 +48,16 @@
"name": "admin", "name": "admin",
"type": "user", "type": "user",
"ask": { "ask": {
"en": "Choose the LimeSurvey administrator (must be an existing YunoHost user)", "en": "Choose the LibreSurvey administrator (must be an existing YunoHost user)",
"fr": "Choisissez l'administrateur de LimeSurvey (doit être un utilisateur YunoHost)" "fr": "Choisissez l'administrateur de LibreSurvey (doit être un utilisateur YunoHost)"
}, },
"example": "john" "example": "john"
}, },
{ {
"name": "language", "name": "language",
"ask": { "ask": {
"en": "Choose the default language of this LimeSurvey", "en": "Choose the default language of this LibreSurvey",
"fr": "Choisissez la langue par défault de LimeSurvey" "fr": "Choisissez la langue par défault de LibreSurvey"
}, },
"choices": ["en", "fr","es", "de"], "choices": ["en", "fr","es", "de"],
"default": "en" "default": "en"
@ -66,8 +66,8 @@
"name": "is_public", "name": "is_public",
"type": "boolean", "type": "boolean",
"ask": { "ask": {
"en": "Will people without YunoHost account have LimeSurvey account to be able to create polls ?", "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 LimeSurvey pour créer des questionnaires ?" "fr": "Est-ce que des personnes sans compte YunoHost aurront un compte LibreSurvey pour créer des questionnaires ?"
}, },
"default": 1 "default": 1
} }

View file

@ -1,85 +1,57 @@
#!/bin/bash #!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# App package root directory should be the parent folder # App package root directory should be the parent folder
PKG_DIR=$(cd ../; pwd) 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 () { ynh_check_var () {
test -n "$1" || ynh_die "$2" 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 () { ynh_export () {
local ynh_arg="" local ynh_arg=""
for var in $@; for var in $@;
do do
ynh_arg=$(echo $var | awk '{print toupper($0)}') ynh_arg=$(echo $var | awk '{print toupper($0)}')
if [ "$var" == "path_url" ]; then
ynh_arg="PATH"
fi
ynh_arg="YNH_APP_ARG_$ynh_arg" ynh_arg="YNH_APP_ARG_$ynh_arg"
export $var=${!ynh_arg} export $var=${!ynh_arg}
done 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 # Check the path doesn't exist
# usage: ynh_local_path_available PATH # usage: ynh_local_path_available PATH
ynh_local_path_available () { ynh_local_path_available () {
@ -94,31 +66,14 @@ ynh_local_path_available () {
ynh_save_args () { ynh_save_args () {
for var in $@; for var in $@;
do 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 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 # Execute a command as another user
# usage: ynh_exec_as USER COMMAND [ARG ...] # usage: ynh_exec_as USER COMMAND [ARG ...]
ynh_exec_as() { ynh_exec_as() {
@ -133,80 +88,20 @@ ynh_exec_as() {
fi 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 # TODO support SOURCE_ID
ynh_save_persistent () { ynh_save_persistent () {
local TYPE=$1 local TYPE=$1
local DIR=/tmp/ynh-persistent/$TYPE/$app/app local DIR=/tmp/ynh-persistent/$TYPE/$app/app
sudo mkdir -p $DIR mkdir -p $DIR
sudo touch $DIR/dir_names touch $DIR/dir_names
shift shift
i=1 i=1
for PERSISTENT_DIR in $@; for PERSISTENT_DIR in $@;
do do
if [ -e $local_path/$PERSISTENT_DIR ]; then if [ -e $local_path/$PERSISTENT_DIR ]; then
sudo mv $local_path/$PERSISTENT_DIR $DIR/$i mv $local_path/$PERSISTENT_DIR $DIR/$i
sudo su -c "echo -n '$PERSISTENT_DIR ' >> $DIR/dir_names" echo -n '$PERSISTENT_DIR ' >> $DIR/dir_names
((i++)) ((i++))
fi fi
done done
@ -224,52 +119,43 @@ ynh_restore_persistent () {
if [ "$TYPE" = "modules" ]; then if [ "$TYPE" = "modules" ]; then
for updated_subdir in $(ls $local_path/$PERSISTENT_DIR); for updated_subdir in $(ls $local_path/$PERSISTENT_DIR);
do do
sudo rm -Rf $DIR/$i/$updated_subdir ynh_secure_remove $DIR/$i/$updated_subdir
done done
fi fi
if [ -d $DIR/$i ]; then 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 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 fi
((i++)) ((i++))
done done
sudo rm -Rf $DIR ynh_secure_remove $DIR
fi fi
} }
ynh_mv_to_home () { ynh_mv_to_home () {
local APP_PATH="/home/yunohost.app/$app/" local APP_PATH="/home/yunohost.app/$app/"
local DATA_PATH="$1" local DATA_PATH="$1"
sudo mkdir -p "$APP_PATH" mkdir -p "$APP_PATH"
sudo chown $app: "$APP_PATH" chown $app: "$APP_PATH"
ynh_exec_as "$app" mv "$DATA_PATH" "$APP_PATH" ynh_exec_as "$app" mv "$DATA_PATH" "$APP_PATH"
ynh_exec_as "$app" ln -s "$APP_PATH$DATA_PATH" "$DATA_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_sso_access () {
ynh_app_setting_set $app unprotected_uris "/" ynh_app_setting_set $app unprotected_uris "/"
if [[ $is_public -eq 0 ]]; then if [[ $is_public -eq 0 ]]; then
ynh_app_setting_set $app protected_uris "$1" ynh_app_setting_set $app protected_uris "$1"
fi fi
sudo yunohost app ssowatconf yunohost app ssowatconf
} }
ynh_exit_if_up_to_date () { ynh_exit_if_up_to_date () {
if [ "${version}" = "${last_version}" ]; then if [ "${version}" = "${last_version}" ]; then
info "Up-to-date, nothing to do" info "Up-to-date, nothing to do"
exit 0 ynh_die "Up-to-date, nothing to do" 0
fi fi
} }
@ -311,64 +197,6 @@ ynh_read_manifest () {
fi 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 () { ynh_configure () {
local TEMPLATE=$1 local TEMPLATE=$1
@ -378,82 +206,167 @@ ynh_configure () {
sudo cp "${PKG_DIR}/conf/$TEMPLATE" "$DEST" sudo cp "${PKG_DIR}/conf/$TEMPLATE" "$DEST"
} }
ynh_configure_nginx () { ynh_add_nginx_config () {
ynh_configure nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
sudo service nginx reload ynh_backup_if_checksum_is_different "$finalnginxconf"
ynh_configure nginx.conf "$finalnginxconf"
ynh_store_file_checksum "$finalnginxconf"
service nginx reload
} }
ynh_configure_php_fpm () { ynh_add_fpm_config () {
finalphpconf=/etc/php5/fpm/pool.d/$app.conf # Configure PHP-FPM 7.0 by default
ynh_configure php-fpm.conf /etc/php5/fpm/pool.d/$app.conf local fpm_config_dir="/etc/php/7.0/fpm"
sudo chown root: $finalphpconf local fpm_service="php7.0-fpm"
# Configure PHP-FPM 5 on Debian Jessie
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini if is_jessie; then
sudo cp ../conf/php-fpm.ini $finalphpini fpm_config_dir="/etc/php5/fpm"
sudo chown root: $finalphpini fpm_service="php5-fpm"
fi
sudo service php5-fpm reload 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 # This helper should be used to avoid an upgrade of a package
# | arg: begin_port - port to start to search # when it's not needed.
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 # To force an upgrade, even if the package is up to date,
# | arg: user - Proprietary of the database # you have to set the variable YNH_FORCE_UPGRADE before.
# | arg: name - Name of the database # example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp
ynh_mysql_remove_db () { #
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $2"; then # Check if the database exist # usage: ynh_abort_if_up_to_date
ynh_mysql_drop_db $2 # Remove the database ynh_abort_if_up_to_date () {
ynh_mysql_drop_user $1 # Remove the associated user to database local force_upgrade=${YNH_FORCE_UPGRADE:-0}
else local package_check=${PACKAGE_CHECK_EXEC:-0}
echo "Database $2 not found" >&2
fi 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 () { # Remove any logs for all the following commands.
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then #
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" # usage: ynh_print_OFF
sudo service nginx reload # WARNING: You should be careful with this helper, and never forgot to use ynh_print_ON as soon as possible to restore the logging.
fi ynh_print_OFF () {
set +x
} }
ynh_rm_php_fpm_conf () { # Restore the logging after ynh_print_OFF
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then #
sudo rm "/etc/php5/fpm/pool.d/$app.conf" # usage: ynh_print_ON
fi ynh_print_ON () {
if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then set -x
sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" # Print an echo only for the log, to be able to know that ynh_print_ON has been called.
fi echo ynh_print_ON > /dev/null
sudo service php5-fpm reload }
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 () { ynh_debian_release () {
if [ -e "/etc/logrotate.d/$app" ]; then lsb_release --codename --short
sudo rm "/etc/logrotate.d/$app"
fi
} }
ynh_secure_rm () { is_stretch () {
[[ "/var/www /opt /home/yunohost.app" =~ $1 ]] \ if [ "$(ynh_debian_release)" == "stretch" ]
|| (test -n "$1" && sudo rm -Rf $1 ) then
return 0
else
return 1
fi
} }
is_jessie () {
if [ "$(ynh_debian_release)" == "jessie" ]
then
return 0
else
return 1
fi
}

View file

@ -1,34 +1,53 @@
#!/bin/bash #!/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 app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path)
local_path=$(ynh_app_setting_get $app local_path) db_name=$(ynh_app_setting_get $app db_name)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
my_ynh_backup () { #=================================================
ynh_backup $@ # STANDARD BACKUP STEPS
echo $2 $1 >> $backup_dir/list #=================================================
} # BACKUP OF THE MAIN DIR OF THE APP
#=================================================
# Copy the app files ynh_backup "$final_path"
my_ynh_backup "$local_path" "sources"
# Copy the conf files #=================================================
my_ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" # BACKUP OF THE NGINX CONFIGURATION
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"
# Save database ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
mysqldump -u "$app" -p"$dbpass" --no-create-db "$app" > ./dump.sql #=================================================
# 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

View file

@ -1,62 +1,166 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _common.sh 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 export app=$YNH_APP_INSTANCE_NAME
user=$app
# Retrieve arguments # Retrieve arguments
ynh_export domain path admin is_public language ynh_export domain path_url admin is_public language
export local_path=/var/www/$app
export prefix=lime_ 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 # 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" export final_path=/var/www/$app
ynh_normalize_url_path "$path" test ! -e "$final_path" || ynh_die "This path already contains a folder"
ynh_path_validity "$domain$path"
ynh_local_path_available "$local_path" # 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" #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
ynh_configure config.php "$local_path/application/config/config.php" #=================================================
# Fill LimeSurvey database # Download, check integrity, uncompress and patch the source from app.src
sed "s/\`prefix_/\`$prefix/g" $local_path/installer/sql/create-mysql.sql > ./structure.sql 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 mysql -u $db_user -p$db_pwd $db_user < ./structure.sql
ynh_configure data.sql ./data.sql ynh_configure data.sql ./data.sql
mysql -u $db_user -p$db_pwd $db_user < ./data.sql mysql -u $db_user -p$db_pwd $db_user < ./data.sql
# Randomize Password user #=================================================
ls_cli=$local_path/application/commands/console.php # Add nice themes
set +x #=================================================
ynh_exec_as "$user" php $ls_cli resetpassword "$admin" "$(ynh_string_random 24)" ynh_setup_source "$final_path/upload/templates/libreform" libreform
set -x #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 # Set permissions
ynh_set_default_perm $local_path set_permissions
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/
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: <HOST>" 5
#=================================================
# SETUP SSOWAT
#=================================================
yunohost app addaccess $app -u $admin
ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts" 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

View file

@ -1,27 +1,68 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _common.sh source _common.sh
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME 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) 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 # Remove a database if it exists, along with the associated user
ynh_rm_php_fpm_conf 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 # REMOVE THE MAIN DIR OF THE APP
ynh_system_user_delete "$user" #=================================================
dep_app=${app/__/-} # Remove the app directory securely
ynh_package_remove $dep_app-ynh-deps 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

View file

@ -1,527 +1,94 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/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 # Exit if an error occurs during the execution of the script
PKG_DIR=$(cd ../; pwd) ynh_abort_if_errors
ynh_check_var () { #=================================================
test -n "$1" || ynh_die "$2" # LOAD SETTINGS
} #=================================================
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
export app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
user=$app
export domain=$(ynh_app_setting_get $app domain) 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) export admin=$(ynh_app_setting_get $app admin)
dbpass=$(ynh_app_setting_get $app mysqlpwd) export final_path=$(ynh_app_setting_get $app final_path)
export local_path=$(ynh_app_setting_get $app local_path)
export is_public=$(ynh_app_setting_get $app is_public) export is_public=$(ynh_app_setting_get $app is_public)
export prefix=$(ynh_app_setting_get $app prefix) export prefix=$(ynh_app_setting_get $app prefix)
dbname=$app export db_name=$(ynh_app_setting_get $app db_name)
dbuser=$user 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 # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
#ynh_path_validity "$domain$path" ynh_webpath_available $domain $path_url \
ynh_check_restore || 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_setup_db $db_name $db_name $db_pwd
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
# Restore file #=================================================
# RESTORE FILES
#=================================================
# Restore files
ynh_restore ynh_restore
# Fix app ownerships & permissions #=================================================
ynh_set_default_perm $local_path # RECREATE THE DEDICATED USER
sudo chmod -R u+w $local_path/tmp #=================================================
sudo chmod -R u+w $local_path/upload ynh_system_user_create "$app" "$final_path"
sudo chmod -R u+w $local_path/application/config/
#=================================================
# RESTORE USER RIGHTS
#=================================================
set_permissions
#=================================================
# SETUP SSOWAT
#=================================================
ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts" ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts"
# Reload services #=================================================
sudo service php5-fpm restart || true # GENERIC FINALISATION
sudo service nginx reload || true #=================================================
# 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"

View file

@ -1,70 +1,128 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _common.sh source _common.sh
ynh_trap_on #=================================================
# LOAD SETTINGS
#=================================================
export app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
user=$app
export domain=$(ynh_app_setting_get $app domain) 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) export admin=$(ynh_app_setting_get $app admin)
db_pwd=$(ynh_app_setting_get $app mysqlpwd) export final_path=$(ynh_app_setting_get $app final_path)
export local_path=$(ynh_app_setting_get $app local_path)
export is_public=$(ynh_app_setting_get $app is_public) export is_public=$(ynh_app_setting_get $app is_public)
is_public=${is_public:-0}
export prefix=$(ynh_app_setting_get $app prefix) export prefix=$(ynh_app_setting_get $app prefix)
prefix=${prefix:-prefix_} export db_pwd=$(ynh_app_setting_get $app mysqlpwd)
version=$(ynh_read_json "/etc/yunohost/apps/$app/manifest.json" 'version' 2> /dev/null || echo '2.0.5') export db_name=$(ynh_app_setting_get $app db_name)
last_version=$(ynh_read_manifest 'version') export db_user=$(ynh_app_setting_get $app db_user)
ynh_exit_if_up_to_date #=================================================
ynh_check_var "$app" "app name not set" # CHECK VERSION
ynh_user_exists "$admin" || err "User does not exist: $admin" #=================================================
ynh_normalize_url_path "$path"
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) # The upload dir can't be symlinked in home (not supported by LS)
upload_path=/home/yunohost.app/$app/upload upload_path=/home/yunohost.app/$app/upload
if [ -h $local_path/upload ]; then if [ -h $final_path/upload ]; then
sudo rm $local_path/upload rm $final_path/upload
sudo mv $upload_path $local_path/ mv $upload_path $final_path/
fi fi
ynh_app_setting_delete $app skipped_uris ynh_app_setting_delete $app skipped_uris
ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts" 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 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 fi
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Backup config, plugins and themes and delete previous files # Backup config, plugins and themes and delete previous files
ynh_save_persistent modules themes plugins ynh_save_persistent modules themes plugins
ynh_save_persistent data application/config/config.php upload ynh_save_persistent data application/config/config.php upload
# Copie new files and restore config, plugins, upload and themes # Copie new files and restore config, plugins, upload and themes
sudo rm -Rf $local_path ynh_secure_remove $final_path
ynh_setup_source "$local_path" "$user" 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 # NGINX CONFIGURATION
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/ 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 # Migrate DB
cd $local_path/application/commands cd $final_path/application/commands
ynh_exec_as "$app" php console.php update ynh_exec_as "$app" php console.php update
#=================================================
# RELOAD NGINX
#=================================================
ynh_system_reload nginx