diff --git a/conf/monitorix.conf b/conf/monitorix.conf index dd8dbfd..4ffd05b 100644 --- a/conf/monitorix.conf +++ b/conf/monitorix.conf @@ -90,7 +90,7 @@ secure_log_date_format = %b %e libvirt = n process = y serv = y - mail = y + mail = n port = y user = y ftp = n @@ -192,7 +192,8 @@ secure_log_date_format = %b %e volt5 = \-12V volt6 = \-5V volt7 = Battery - gpu0 = nvidia + gpu0 = + #gpu0 = nvidia #enable that if you need nvidia gpu monitoring @@ -732,7 +733,7 @@ secure_log_date_format = %b %e # ----------------------------------------------------------------------------- enabled = n - url_prefix = https://YNH_DOMAINYNH_WWW_PATH + url_prefix = http://127.0.0.1:SERVICE_PORTYNH_WWW_PATH smtp_hostname = localhost from_address = noreply@YNH_DOMAIN hour = 0 diff --git a/conf/nginx.conf b/conf/nginx.conf index 8e99278..5fad826 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -7,6 +7,11 @@ location YNH_WWW_PATH { alias /var/lib/monitorix/www/$1; } + proxy_connect_timeout 600; + proxy_send_timeout 600; + proxy_read_timeout 600; + send_timeout 600; + # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } \ No newline at end of file diff --git a/scripts/_common.sh b/scripts/_common.sh index 8f520f4..33fb6db 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -14,15 +14,6 @@ init_script() { app=$YNH_APP_INSTANCE_NAME } -correct_path() { - if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; then - path="/$path" - fi - if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then - path="${path:0:${#path}-1}" - fi -} - get_source() { wget -q -O '/tmp/monitorix.deb' 'http://www.monitorix.org/monitorix_3.9.0-izzy1_all.deb' @@ -31,4 +22,160 @@ get_source() { then ynh_die "Error : can't get monitorix debian package" fi -} \ No newline at end of file +} + + +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) +} + +EXIT_PROPERLY () { # Provoque l'arrêt du script en cas d'erreur. Et nettoye les résidus. + exit_code=$? + if [ "$exit_code" -eq 0 ]; then + exit 0 # Quitte sans erreur si le script se termine correctement. + fi + trap '' EXIT + set +eu + echo -e "\e[91m \e[1m" # Shell in light red bold + echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!" >&2 + + if type -t CLEAN_SETUP > /dev/null; then # Vérifie l'existance de la fonction avant de l'exécuter. + CLEAN_SETUP # Appel la fonction de nettoyage spécifique du script install. + fi + + # Compense le bug de ssowat qui ne supprime pas l'entrée de l'app en cas d'erreur d'installation. + sudo sed -i "\@\"$domain$path/\":@d" /etc/ssowat/conf.json + + ynh_die +} + +TRAP_ON () { # Activate signal capture + set -eu # Exit if a command fail, and if a variable is used unset. + trap EXIT_PROPERLY EXIT # Capturing exit signals on shell script +} + +# 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_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 + if [ -e "$final_path" ] + then + echo "This path already contains a folder" >&2 + false + fi +} + +SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path +# $1 = Nom de l'archive téléchargée. + wget -nv -i ../sources/source_url -O $1 + # Vérifie la somme de contrôle de la source téléchargée. + md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false) + # Décompresse la source + if [ "$(echo ${1##*.})" == "gz" ]; then + tar -x -f $1 + elif [ "$(echo ${1##*.})" == "zip" ]; then + unzip -q $1 + else + false # Format d'archive non pris en charge. + fi + # Copie les fichiers sources + sudo cp -a $(cat ../sources/source_dir)/. "$final_path" + # Copie les fichiers additionnels ou modifiés. + if test -e "../sources/ajouts"; then + sudo cp -a ../sources/ajouts/. "$final_path" + fi +} + +STORE_MD5_CONFIG () { # Enregistre la somme de contrôle du fichier de config +# $1 = Nom du fichier de conf pour le stockage dans settings.yml +# $2 = Nom complet et chemin du fichier de conf. + ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1) +} + +CHECK_MD5_CONFIG () { # Créé un backup du fichier de config si il a été modifié. +# $1 = Nom du fichier de conf pour le stockage dans settings.yml +# $2 = Nom complet et chemin du fichier de conf. + if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then + sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup. + 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 +} diff --git a/scripts/backup b/scripts/backup index 85b1fc0..2983732 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,13 +1,27 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +######## Actually we cant use common script in backup / restore script see this issue for more informations : https://dev.yunohost.org/issues/621 +# # Import common cmd +# source ./_common.sh +# -# See comments in install script -app=$YNH_APP_INSTANCE_NAME +######## We implement manually this fonctions -# Source YunoHost helpers -source /usr/share/yunohost/helpers +init_script() { + # Exit on command errors and treat unset variables as an error + set -eu + + # Source YunoHost helpers + source /usr/share/yunohost/helpers + + # Retrieve arguments + app=$YNH_APP_INSTANCE_NAME +} + +######## End of common fonctions + +# Init script +init_script # # Dump the database dbname=$app diff --git a/scripts/install b/scripts/install index 7f925ec..1d31bd0 100755 --- a/scripts/install +++ b/scripts/install @@ -11,7 +11,7 @@ domain=$YNH_APP_ARG_DOMAIN path=$YNH_APP_ARG_PATH # Correct path if it is not correct -correct_path +CHECK_PATH # Check domain/path availability sudo yunohost app checkurl "${domain}${path}" -a "$app" \ @@ -35,18 +35,10 @@ ynh_app_setting_set "$app" mysqlpwd "$dbpass" ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" # Find a port for built-in monitorix HTTP server -port='' -findPort () { - port=$1 - - while ! sudo yunohost app checkport $port ; do - port=$(($port + 1)) - done -} -findPort 8080 +FIND_PORT 8080 http_port=$port ynh_app_setting_set $app http_port $http_port -findPort $(($port +1)) +FIND_PORT $(($port +1)) nginx_status_port=$port ynh_app_setting_set $app nginx_status_port $nginx_status_port diff --git a/scripts/restore b/scripts/restore index 9b9dbee..53b2344 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,24 @@ #!/bin/bash -# Import common cmd -source ./_common.sh +######## Actually we cant use common script in backup / restore script see this issue for more informations : https://dev.yunohost.org/issues/621 +# # Import common cmd +# source ./_common.sh +# + +######## We implement manually this fonctions + +init_script() { + # Exit on command errors and treat unset variables as an error + set -eu + + # Source YunoHost helpers + source /usr/share/yunohost/helpers + + # Retrieve arguments + app=$YNH_APP_INSTANCE_NAME +} + +######## End of common fonctions # Init script init_script @@ -14,7 +31,7 @@ domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) # Correct path if it is not correct -correct_path +CHECK_PATH # Check domain/path availability sudo yunohost app checkurl "${domain}${path}" -a "$app" \ diff --git a/scripts/upgrade b/scripts/upgrade index f349024..bbe5634 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -16,7 +16,7 @@ dbname=$app dbpass=$(ynh_app_setting_get "$app" mysqlpwd) # Correct path if it is not correct -correct_path +CHECK_PATH # Download package get_source