diff --git a/scripts/.fonctions b/scripts/.fonctions index b4dac42..fc80811 100644 --- a/scripts/.fonctions +++ b/scripts/.fonctions @@ -108,25 +108,6 @@ CHECK_MD5_CONFIG () { # Created a backup of the config file if it was changed. fi } -FIND_PORT () { # Search free port - if [ YNH_VERSION = "2.5" ]; then - # $1 = Port number to start the search. - port=$1 - while ! sudo yunohost app checkport $port ; do - port=$((port+1)) - done - CHECK_VAR "$port" "port empty" - else - # $1 = Port number to start the search. - port=$1 - if [ "$(sudo yunohost tools port-available $port)" = "True" ]; then - port=$((port+1)) - fi - CHECK_VAR "$port" "port empty" - fi -} - - ### REMOVE SCRIPT REMOVE_NGINX_CONF () { # Delete nginx configuration @@ -179,6 +160,22 @@ REMOVE_SYS_USER () { # Delete user 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 +} + #================================================= # BACKUP #================================================= diff --git a/scripts/install b/scripts/install index 8abb53b..acf1b0f 100644 --- a/scripts/install +++ b/scripts/install @@ -38,7 +38,7 @@ CHECK_FINALPATH # Check final path domain_regex=$(echo "$domain" | sed 's@-@.@g') CHECK_VAR "$domain_regex" "domain_regex empty" -FIND_PORT 8095 # Check port availability +port=$(ynh_find_port 8096) # Check port availability # Save app settings ynh_app_setting_set $app admin $admin