#!/bin/sh set -e PHP_FPM_CONF="/etc/php${PHP_VERSION}/php-fpm.conf" # Inject dynamic PHP-FPM config if not already there if [ ! -f "$PHP_FPM_CONF" ]; then mkdir -p "/etc/php${PHP_VERSION}" cp /etc/php-fpm.conf.template "$PHP_FPM_CONF" fi # Check for Grav instalation if [ ! -f "$GRAV_ROOT/index.php" ]; then echo "Grav not found. Installing..." mkdir -p "$GRAV_ROOT" curl -Lso /tmp/grav.zip https://github.com/getgrav/grav/releases/download/${GRAV_VERSION}/grav-admin-v${GRAV_VERSION}.zip # Check if it's a valid zip if unzip -t /tmp/grav.zip > /dev/null 2>&1; then unzip -oq /tmp/grav.zip -d /tmp # Get the name of the extracted directory (grav-admin or grav) EXTRACTED_DIR=$(unzip -Z -1 /tmp/grav.zip | head -n 1 | cut -d/ -f1) if [ -d "/tmp/$EXTRACTED_DIR" ]; then mv "/tmp/$EXTRACTED_DIR"/* "$GRAV_ROOT" chown -R rocky:tty "$GRAV_ROOT" else echo "❌ Could not find extracted Grav folder." exit 1 fi else echo "❌ Invalid ZIP file downloaded from $GRAV_ZIP_URL" cat /tmp/grav.zip exit 1 fi else echo "Grav already installed." fi chown -R rocky:rocky "$GRAV_ROOT" chown -R rocky:rocky /var/lib/nginx/html # PERMISSIONS find /var/www/html -type f | xargs chmod 664 find /var/www/html -type d | xargs chmod 775 find /var/www/html -type d | xargs chmod +s # Start services php-fpm${PHP_VERSION} -D # start nginx mkdir -p /tmp/nginx/ chown -R rocky:rocky /tmp/nginx nginx -g "daemon off;"