mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
* Nouveau helper ynh_check_path Nouveau helper pour vérifier et corriger la syntaxe du path. Et ça permet de passer le test "incorrect_path" de package check * [fix] Bad comment * path en argument et normalize * Make commande more obvious * Do not use path * Adding behavior for / in the documentation
39 lines
No EOL
1.4 KiB
Text
39 lines
No EOL
1.4 KiB
Text
# Normalize the url path syntax
|
|
# Handle the slash at the beginning of path and its absence at ending
|
|
# Return a normalized url path
|
|
#
|
|
# example: url_path=$(ynh_normalize_url_path $url_path)
|
|
# ynh_normalize_url_path example -> /example
|
|
# ynh_normalize_url_path /example -> /example
|
|
# ynh_normalize_url_path /example/ -> /example
|
|
# ynh_normalize_url_path / -> /
|
|
#
|
|
# usage: ynh_normalize_url_path path_to_normalize
|
|
# | arg: url_path_to_normalize - URL path to normalize before using it
|
|
ynh_normalize_url_path () {
|
|
path_url=$1
|
|
test -n "$path_url" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing."
|
|
if [ "${path_url:0:1}" != "/" ]; then # If the first character is not a /
|
|
path_url="/$path_url" # Add / at begin of path variable
|
|
fi
|
|
if [ "${path_url:${#path_url}-1}" == "/" ] && [ ${#path_url} -gt 1 ]; then # If the last character is a / and that not the only character.
|
|
path_url="${path_url:0:${#path_url}-1}" # Delete the last character
|
|
fi
|
|
echo $path_url
|
|
}
|
|
|
|
# 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
|
|
} |