Files
wol/build/entrypoint.sh

40 lines
965 B
Bash
Executable File

#!/bin/bash
set -eu
template='/usr/local/share/rwsols-config.php'
file='/var/www/html/config.php'
cp "$template" "$file"
search_and_replace() {
local search="$1"
local replace="$2"
local escaped
escaped=$(printf '%s' "$replace" | sed -e 's/[&|\\]/\\&/g')
sed -i "s|$search|$escaped|g" "$file"
}
for v in $(compgen -A variable RWSOLS_); do
if grep -q "REPLACE_$v" "$file"; then
echo "search_and_replace REPLACE_$v with ${!v}"
search_and_replace "REPLACE_$v" "${!v}"
fi
done
RWSOLS_HASH=$(php -r '$p = getenv("PASSPHRASE"); echo password_hash($p === false ? "" : $p, PASSWORD_DEFAULT);')
search_and_replace "REPLACE_APPROVED_HASH" "$RWSOLS_HASH"
case "${APACHE2_PORT:-}" in
''|*[!0-9]*)
echo "APACHE2_PORT must be a numeric port" >&2
exit 1
;;
esac
echo "Starting Apache2 on port $APACHE2_PORT"
sed -i "s|8080|$APACHE2_PORT|g" /etc/apache2/ports.conf /etc/apache2/sites-available/000-default.conf
exec apache2-foreground