diff --git a/scripts/functions.sh b/scripts/functions.sh index 9dd401b..6a50fe7 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -56,3 +56,20 @@ fi # Remove Duniter package sudo dpkg -r duniter } + +# 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 +} + diff --git a/scripts/install b/scripts/install index d3584e1..ebb64fb 100755 --- a/scripts/install +++ b/scripts/install @@ -22,10 +22,7 @@ sudo yunohost app checkurl "${domain}${path}" -a "$app" \ || ynh_die "Path not available: ${domain}${path}" # Check port availability -sudo yunohost app checkport $port -if [[ ! $? -eq 0 ]]; then - ynh_die "Port not available: ${port}" -fi +port=$(ynh_find_port $port) # Check node availability if curl --output /dev/null --silent --head --fail "$sync_node:$sync_port/node/summary"; then