From a919a3198b6285146a599556a624794aa3e9f902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 21 Jul 2017 15:00:56 +0200 Subject: [PATCH] Full app Update --- conf/app.src | 13 +++++ manifest.json | 24 ++++----- scripts/_common.sh | 127 ++++----------------------------------------- scripts/backup | 20 +++++++ scripts/change_url | 45 ++++++++++++++++ scripts/install | 45 +++++++--------- scripts/remove | 22 ++++---- scripts/restore | 22 ++++++++ scripts/upgrade | 33 ++++++------ 9 files changed, 168 insertions(+), 183 deletions(-) create mode 100644 conf/app.src create mode 100644 scripts/backup create mode 100644 scripts/change_url create mode 100644 scripts/restore diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..42021cd --- /dev/null +++ b/conf/app.src @@ -0,0 +1,13 @@ + + +SOURCE_URL=https://github.com/vector-im/riot-web/releases/download/v0.11.4/riot-v0.11.4.tar.gz +SOURCE_SUM=792b8eb398ec08c6f32f64b27f92d31d658c6d2338c1e43c84136f25f64d1cb2 +# (Optional) Program to check the integrity (sha256sum, md5sum...) +# default: sha256 +SOURCE_SUM_PRG=sha256sum +# (Optional) Archive format +# default: tar.gz +SOURCE_FORMAT=tar.gz +# (Optional) Put false if sources are directly in the archive root +# default: true +SOURCE_IN_SUBDIR=true diff --git a/manifest.json b/manifest.json index f9bfb73..cf345f2 100644 --- a/manifest.json +++ b/manifest.json @@ -3,14 +3,14 @@ "id": "riot", "packaging_format": 1, "requirements": { - "yunohost": ">= 2.4" + "yunohost": ">= 2.6.4" }, "description": { "en": "A web client for matrix", "fr": "Un client web pour matrix" }, - "version": "1.0", - "url": "http://www.site", + "version": "11.4", + "url": "https://riot.im", "license": "free", "maintainer": { "name": "Josué Tille", @@ -50,15 +50,15 @@ "example": "my-own-homeserver.tld", "default": "matrix.org" }, - { - "name": "is_public", - "type": "boolean", - "ask": { - "en": "Is it a public server ?", - "fr": "Est-ce un serveur publique ?" - }, - "default": "0" - } + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public server ?", + "fr": "Est-ce un serveur publique ?" + }, + "default": "0" + } ] } } diff --git a/scripts/_common.sh b/scripts/_common.sh index 638b0f7..1494571 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,122 +1,17 @@ #!/bin/bash -## Adapt md5sum while you update app -md5sum="e561dda5a9cc1f5c2dcef011cabff725" -riot_version="0.11.4" +# Retrieve arguments +app=$YNH_APP_INSTANCE_NAME +final_path="/var/www/$app" -init_script() { - # Exit on command errors and treat unset variables as an error - set -eu +config_nginx() { + cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf - # Source YunoHost helpers - source /usr/share/yunohost/helpers - - # Retrieve arguments - app=$YNH_APP_INSTANCE_NAME - CHECK_VAR "$app" "app name not set" + ynh_replace_string __PATH__ $path /etc/nginx/conf.d/$domain.d/$app.conf + ynh_replace_string __FINALPATH__ $final_path /etc/nginx/conf.d/$domain.d/$app.conf } -get_source() { - - wget -q -O '/tmp/riot.tar.gz' "https://github.com/vector-im/riot-web/releases/download/v${riot_version}/riot-v${riot_version}.tar.gz" - - if [[ ! -e '/tmp/riot.tar.gz' ]] || [[ $(md5sum '/tmp/riot.tar.gz' | cut -d' ' -f1) != $md5sum ]] - then - ynh_die "Error : can't get Riot source" - fi - tar xzf '/tmp/riot.tar.gz' - sudo cp -r riot-v${riot_version}/. $final_path/ - sudo chown www-data -R $final_path - sudo chmod 740 -R $final_path -} - - -CHECK_VAR () { # Vérifie que la variable n'est pas vide. -# $1 = Variable à vérifier -# $2 = Texte à afficher en cas d'erreur - test -n "$1" || (echo "$2" >&2 && false) -} - -# Ignore the yunohost-cli log to prevent errors with conditionals commands -# usage: NO_LOG COMMAND -# Simply duplicate the log, execute the yunohost command and replace the log without the result of this command -# It's a very badly hack... -# Petite copie perso à mon usage ;) -NO_LOG() { - ynh_cli_log=/var/log/yunohost/yunohost-cli.log - sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move - eval $@ - exit_code=$? - sudo mv ${ynh_cli_log}-move ${ynh_cli_log} - return $? -} - -CHECK_USER () { # Vérifie la validité de l'user admin -# $1 = Variable de l'user admin. - ynh_user_exists "$1" || (echo "Wrong admin" >&2 && false) -} - -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_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé. - final_path=/var/www/$app - if [ -e "$final_path" ] - then - echo "This path already contains a folder" >&2 - false - fi -} - -FIND_PORT () { # Cherche un port libre. -# $1 = Numéro de port pour débuter la recherche. - port=$1 - while ! sudo yunohost app checkport $port ; do - port=$((port+1)) - done - CHECK_VAR "$port" "port empty" -} - -### REMOVE SCRIPT - -REMOVE_NGINX_CONF () { # Suppression de la configuration nginx - if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config - echo "Delete nginx config" - sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" - sudo service nginx reload - fi -} - -SECURE_REMOVE () { # Suppression de dossier avec vérification des variables - chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables. - no_var=0 - while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine - do - no_var=1 - global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole la première variable trouvée. - only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole complètement la variable en ajoutant le $ au début et en gardant uniquement le nom de la variable. Se débarrasse surtout du / et d'un éventuel chemin derrière. - real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` permet d'interpréter une variable contenue dans une variable. - if test -z "$real_var" || [ "$real_var" = "/" ]; then - echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2 - return 1 - fi - chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # remplace la variable par sa valeur dans la chaine. - done - if [ "$no_var" -eq 1 ] - then - if [ -e "$chaine" ]; then - echo "Delete directory $chaine" - sudo rm -r "$chaine" - fi - return 0 - else - echo "No detected variable." >&2 - return 1 - fi -} +config_riot() { + cp ../conf/config.json $final_path/config.json + ynh_replace_string __DEFAULT_SERVER__ $default_home_server $final_path/config.json +} \ No newline at end of file diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..6becff6 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,20 @@ +#!/bin/bash + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Stop script if errors +ynh_abort_if_errors + +# Import common cmd +source ../settings/scripts/_common.sh + +# Retrieve arguments +domain=$(ynh_app_setting_get $app domain) + +# Copy Nginx config +ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" + +# Backup riot files +ynh_backup "/var/www/$app" + diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..520c338 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,45 @@ +#!/bin/bash + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Import common cmd +source ./_common.sh + +# Retrive arguments +old_domain=$YNH_APP_OLD_DOMAIN +old_path=$(ynh_normalize_url_path $YNH_APP_OLD_PATH) +new_domain=$YNH_APP_NEW_DOMAIN +new_path=$(ynh_normalize_url_path $YNH_APP_NEW_PATH) + +# CHECK WHICH PARTS SHOULD BE CHANGED +change_domain=0 +if [ "$old_domain" != "$new_domain" ] +then + change_domain=1 +fi + +change_path=0 +if [ "$old_path" != "$new_path" ] +then + change_path=1 +fi + +# STANDARD MODIFICATIONS +# MODIFY URL IN NGINX CONF +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# Change the path in the nginx config file +if [ $change_path -eq 1 ] +then + ynh_replace_string "location $old_path" "location $new_path" "$nginx_conf_path" +fi + +# Change the domain for nginx +if [ $change_domain -eq 1 ] +then + sudo mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf +fi + +# Reload services +sudo systemctl reload nginx.service \ No newline at end of file diff --git a/scripts/install b/scripts/install index 75dea2a..7407e56 100644 --- a/scripts/install +++ b/scripts/install @@ -1,47 +1,42 @@ #!/bin/bash +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Stop script if errors +ynh_abort_if_errors + # Import common cmd source ./_common.sh -# Init script -init_script - # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH +path=$(ynh_normalize_url_path $YNH_APP_ARG_PATH) is_public=$YNH_APP_ARG_IS_PUBLIC default_home_server=$YNH_APP_ARG_DEFAULT_HOME_SERVER -CHECK_PATH # Vérifie et corrige la syntaxe du path. -CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé. - # Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +test $(ynh_webpath_available $domain $path) == 'True' || ynh_die "$domain$path is not available, please use an other domain or path." +ynh_webpath_register $app $domain $path + +# Check Final Path availability +test ! -e "$final_path" || ynh_die "This path already contains a folder" # Enregistre les infos dans la config YunoHost -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app default_home_server $default_home_server - -# Créer le repertoire de destination et stocke son emplacement. -sudo mkdir "$final_path" ynh_app_setting_set $app final_path $final_path # Get source and install in source dir -get_source +ynh_setup_source $final_path/ +chown www-data -R $final_path +chmod 740 -R $final_path -# Et copie le fichier de config nginx -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf - -# Modifie les variables dans le fichier de configuration nginx -sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf -sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf +# Config nginx +config_nginx # Update Riot config -sudo cp ../conf/config.json $final_path/config.json -sudo sed -i "s@__DEFAULT_SERVER__@$default_home_server@g" $final_path/config.json +config_riot if [ "$is_public" = "0" ]; then # Retire l'accès public @@ -51,6 +46,4 @@ else fi # Recharge la configuration Nginx -sudo service nginx reload -# Régénère la configuration de SSOwat -sudo yunohost app ssowatconf +systemctl reload nginx.service diff --git a/scripts/remove b/scripts/remove index 82eaaad..c1d951d 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,20 +1,20 @@ #!/bin/bash +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Stop script if errors +set -u + # Import common cmd source ./_common.sh -# Init script -init_script - +# Retrieve arguments domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) -SECURE_REMOVE '/var/www/$app' # Suppression du dossier de l'application +ynh_secure_remove "/var/www/$app" -REMOVE_NGINX_CONF # Suppression de la configuration nginx +# Suppression de la configuration nginx +ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" +systemctl reload nginx.service -# Suppression d'un dossier -SECURE_REMOVE '/etc/$app/' - -# Régénère la configuration de SSOwat -sudo yunohost app ssowatconf diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..ce34e74 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,22 @@ +#!/bin/bash + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Stop script if errors +ynh_abort_if_errors + +# Import common cmd +source ../settings/scripts/_common.sh + +# Retrieve arguments +domain=$(ynh_app_setting_get $app domain) +path=$(ynh_app_setting_get $app path) + +# Check domain/path availability +ynh_webpath_available $domain $path || ynh_die "$domain/$path is not available, please use an other domain or path." + +# Restore all config and data +ynh_restore + + diff --git a/scripts/upgrade b/scripts/upgrade index cb83406..d6f5ee6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,34 +1,31 @@ #!/bin/bash +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Stop script if errors +ynh_abort_if_errors + # Import common cmd source ./_common.sh -# Init script -init_script - +# Retrieve arguments domain=$(ynh_app_setting_get $app domain) -path=$(ynh_app_setting_get $app path) +path=$(ynh_normalize_url_path $(ynh_app_setting_get $app path)) is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) default_home_server=$(ynh_app_setting_get $app default_home_server) -CHECK_PATH # Vérifie et corrige la syntaxe du path. - # Get source and install in source dir -get_source +ynh_setup_source $final_path/ +chown www-data -R $final_path +chmod 740 -R $final_path -# Et copie le fichier de config nginx -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf - -# Modifie les variables dans le fichier de configuration nginx -sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf -sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf +# Update nginx config +config_nginx # Update Riot config -sudo cp ../conf/config.json $final_path/config.json -sudo sed -i "s@__DEFAULT_SERVER__@$default_home_server@g" $final_path/config.json +config_riot # Recharge la configuration Nginx -sudo service nginx reload -# Régénère la configuration de SSOwat -sudo yunohost app ssowatconf +systemctl reload nginx.service