From 3e9d086f7ff64f923b2d623df41ec42c88c8a8ef Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 22 Jan 2017 20:01:27 +0100 Subject: [PATCH 1/3] Nouveau helper ynh_find_port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nouveau helper pour trouver un port libre. Déclinaison du code classique avec une vérification préalable de l'argument. --- data/helpers.d/network | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 data/helpers.d/network diff --git a/data/helpers.d/network b/data/helpers.d/network new file mode 100644 index 000000000..080ac68e2 --- /dev/null +++ b/data/helpers.d/network @@ -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 +} From cd93427a97378ab635c85c0ae9a1e45132d6245c Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Mon, 23 Jan 2017 15:17:13 +0100 Subject: [PATCH 2/3] Retire la commande ynh --- data/helpers.d/network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/helpers.d/network b/data/helpers.d/network index 080ac68e2..e06656820 100644 --- a/data/helpers.d/network +++ b/data/helpers.d/network @@ -7,7 +7,7 @@ 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 + while netcat -z 127.0.0.1 $port # Check if the port is free do port=$((port+1)) # Else, pass to next port done From 901e3df9b604f542f2c460aad05bcc8efc9fd054 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Mon, 23 Jan 2017 15:18:52 +0100 Subject: [PATCH 3/3] Pas de correction de l'argument --- data/helpers.d/network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/helpers.d/network b/data/helpers.d/network index e06656820..42616d513 100644 --- a/data/helpers.d/network +++ b/data/helpers.d/network @@ -5,7 +5,7 @@ # 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 + 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