#!/bin/bash

# enable strict mode
set -euo pipefail
IFS=$'\n\t'

SHARED_MOUNT_DIRECTORIES=('public/tmp')
# APP_HOME is provided by the Dockerfile

# Add temporary directories used for artwork and potentially other uploads.
for DIR in "${SHARED_MOUNT_DIRECTORIES[@]}"; do
  if [ ! -d "${APP_HOME}/${DIR}" ]; then
    mkdir -p "${APP_HOME}/${DIR}"
    chown www-data "${APP_HOME}/${DIR}"
  fi
done

# Make sure coverart directories are writable
find "${APP_HOME}/public/images" -type d -name "*coverart*" -exec chown www-data {} \;

/usr/sbin/apache2ctl -k start -D FOREGROUND
