-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy path_common.sh
58 lines (50 loc) · 2.13 KB
/
_common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
#=================================================
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
# Define a function to execute commands with `occ`
exec_occ() {
(cd "$install_dir" && ynh_exec_as_app \
php${php_version} --define apc.enable_cli=1 occ --no-interaction --no-ansi "$@")
}
wait_nginx_reload() {
# NGINX may take some time to support the new configuration,
# wait for the Nextcloud configuration file to disappear from NGINX before checking the CalDAV/CardDAV URL.
timeout=30
for i in $(seq 1 $timeout); do
if ! ynh_hide_warnings nginx -T | grep --quiet "# configuration file /etc/nginx/conf.d/$domain.d/$app.conf:"; then
break
fi
sleep 1
done
# Wait untils NGINX has fully reloaded (avoid cURL fail with http2)
sleep 2
}
# Check if an URL is already handled
# usage: is_url_handled --domain=DOMAIN --path=PATH_URI
is_url_handled() {
# Declare an array to define the options of this helper.
local legacy_args=dp
declare -Ar args_array=( [d]=domain= [p]=path= )
local domain
local path
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Try to get the URL with cURL, and keep the http code and an eventual redirection URL.
local curl_output="$(curl --insecure --silent --output /dev/null \
--write-out '%{http_code};%{redirect_url}' https://127.0.0.1$path --header "Host: $domain" --resolve $domain:443:127.0.0.1)"
# Cut the output and keep only the first part to keep the http code
local http_code="${curl_output%%;*}"
# Do the same thing but keep the second part, the redirection URL
local redirection="${curl_output#*;}"
# Return 1 if the URL isn't handled.
# Which means either cURL got a 404 (or the admin) or the SSO.
# A handled URL should redirect to a publicly accessible URL.
# Return 1 if the URL has returned 404
if [ "$http_code" = "404" ] || [[ $redirection =~ "/yunohost/admin" ]]; then
return 1
# Return 1 if the URL is redirected to the SSO
elif [[ $redirection =~ "/yunohost/sso" ]]; then
return 1
fi
}