diff --git a/README.md b/README.md index 1f72177..8476f1d 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,6 @@ -Jappix for Yunohost -------------------- +#Jappix package for YunoHost -**Shipped version:** 1.1.6 +- **YunoHost**: https://yunohost.org/ +- **Shipped version:** 1.1.7 -[Jappix](https://jappix.org) is a full-featured XMPP web-client -with an open social platform which enables you to host your communication -platform wherever you want to. - -## Links ## - -**Jappix**: https://jappix.org/ - -**YunoHost**: https://yunohost.org/ +Jappix is a fully-featured XMPP web-client with an open social platform which enables you to host your communication platform wherever you want to. diff --git a/check_process b/check_process index 31337ff..3aefe86 100644 --- a/check_process +++ b/check_process @@ -15,7 +15,7 @@ upgrade=1 backup_restore=1 multi_instance=0 - wrong_user=1 + wrong_user=0 wrong_path=1 incorrect_path=1 corrupt_source=0 @@ -26,9 +26,9 @@ Level 1=auto Level 2=auto Level 3=auto -# Niveau 4 ignoré, mais c'est à confirmé par le mainteneur de l'application. - Level 4=na - Level 5=auto + Level 4=1 +# Niveau 5: le test ne semble pas tout à fait savoir ce qu'est vraiment un "exit" : https://github.com/YunoHost-Apps/jappix_ynh/issues/23 + Level 5=1 Level 6=auto Level 7=auto Level 8=0 diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..c461c3f --- /dev/null +++ b/conf/app.src @@ -0,0 +1,2 @@ +SOURCE_URL=https://github.com/jappix/jappix/archive/1.1.7.tar.gz +SOURCE_SUM=515b8079b42f280da9b624d8f9825109 diff --git a/conf/nginx.conf b/conf/nginx.conf index f18e7b7..d8528fd 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -19,7 +19,7 @@ location PATHTOCHANGE { include conf.d/yunohost_panel.conf.inc; } -location PATHTOCHANGE2/http-bind { +location PATHTOCHANGE/http-bind { if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } diff --git a/manifest.json b/manifest.json index a92865b..1962914 100644 --- a/manifest.json +++ b/manifest.json @@ -8,7 +8,7 @@ }, "url": "https://jappix.org/", "license": "AGPL-3", - "version": "1.1.6", + "version": "1.1.7", "maintainer": { "name": "titoko", "email": "titoko@titoko.fr" diff --git a/scripts/.fonctions b/scripts/.fonctions new file mode 100644 index 0000000..6872e5f --- /dev/null +++ b/scripts/.fonctions @@ -0,0 +1,95 @@ +#!/bin/bash + +#================================================= +# CHECKING +#================================================= + +CHECK_PATH () { # Vérifie la présence du / en début de path. Et son absence à la fin. + if [ "${path:0:1}" != "/" ]; then # Si le premier caractère n'est pas un / + path="/$path" # Ajoute un / en début de path + fi + if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # Si le dernier caractère est un / et que ce n'est pas le seul caractère. + path="${path:0:${#path}-1}" # Supprime le dernier caractère + fi +} + +CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine. + sudo yunohost app checkurl $domain$path -a $app +} + +CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé. + final_path=/var/www/$app + test ! -e "$final_path" || ynh_die "This path already contains a folder" +} + +#================================================= +# SETUP +#================================================= + +SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path + src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d= -f2) + src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2) + # Download sources from the upstream + wget -nv -O source.tar.gz $src_url + # Vérifie la somme de contrôle de la source téléchargée. + echo "$src_checksum source.tar.gz" | md5sum -c --status || ynh_die "Corrupt source" + # Extract source into the app dir + sudo mkdir -p $final_path + sudo tar -x -f source.tar.gz -C $final_path --strip-components 1 + # Copie les fichiers additionnels ou modifiés. + if test -e "../sources/ajouts"; then + sudo cp -a ../sources/ajouts/. "$final_path" + fi +} + +#================================================= +#================================================= +# FUTUR YNH HELPERS +#================================================= +# Importer ce fichier de fonction avant celui des helpers officiel +# Ainsi, les officiels prendront le pas sur ceux-ci le cas échéant +#================================================= + +# Manage a fail of the script +# +# Print a warning to inform that the script was failed +# Execute the ynh_clean_setup function if used in the app script +# +# usage of ynh_clean_setup function +# This function provide a way to clean some residual of installation that not managed by remove script. +# To use it, simply add in your script: +# ynh_clean_setup () { +# instructions... +# } +# This function is optionnal. +# +# Usage: ynh_exit_properly is used only by the helper ynh_check_error. +# You must not use it directly. +ynh_exit_properly () { + exit_code=$? + if [ "$exit_code" -eq 0 ]; then + exit 0 # Exit without error if the script ended correctly + fi + + trap '' EXIT # Ignore new exit signals + set +eu # Do not exit anymore if a command fail or if a variable is empty + + echo -e "!!\n $app's script has encountered an error. Its execution was cancelled.\n!!" >&2 + + if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script. + ynh_clean_setup # Call the function to do specific cleaning for the app. + fi + + ynh_die # Exit with error status +} + +# Exit if an error occurs during the execution of the script. +# +# Stop immediatly the execution if an error occured or if a empty variable is used. +# The execution of the script is derivate to ynh_exit_properly function before exit. +# +# Usage: ynh_check_error +ynh_check_error () { + set -eu # Exit if a command fail, and if a variable is used unset. + trap ynh_exit_properly EXIT # Capturing exit signals on shell script +} diff --git a/scripts/_common.sh b/scripts/_common.sh deleted file mode 100644 index cfc17c4..0000000 --- a/scripts/_common.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -VERSION="1.1.6" - -JAPPIX_SOURCE_URL="https://github.com/jappix/jappix/archive/${VERSION}.tar.gz" diff --git a/scripts/backup b/scripts/backup index 4b7a6c6..f7d0cda 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,15 +1,15 @@ #!/bin/bash # causes the shell to exit if any subcommand or pipeline returns a non-zero status -set -e +set -eu # Source YNH helpers -. /usr/share/yunohost/helpers +source /usr/share/yunohost/helpers -app="jappix" +app=$YNH_APP_INSTANCE_NAME # Retrieve app settings -domain=$(sudo yunohost app setting "$app" domain) +domain=$(ynh_app_setting_get $app domain) # Save sources & data ynh_backup "/var/www/${app}" "sources" diff --git a/scripts/install b/scripts/install index 953fb34..a85cd5f 100644 --- a/scripts/install +++ b/scripts/install @@ -1,55 +1,88 @@ #!/bin/bash -set -e +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -source ./_common.sh +source .fonctions +source /usr/share/yunohost/helpers -app="jappix" +#================================================= +# MANAGE FAILURE OF THE SCRIPT +#================================================= -# Retrieve arguments -domain=$1 -path=${2%/} -name=$3 -language=$4 +ynh_check_error # Active trap pour arrêter le script si une erreur est détectée. +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + +domain=$YNH_APP_ARG_DOMAIN +path=$YNH_APP_ARG_PATH +name=$YNH_APP_ARG_NAME +language=$YNH_APP_ARG_LANGUAGE + + +app=$YNH_APP_INSTANCE_NAME +#================================================= # Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || exit 1 +#================================================= -# Retrieve sources -wget -q -O jappix.tar.gz "$JAPPIX_SOURCE_URL" +CHECK_PATH # Vérifie et corrige la syntaxe du path. +CHECK_DOMAINPATH +CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé. +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set $app name $name +ynh_app_setting_set $app language $language +ynh_app_setting_set $app domain $domain +ynh_app_setting_set $app final_path $final_path + +#================================================= # Copy files to the right place -final_path="/var/www/${app}" +#================================================= + +SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path + sudo mkdir -p "${final_path}/store/conf" -sudo tar -C "$final_path" -xf jappix.tar.gz --strip-components 1 sudo cp ../conf/*.xml "${final_path}/store/conf/" +#================================================= # Set permissions to jappix directory +#================================================= + sudo chown -R www-data: "$final_path" +#================================================= # Set and copy NGINX configuraion -sudo sed -i "s@PATHTOCHANGE2@${path}@g" ../conf/nginx.conf -path=${path:-/} +#================================================= + sudo sed -i "s@PATHTOCHANGE@${path}@g" ../conf/nginx.conf sudo sed -i "s@ALIASTOCHANGE@${final_path}/@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" +#================================================= # Validate language -[[ -a "${final_path}/i18n/${language}" ]] \ +#================================================= + +[[ -e "${final_path}/i18n/${language}" ]] \ || language="en" -# Store app settings -sudo yunohost app setting "$app" name -v "$name" -sudo yunohost app setting "$app" language -v "$language" - +#================================================= # Set Jappix configuration -sudo sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/main.xml" +#================================================= + sudo sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/hosts.xml" -sudo sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/main.xml" sudo sed -i "s@CHANGELANG@${language}@g" "${final_path}/store/conf/main.xml" sudo sed -i "s@CHANGENAME@${name}@g" "${final_path}/store/conf/main.xml" sudo sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/hosts.xml" - +#================================================= # Reload services +#================================================= + sudo service nginx reload diff --git a/scripts/remove b/scripts/remove index 893a4b0..da603b9 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,9 +1,12 @@ #!/bin/bash -app="jappix" +set -u +source /usr/share/yunohost/helpers + +app=$YNH_APP_INSTANCE_NAME # Retrieve arguments -domain=$(sudo yunohost app setting "$app" domain) +domain=$(ynh_app_setting_get "$app" domain) # Remove sources and configuration sudo rm -rf "/var/www/${app}" diff --git a/scripts/restore b/scripts/restore index 66fa81c..bffce4b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,12 +1,13 @@ #!/bin/bash # causes the shell to exit if any subcommand or pipeline returns a non-zero status -set -e - -app="jappix" +set -eu +source /usr/share/yunohost/helpers # Retrieve old app settings -domain=$(sudo yunohost app setting "$app" domain) +app=$YNH_APP_INSTANCE_NAME +domain=$(ynh_app_setting_get $app domain) + # Restore sources & data sudo cp -a ./sources "/var/www/${app}" diff --git a/scripts/upgrade b/scripts/upgrade index 245ffe8..4e4e187 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,47 +1,44 @@ #!/bin/bash -set -e +set -eu +source .fonctions +source /usr/share/yunohost/helpers -source ./_common.sh +app=$YNH_APP_INSTANCE_NAME -app="jappix" - -# Retrieve arguments -domain=$(sudo yunohost app setting "$app" domain) -path=$(sudo yunohost app setting "$app" path) -name=$(sudo yunohost app setting "$app" name) -language=$(sudo yunohost app setting "$app" language) +# Récupère les infos de l'application. +domain=$(ynh_app_setting_get $app domain) +path=$(ynh_app_setting_get $app path) +name=$(ynh_app_setting_get "$app" name) +language=$(ynh_app_setting_get "$app" language) # Set default values name="${name:-YunoJappix}" language="${language:-en}" # Remove trailing "/" for next commands -path=${path%/} - -# Retrieve sources -wget -q -O jappix.tar.gz "$JAPPIX_SOURCE_URL" +CHECK_PATH +#================================================= # Copy files to the right place +#================================================= + final_path="/var/www/${app}" +ynh_app_setting_set $app final_path $final_path +SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path sudo mkdir -p "${final_path}/store/conf" -sudo tar -C "$final_path" -xf jappix.tar.gz --strip-components 1 sudo cp ../conf/*.xml "${final_path}/store/conf/" # Set permissions to jappix directory sudo chown -R www-data: "$final_path" # Set and copy NGINX configuraion -sudo sed -i "s@PATHTOCHANGE2@${path}@g" ../conf/nginx.conf -path=${path:-/} sudo sed -i "s@PATHTOCHANGE@${path}@g" ../conf/nginx.conf sudo sed -i "s@ALIASTOCHANGE@${final_path}/@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" # Set Jappix configuration -sudo sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/main.xml" sudo sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/hosts.xml" -sudo sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/main.xml" sudo sed -i "s@CHANGELANG@${language}@g" "${final_path}/store/conf/main.xml" sudo sed -i "s@CHANGENAME@${name}@g" "${final_path}/store/conf/main.xml" sudo sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/hosts.xml"