#!/usr/bin/env bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # casjaysdevdocker/ampache - 05-custom.sh # 1. Wipe distro defaults under /etc/{apache2,php84,my.cnf.d}/* and # drop in our optimized configs from /tmp/etc/. # 2. Fetch the upstream Ampache prebuilt zip and unpack it under # /usr/local/share/ampache. # 3. Stage runtime dirs that the init.d scripts will need. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - set -e -o pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS exitCode=0 AMPACHE_VERSION="${AMPACHE_VERSION:-7.9.3}" AMPACHE_PHP_TAG="${AMPACHE_PHP_TAG:-php8.4}" AMPACHE_URL="https://github.com/ampache/ampache/releases/download/${AMPACHE_VERSION}/ampache-${AMPACHE_VERSION}_all_${AMPACHE_PHP_TAG}.zip" AMPACHE_INSTALL_DIR="/usr/local/share/ampache" echo "Wiping distro defaults and installing optimized configs" for svc in apache2 php84 my.cnf.d; do src="/tmp/etc/$svc" dst="/etc/$svc" [ -d "$src" ] || continue # Preserve mime.types + magic from the apache2 package; we don't ship our own. if [ "$svc" = "apache2" ]; then [ -f "$dst/mime.types" ] && cp -f "$dst/mime.types" "/tmp/${svc}_mime.types.preserve" || true [ -f "$dst/magic" ] && cp -f "$dst/magic" "/tmp/${svc}_magic.preserve" || true fi rm -Rf "$dst"/* mkdir -p "$dst" cp -Rf "$src/." "$dst/" if [ "$svc" = "apache2" ]; then [ -f "/tmp/${svc}_mime.types.preserve" ] && mv -f "/tmp/${svc}_mime.types.preserve" "$dst/mime.types" [ -f "/tmp/${svc}_magic.preserve" ] && mv -f "/tmp/${svc}_magic.preserve" "$dst/magic" fi # Drop a copy under template-files/config/ so /config/$svc gets seeded on first run. mkdir -p "/usr/local/share/template-files/config/$svc" cp -Rf "$dst/." "/usr/local/share/template-files/config/$svc/" done echo "Fetching Ampache ${AMPACHE_VERSION} (${AMPACHE_PHP_TAG})" mkdir -p "$AMPACHE_INSTALL_DIR" cd /tmp if ! wget -q -O /tmp/ampache.zip "$AMPACHE_URL"; then echo "Failed to download $AMPACHE_URL" >&2 exit 10 fi unzip -q -o /tmp/ampache.zip -d "$AMPACHE_INSTALL_DIR" rm -f /tmp/ampache.zip # Some upstream zips unpack into a versioned subdir; flatten if needed. if [ -d "$AMPACHE_INSTALL_DIR/ampache-${AMPACHE_VERSION}" ]; then shopt -s dotglob mv "$AMPACHE_INSTALL_DIR/ampache-${AMPACHE_VERSION}"/* "$AMPACHE_INSTALL_DIR/" rmdir "$AMPACHE_INSTALL_DIR/ampache-${AMPACHE_VERSION}" shopt -u dotglob fi if [ ! -f "$AMPACHE_INSTALL_DIR/public/index.php" ]; then echo "Ampache install layout unexpected: $AMPACHE_INSTALL_DIR/public/index.php missing" >&2 ls -la "$AMPACHE_INSTALL_DIR" | head -20 >&2 exit 11 fi mkdir -p "$AMPACHE_INSTALL_DIR/config" echo "Creating runtime dirs" mkdir -p /run/apache2 /run/php-fpm /run/mysqld /tmp/php-sessions \ /var/log/apache2 \ /usr/local/share/template-files/config/ampache # Seed for /config/ampache cat <<'EOF' >/usr/local/share/template-files/config/ampache/.gitkeep # Placeholder. Real ampache.cfg.php is generated by install.php on first # web visit, then mirrored to this directory by 99-ampache.sh post_execute. EOF # Make sure the apache user owns the app tree (composer artifacts ship as # www-data:www-data by default, but apache uid/gid differ on Alpine). if id apache >/dev/null 2>&1; then chown -Rf apache:apache "$AMPACHE_INSTALL_DIR" 2>/dev/null || true fi exit $exitCode