1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/duniter_ynh.git synced 2024-09-03 18:26:35 +02:00

[enh] Add ynh_find_port helper

This commit is contained in:
nemsia 2017-05-10 22:17:00 +02:00
parent 2ddb2cc18e
commit 03feb876a2
2 changed files with 18 additions and 4 deletions

View file

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

View file

@ -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