coreos-home-server/config/service/writefreely/container/run-writefreely
Alex Palaistras a6416f9ea6 Add service for WriteFreely
This commit integrates WriteFreely as a systemd service, set up as a
single-user instance by default (as is probably appropriate for a
home-server setup); a default administrator is set up, and whoever
is managing the home-server is expected to update the username and
password after first login.

Though WriteFreely expects to have a hostname set up for the instance,
we do not listen on any specific hostname by default. It is expected,
rather, that the `nginx-proxy-http` service is used with a drop-in for
using the correct `writefreely` upstream.

Configuration for this will continue to evolve as required.
2021-11-27 17:37:46 +00:00

32 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# Create configuration file from collected templates.
envsubst < /etc/writefreely/config.ini.template > /etc/writefreely/config.ini
mkdir -p /var/lib/writefreely/keys
# Initialize and run migrates on database if needed. New instances of WriteFreely will have a
# default administrator be created with a random password, which is echoed back to the system. It
# is intended that both the username and password are changed by whoever manages this instance.
if ! test -f /var/lib/writefreely/writefreely.db; then
writefreely -c /etc/writefreely/config.ini db init
(
password="$(dd if=/dev/urandom | tr -dc '[:alnum:]' | head -c 50)"
writefreely -c /etc/writefreely/config.ini user add --admin "default:${password}"
echo "Created an administrator user with username 'default' and password '${password}'"
echo "Make sure to change this immediately after logging in for the first time!"
)
fi
writefreely -c /etc/writefreely/config.ini db migrate
# Generate keys, if none have already been generated.
if test -z "$(ls -A /var/lib/writefreely/keys)"; then
writefreely -c /etc/writefreely/config.ini keys generate
fi
# Correct permissions for data files.
chown -R writefreely:writefreely /var/lib/writefreely
# Run entrypoint under specific user.
gosu writefreely /bin/writefreely -c /etc/writefreely/config.ini "$@"