yunohost/data/helpers.d/network
2017-01-23 15:17:13 +01:00

15 lines
468 B
Text

# 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 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
}