quartz-docker/entrypoint.sh

80 lines
2.2 KiB
Bash
Raw Permalink Normal View History

2025-01-17 00:27:12 +00:00
#!/bin/bash
set -e
2025-01-18 01:42:12 +00:00
setup_user() {
if ! getent group quartzgroup >/dev/null 2>&1; then
addgroup -g "$GROUP_ID" quartzgroup
fi
if ! id -u quartz >/dev/null 2>&1; then
adduser -D -u "$USER_ID" -G quartzgroup quartz
fi
}
2025-01-17 00:27:12 +00:00
setup_cron() {
2025-01-18 01:42:12 +00:00
# NEW_JOB="${BUILD_SCHEDULE} (cd /quartz/content && git pull) >/dev/null && echo && (cd /quartz/src && npx quartz build) >/dev/null 2>&1"
NEW_JOB="${BUILD_SCHEDULE} (cd /quartz/content && git restore . && git pull) >/dev/null && (cd /quartz/src && npx quartz build) >/dev/null && echo 'Content Updated.'"
if [[ "$ENABLE_CRON" == "true" ]]; then
2025-01-18 01:42:12 +00:00
echo "Cron is enabled..."
echo "Setting up cron job..."
echo "$NEW_JOB" >/etc/crontabs/root
/usr/sbin/crond -f &
else
echo "Cron is disabled"
2025-01-17 00:27:12 +00:00
fi
}
2025-01-17 02:27:03 +00:00
2025-01-18 01:42:12 +00:00
verify_quartz() {
if [ ! -d "/quartz/src" ]; then
echo "Cloning Quartz..."
git clone https://github.com/jackyzha0/quartz.git /quartz/src
cd /quartz/src
rm -rf /quartz/src/content
ln -s /quartz/content /quartz/src
git config --global --add safe.directory /quartz/src
echo "Installing Quartz dependencies..."
npm install >/dev/null
echo "Building Quartz..."
npx quartz build >/dev/null
fi
}
download_content() {
mkdir -p /quartz/content # Ensure directory exists
if [ -n "${CONTENT_REPO}" ] && [ -z "$(ls -A /quartz/content 2>/dev/null)" ]; then
echo "Downloading content..."
git clone "${CONTENT_REPO}" /quartz/content
fi
git config --global --add safe.directory /quartz/content
}
main() {
2025-01-18 01:42:12 +00:00
echo "Setting up Quartz environment..."
setup_user
setup_cron
2025-01-18 01:42:12 +00:00
verify_quartz
download_content
2025-01-17 00:27:12 +00:00
2025-01-18 01:42:12 +00:00
rm -rf /quartz/src/content
ln -s /quartz/content /quartz/src
2025-01-17 02:27:03 +00:00
2025-01-18 01:42:12 +00:00
echo "Setting correct permissions..."
chown -R "${USER_ID}":"${GROUP_ID}" /quartz
chmod -R 755 /quartz
2025-01-17 00:27:12 +00:00
2025-01-18 01:42:12 +00:00
echo "NGINX variable substitution..."
/docker-entrypoint.d/20-envsubst-on-templates.sh >/dev/null
2025-01-17 02:27:03 +00:00
echo "Building Quartz..."
2025-01-18 01:42:12 +00:00
su quartz -c "bash -c 'cd /quartz/src && npx quartz build >/dev/null'"
2025-01-17 00:27:12 +00:00
echo "Starting Nginx..."
2025-01-18 01:42:12 +00:00
exec nginx -g "daemon off; error_log warn;"
}
2025-01-17 00:27:12 +00:00
main