2021-03-28 12:38:25 +11:00
|
|
|
#!/bin/ash -e
|
2026-02-18 14:40:46 -05:00
|
|
|
# shellcheck shell=dash
|
|
|
|
|
|
2025-12-14 15:02:06 -05:00
|
|
|
# check for .env file or symlink and generate app keys if missing
|
2026-02-18 14:40:46 -05:00
|
|
|
if [ -f /pelican-data/.env ]; then
|
|
|
|
|
echo ".env vars exist."
|
2026-01-18 16:21:33 -05:00
|
|
|
# load specific env vars from .env used in the entrypoint and they are not already set
|
2026-02-18 14:40:46 -05:00
|
|
|
for VAR in "APP_KEY" "APP_INSTALLED" "DB_CONNECTION" "DB_HOST" "DB_PORT"; do
|
|
|
|
|
echo "checking for ${VAR}"
|
|
|
|
|
## skip if it looks like it might try to execute code
|
|
|
|
|
if (grep "${VAR}" .env | grep -qE "\$\(|=\`|\$#"); then echo "var in .env may be executable or a comment, skipping"; continue; fi
|
|
|
|
|
# if the variable is in .env then set it
|
|
|
|
|
if (grep -q "${VAR}" .env); then
|
|
|
|
|
echo "loading ${VAR} from .env"
|
|
|
|
|
export "$(grep "${VAR}" .env | sed 's/"//g')"
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
## variable wasn't loaded or in the env to set
|
|
|
|
|
echo "didn't find variable to set"
|
|
|
|
|
done
|
2024-06-27 14:56:49 -04:00
|
|
|
else
|
2026-02-18 14:40:46 -05:00
|
|
|
echo ".env vars don't exist."
|
2025-01-23 01:01:14 -08:00
|
|
|
# webroot .env is symlinked to this path
|
2024-06-27 14:56:49 -04:00
|
|
|
touch /pelican-data/.env
|
|
|
|
|
|
2025-12-14 15:02:06 -05:00
|
|
|
# manually generate a key because key generate --force fails
|
2026-02-18 14:40:46 -05:00
|
|
|
if [ -z "${APP_KEY}" ]; then
|
|
|
|
|
echo "No key set, Generating key."
|
2025-12-05 22:50:49 -05:00
|
|
|
APP_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
|
2026-02-18 14:40:46 -05:00
|
|
|
echo "APP_KEY=$APP_KEY" > /pelican-data/.env
|
|
|
|
|
echo "Generated app key written to .env file"
|
2024-06-27 14:56:49 -04:00
|
|
|
else
|
2026-02-18 14:40:46 -05:00
|
|
|
echo "APP_KEY exists in environment, using that."
|
2026-04-23 08:41:44 -05:00
|
|
|
echo "APP_KEY=${APP_KEY}" > /pelican-data/.env
|
2024-06-27 14:56:49 -04:00
|
|
|
fi
|
2024-10-15 22:36:35 +02:00
|
|
|
|
2025-12-14 15:02:06 -05:00
|
|
|
# enable installer
|
2026-02-18 14:40:46 -05:00
|
|
|
echo "APP_INSTALLED=false" >> /pelican-data/.env
|
2024-06-27 14:56:49 -04:00
|
|
|
fi
|
|
|
|
|
|
2025-12-14 15:02:06 -05:00
|
|
|
# create directories for volumes
|
2026-01-19 09:15:18 -05:00
|
|
|
mkdir -p /pelican-data/database /pelican-data/storage/avatars /pelican-data/storage/fonts /pelican-data/storage/icons /pelican-data/plugins /var/www/html/storage/logs/supervisord 2>/dev/null
|
2024-06-27 14:56:49 -04:00
|
|
|
|
2025-12-14 15:02:06 -05:00
|
|
|
# if the app is installed then we need to run migrations on start. New installs will run migrations when you run the installer.
|
2026-02-18 14:40:46 -05:00
|
|
|
if [ "${APP_INSTALLED}" = "true" ]; then
|
2025-12-14 15:02:06 -05:00
|
|
|
#if the db is anything but sqlite wait until it's accepting connections
|
|
|
|
|
if [ "${DB_CONNECTION}" != "sqlite" ]; then
|
|
|
|
|
# check for DB up before starting the panel
|
|
|
|
|
echo "Checking database status."
|
2026-04-23 08:41:44 -05:00
|
|
|
until nc -z -v -w30 "${DB_HOST}" "${DB_PORT}"
|
2025-12-14 15:02:06 -05:00
|
|
|
do
|
|
|
|
|
echo "Waiting for database connection..."
|
|
|
|
|
# wait for 1 seconds before check again
|
|
|
|
|
sleep 1
|
|
|
|
|
done
|
2026-02-18 14:40:46 -05:00
|
|
|
else
|
|
|
|
|
echo "using sqlite database"
|
2025-12-14 15:02:06 -05:00
|
|
|
fi
|
2026-02-18 14:40:46 -05:00
|
|
|
|
2025-12-14 15:02:06 -05:00
|
|
|
# run migration
|
|
|
|
|
php artisan migrate --force
|
2026-04-23 08:41:44 -05:00
|
|
|
|
|
|
|
|
php artisan p:plugin:composer
|
2024-06-27 14:56:49 -04:00
|
|
|
fi
|
2018-11-10 18:57:49 -05:00
|
|
|
|
2026-02-18 14:40:46 -05:00
|
|
|
echo "Optimizing Filament"
|
2024-10-12 10:58:18 -04:00
|
|
|
php artisan filament:optimize
|
|
|
|
|
|
2025-08-10 14:30:58 -05:00
|
|
|
# default to caddy not starting
|
2024-09-27 17:36:45 -04:00
|
|
|
export SUPERVISORD_CADDY=false
|
2026-02-18 14:40:46 -05:00
|
|
|
export CADDY_APP_URL="${APP_URL}"
|
2025-12-05 22:50:49 -05:00
|
|
|
|
2026-02-18 14:40:46 -05:00
|
|
|
# checking if app url is https
|
|
|
|
|
if (echo "${APP_URL}" | grep -qE '^https://'); then
|
|
|
|
|
# check lets encrypt email was set without a proxy
|
|
|
|
|
if [ -z "${LE_EMAIL}" ] && [ "${BEHIND_PROXY}" != "true" ]; then
|
|
|
|
|
echo "when app url is https a lets encrypt email must be set when not behind a proxy"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2025-12-14 15:02:06 -05:00
|
|
|
echo "https domain found setting email var"
|
2026-02-18 14:40:46 -05:00
|
|
|
export CADDY_LE_EMAIL="email ${LE_EMAIL}"
|
2025-12-14 15:02:06 -05:00
|
|
|
fi
|
|
|
|
|
|
2025-12-05 22:50:49 -05:00
|
|
|
# when running behind a proxy
|
2026-02-18 14:40:46 -05:00
|
|
|
if [ "${BEHIND_PROXY}" = "true" ]; then
|
2025-12-05 22:50:49 -05:00
|
|
|
echo "running behind proxy"
|
|
|
|
|
echo "listening on port 80 internally"
|
2026-02-18 14:40:46 -05:00
|
|
|
export CADDY_LE_EMAIL=""
|
|
|
|
|
export CADDY_APP_URL=":80"
|
|
|
|
|
export CADDY_AUTO_HTTPS="auto_https off"
|
|
|
|
|
export ASSET_URL="${APP_URL}"
|
2025-12-05 22:50:49 -05:00
|
|
|
fi
|
2024-09-27 17:36:45 -04:00
|
|
|
|
2025-12-14 15:02:06 -05:00
|
|
|
# disable caddy if SKIP_CADDY is set
|
2026-02-18 14:40:46 -05:00
|
|
|
if [ "${SKIP_CADDY:-}" = "true" ]; then
|
2024-11-04 12:43:40 +01:00
|
|
|
echo "Starting PHP-FPM only"
|
|
|
|
|
else
|
2024-06-27 15:59:07 -04:00
|
|
|
echo "Starting PHP-FPM and Caddy"
|
2025-08-10 14:30:58 -05:00
|
|
|
# enable caddy
|
2024-09-27 17:36:45 -04:00
|
|
|
export SUPERVISORD_CADDY=true
|
2025-08-10 14:30:58 -05:00
|
|
|
|
2025-12-14 15:02:06 -05:00
|
|
|
# handle trusted proxies for caddy when variable has data
|
2026-02-18 14:40:46 -05:00
|
|
|
if [ -n "${TRUSTED_PROXIES:-}" ]; then
|
|
|
|
|
FORMATTED_PROXIES=$(echo "trusted_proxies static ${TRUSTED_PROXIES}" | sed 's/,/ /g')
|
|
|
|
|
export CADDY_TRUSTED_PROXIES="${FORMATTED_PROXIES}"
|
2025-08-10 14:30:58 -05:00
|
|
|
export CADDY_STRICT_PROXIES="trusted_proxies_strict"
|
|
|
|
|
fi
|
2024-06-27 15:59:07 -04:00
|
|
|
fi
|
|
|
|
|
|
2024-09-27 17:36:45 -04:00
|
|
|
echo "Starting Supervisord"
|
2025-12-05 22:50:49 -05:00
|
|
|
exec "$@"
|