mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
93 lines
3.1 KiB
Bash
93 lines
3.1 KiB
Bash
#!/bin/bash
|
|
|
|
# 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_url=path_to_normalize
|
|
# | arg: -p, --path_url - URL path to normalize before using it
|
|
ynh_normalize_url_path () {
|
|
# Declare an array to define the options of this helper.
|
|
local legacy_args=p
|
|
declare -Ar args_array=( [p]=path_url= )
|
|
local path_url
|
|
# Manage arguments with getopts
|
|
ynh_handle_getopts_args "$@"
|
|
|
|
test -n "$path_url" || ynh_die --message="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 --port=8080)
|
|
#
|
|
# usage: ynh_find_port --port=begin_port
|
|
# | arg: -p, --port - port to start to search
|
|
ynh_find_port () {
|
|
# Declare an array to define the options of this helper.
|
|
local legacy_args=p
|
|
declare -Ar args_array=( [p]=port= )
|
|
local port
|
|
# Manage arguments with getopts
|
|
ynh_handle_getopts_args "$@"
|
|
|
|
test -n "$port" || ynh_die --message="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
|
|
}
|
|
|
|
# Check availability of a web path
|
|
#
|
|
# example: ynh_webpath_available --domain=some.domain.tld --path_url=/coffee
|
|
#
|
|
# usage: ynh_webpath_available --domain=domain --path_url=path
|
|
# | arg: -d, --domain - the domain/host of the url
|
|
# | arg: -p, --path_url - the web path to check the availability of
|
|
ynh_webpath_available () {
|
|
# Declare an array to define the options of this helper.
|
|
local legacy_args=dp
|
|
declare -Ar args_array=( [d]=domain= [p]=path_url= )
|
|
local domain
|
|
local path_url
|
|
# Manage arguments with getopts
|
|
ynh_handle_getopts_args "$@"
|
|
|
|
sudo yunohost domain url-available $domain $path_url
|
|
}
|
|
|
|
# Register/book a web path for an app
|
|
#
|
|
# example: ynh_webpath_register --app=wordpress --domain=some.domain.tld --path_url=/coffee
|
|
#
|
|
# usage: ynh_webpath_register --app=app --domain=domain --path_url=path
|
|
# | arg: -a, --app - the app for which the domain should be registered
|
|
# | arg: -d, --domain - the domain/host of the web path
|
|
# | arg: -p, --path_url - the web path to be registered
|
|
ynh_webpath_register () {
|
|
# Declare an array to define the options of this helper.
|
|
local legacy_args=adp
|
|
declare -Ar args_array=( [a]=app= [d]=domain= [p]=path_url= )
|
|
local app
|
|
local domain
|
|
local path_url
|
|
# Manage arguments with getopts
|
|
ynh_handle_getopts_args "$@"
|
|
|
|
sudo yunohost app register-url $app $domain $path_url
|
|
}
|