Nouveau helper ynh_find_port

Nouveau helper pour trouver un port libre.

Déclinaison du code classique avec une vérification préalable de l'argument.
This commit is contained in:
Maniack Crudelis 2017-01-22 20:01:27 +01:00 committed by GitHub
parent fc7c35c319
commit 3e9d086f7f

15
data/helpers.d/network Normal file
View file

@ -0,0 +1,15 @@
# 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=$(echo "$1" | sed 's/[^0-9]//g') # Eliminate all non-digit characters
test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port."
while ! sudo yunohost app checkport $port --quiet # Check if the port is free
do
port=$((port+1)) # Else, pass to next port
done
echo $port
}