2021-11-30 18:20:42 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ -z "$NC_DOMAIN" ]; then
|
|
|
|
echo "NC_DOMAIN and NEXTCLOUD_HOST need to be provided. Exiting!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Need write access to /mnt/data
|
|
|
|
if ! [ -w /mnt/data ]; then
|
|
|
|
echo "Cannot write to /mnt/data"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Only start container if nextcloud is accessible
|
|
|
|
while ! nc -z "$NEXTCLOUD_HOST" 9000; do
|
|
|
|
echo "Waiting for Nextcloud to start..."
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
2023-08-17 16:51:55 +08:00
|
|
|
# Get ipv4-address of Apache
|
2023-11-06 21:16:54 +08:00
|
|
|
IPv4_ADDRESS="$(dig nextcloud-aio-apache A +short +search | head -1)"
|
2023-08-17 16:51:55 +08:00
|
|
|
# Bring it in CIDR notation
|
2023-08-17 17:00:50 +08:00
|
|
|
# shellcheck disable=SC2001
|
2023-08-17 16:51:55 +08:00
|
|
|
IPv4_ADDRESS="$(echo "$IPv4_ADDRESS" | sed 's|[0-9]\+$|1/32|')"
|
|
|
|
|
2021-12-09 01:12:56 +08:00
|
|
|
if [ -z "$APACHE_PORT" ]; then
|
|
|
|
export APACHE_PORT="443"
|
|
|
|
fi
|
|
|
|
|
2022-06-15 18:42:14 +08:00
|
|
|
# Change variables in case of reverse proxies
|
2021-12-09 01:12:56 +08:00
|
|
|
if [ "$APACHE_PORT" != '443' ]; then
|
|
|
|
export PROTOCOL="http"
|
|
|
|
export NC_DOMAIN=""
|
|
|
|
else
|
|
|
|
export PROTOCOL="https"
|
2022-06-15 18:42:14 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Change the auto_https in case of reverse proxies
|
|
|
|
if [ "$APACHE_PORT" != '443' ]; then
|
|
|
|
CADDYFILE="$(sed 's|auto_https.*|auto_https off|' /Caddyfile)"
|
|
|
|
else
|
2022-05-29 22:25:00 +08:00
|
|
|
CADDYFILE="$(sed 's|auto_https.*|auto_https disable_redirects|' /Caddyfile)"
|
2021-12-09 01:12:56 +08:00
|
|
|
fi
|
2023-07-13 21:18:32 +08:00
|
|
|
echo "$CADDYFILE" > /tmp/Caddyfile
|
2021-12-09 01:12:56 +08:00
|
|
|
|
2022-06-15 18:42:14 +08:00
|
|
|
# Change the trusted_proxies in case of reverse proxies
|
|
|
|
if [ "$APACHE_PORT" != '443' ]; then
|
2023-07-13 21:18:32 +08:00
|
|
|
CADDYFILE="$(sed 's|# trusted_proxies placeholder|trusted_proxies static private_ranges|' /tmp/Caddyfile)"
|
2022-06-15 18:42:14 +08:00
|
|
|
else
|
2023-08-17 16:51:55 +08:00
|
|
|
CADDYFILE="$(sed "s|# trusted_proxies placeholder|trusted_proxies static $IPv4_ADDRESS|" /tmp/Caddyfile)"
|
2022-06-15 18:42:14 +08:00
|
|
|
fi
|
2023-07-13 21:18:32 +08:00
|
|
|
echo "$CADDYFILE" > /tmp/Caddyfile
|
2022-06-15 18:42:14 +08:00
|
|
|
|
2024-02-01 20:25:22 +08:00
|
|
|
# Remove additional domain if not given
|
|
|
|
if [ -z "$ADDITIONAL_TRUSTED_DOMAIN" ]; then
|
|
|
|
CADDYFILE="$(sed '/ADDITIONAL_TRUSTED_DOMAIN/d' /tmp/Caddyfile)"
|
|
|
|
fi
|
|
|
|
echo "$CADDYFILE" > /tmp/Caddyfile
|
|
|
|
|
2023-02-12 03:49:30 +08:00
|
|
|
# Fix the Caddyfile format
|
2023-07-13 21:18:32 +08:00
|
|
|
caddy fmt --overwrite /tmp/Caddyfile
|
2023-02-12 03:49:30 +08:00
|
|
|
|
2021-11-30 18:20:42 +08:00
|
|
|
# Add caddy path
|
|
|
|
mkdir -p /mnt/data/caddy/
|
|
|
|
|
2023-05-19 22:29:45 +08:00
|
|
|
# Add caddy import path
|
|
|
|
mkdir -p /mnt/data/caddy-imports
|
|
|
|
|
2023-05-21 00:41:12 +08:00
|
|
|
# Remove falsely added Nextcloud conf
|
|
|
|
rm -f /mnt/data/caddy-imports/nextcloud
|
|
|
|
|
2023-08-28 03:16:12 +08:00
|
|
|
# Make sure that the caddy-imports dir is not empty
|
2023-05-21 00:58:36 +08:00
|
|
|
echo "# empty file so that caddy does not print a warning" > /mnt/data/caddy-imports/empty
|
2023-05-21 00:36:43 +08:00
|
|
|
|
2023-01-28 02:43:55 +08:00
|
|
|
# Fix apache startup
|
|
|
|
rm -f /usr/local/apache2/logs/httpd.pid
|
2021-11-30 18:20:42 +08:00
|
|
|
|
2023-01-28 02:43:55 +08:00
|
|
|
exec "$@"
|