diff options
Diffstat (limited to 'etc/library.sh')
-rw-r--r-- | etc/library.sh | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/etc/library.sh b/etc/library.sh index 755a4cb2..b382bad0 100644 --- a/etc/library.sh +++ b/etc/library.sh @@ -11,6 +11,12 @@ export NCPCFG=${NCPCFG:-/usr/local/etc/ncp.cfg} export CFGDIR=/usr/local/etc/ncp-config.d export BINDIR=/usr/local/bin/ncp +export NCDIR=/var/www/nextcloud + +export TRUSTED_DOMAINS=( + [ip]=1 [dnsmasq]=2 [nc_domain]=3 [nextcloudpi-local]=5 [docker_overwrite]=6 + [nextcloudpi]=7 [nextcloudpi-lan]=8 [public_ip]=11 [letsencrypt_1]=12 + [letsencrypt_2]=13 [trusted_domain_1]=20 [trusted_domain_1]=21 [trusted_domain_1]=22) command -v jq &>/dev/null || { apt-get update @@ -18,10 +24,11 @@ command -v jq &>/dev/null || { } [[ -f "$NCPCFG" ]] && { - NCVER=$( jq -r .nextcloud_version < "$NCPCFG") - PHPVER=$( jq -r .php_version < "$NCPCFG") - RELEASE=$(jq -r .release < "$NCPCFG") + NCLATESTVER=$(jq -r .nextcloud_version < "$NCPCFG") + PHPVER=$( jq -r .php_version < "$NCPCFG") + RELEASE=$( jq -r .release < "$NCPCFG") } +command -v ncc &>/dev/null && NCVER="$(ncc status | grep "version:" | awk '{ print $3 }')" function configure_app() { @@ -101,6 +108,45 @@ function configure_app() return $ret } +function set-nc-domain() +{ + local domain="${1?}" + domain="$(sed 's|http.\?://||;s|\(/.*\)||' <<<"${domain}")" + if [[ "${domain}" == "" ]] || is_an_ip "${domain}"; then + echo "warning: No domain found. Defaulting to '$(hostname)'" + domain="$(hostname)" + fi + local proto + proto="$(ncc config:system:get overwriteprotocol)" || true + [[ "${proto}" == "" ]] && proto="https" + local url="${proto}://${domain%*/}" + # trusted_domain no 3 will always contain the overwrite domain + [[ "$2" == "--no-trusted-domain" ]] || ncc config:system:set trusted_domains 3 --value="${domain%*/}" + ncc config:system:set overwrite.cli.url --value="${url}/" + if is_ncp_activated && is_app_enabled notify_push; then + ncc config:system:set trusted_proxies 11 --value="127.0.0.1" + ncc config:system:set trusted_proxies 12 --value="::1" + ncc config:system:set trusted_proxies 13 --value="${domain}" + ncc config:system:set trusted_proxies 14 --value="$(dig +short "${domain}")" + sleep 5 # this seems to be required in the VM for some reason. We get `http2 error: protocol error` after ncp-upgrade-nc + ncc notify_push:setup "${url}/push" + fi +} + +function start_notify_push +{ + pgrep notify_push &>/dev/null && return + if [[ -f /.docker-image ]]; then + local arch + arch="$(uname -m)" + [[ "${arch}" =~ "armv7" ]] && arch="armv7" + sudo -u www-data /var/www/nextcloud/apps/notify_push/bin/"${arch}"/notify_push --allow-self-signed /var/www/nextcloud/config/config.php &>/dev/null & + else + systemctl enable --now notify_push + fi + sleep 5 # apparently we need to make sure we wait until the database is written or something +} + function run_app() { local ncp_app=$1 @@ -304,6 +350,12 @@ function is_more_recent_than() return 0 } +function is_app_enabled() +{ + local app="$1" + ncc app:list | sed '0,/Disabled/!d' | grep -q "${app}" +} + function check_distro() { local cfg="${1:-$NCPCFG}" @@ -312,6 +364,22 @@ function check_distro() return 1 } +function nc_version() +{ + ncc status | grep "version:" | awk '{ print $3 }' +} + +function is_an_ip() +{ + local ip_or_domain="${1}" + grep -oPq '\d{1,3}(.\d{1,3}){3}' <<<"${ip_or_domain}" +} + +function is_ncp_activated() +{ + ! a2query -s ncp-activation -q +} + function clear_password_fields() { local cfg_file="$1" |