#!/bin/bash ## Adapt md5sum while you update app md5sum="7314ad6fcd014a34c2e4e8a95455bcaa" monitorix_version="3.9.0" 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 } get_source() { wget -q -O '/tmp/monitorix.deb' "http://www.monitorix.org/monitorix_${monitorix_version}-izzy1_all.deb" if [[ ! -e '/tmp/monitorix.deb' ]] || [[ $(md5sum '/tmp/monitorix.deb' | cut -d' ' -f1) != $md5sum ]] then ynh_die "Error : can't get monitorix debian package" fi } 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) } 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 } # 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_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 }