From d8ed05e786c4bddb32ef38444f902eca12997048 Mon Sep 17 00:00:00 2001 From: Rafi594 Date: Sat, 26 Oct 2019 22:42:12 +0200 Subject: [PATCH] fix ynh_find_port --- scripts/_common.sh | 17 +++++++++++++++++ scripts/install | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 4f728d8..601fa68 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -12,6 +12,23 @@ pkg_dependencies="build-essential libirrlicht-dev cmake libbz2-dev libpng-dev li # PERSONAL HELPERS #================================================= +# To remove once https://github.com/YunoHost/yunohost/pull/827 get merged +ynh_find_port () { + # Declare an array to define the options of this helper. + local legacy_args=p + declare -Ar args_array=( [p]=port= ) + local port + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + test -n "$port" || ynh_die --message="The argument of ynh_find_port must be a valid port." + while ss -nltu | grep -q -w :$port # Check if the port is free + do + port=$((port+1)) # Else, pass to next port + done + echo $port +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 76862b5..da1b344 100755 --- a/scripts/install +++ b/scripts/install @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh source /usr/share/yunohost/helpers +source _common.sh #================================================= # MANAGE SCRIPT FAILURE