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
|
|
|
|
|
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
|
2022-05-29 22:25:00 +08:00
|
|
|
echo "$CADDYFILE" > /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-05-20 02:58:06 +08:00
|
|
|
CADDYFILE="$(sed 's|# trusted_proxies placeholder|trusted_proxies static private_ranges|' /Caddyfile)"
|
2022-06-15 18:42:14 +08:00
|
|
|
else
|
2023-05-20 02:58:06 +08:00
|
|
|
CADDYFILE="$(sed 's|trusted_proxies.*private_ranges|# trusted_proxies placeholder|' /Caddyfile)"
|
2022-06-15 18:42:14 +08:00
|
|
|
fi
|
|
|
|
echo "$CADDYFILE" > /Caddyfile
|
|
|
|
|
2023-02-12 03:49:30 +08:00
|
|
|
# Fix the Caddyfile format
|
|
|
|
caddy fmt --overwrite /Caddyfile
|
|
|
|
|
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-05-21 00:36:43 +08:00
|
|
|
# Makre 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 "$@"
|