Makes the path of the config file configurable via CONFIG environment variable

This commit is contained in:
EnigmaCurry 2021-12-15 18:47:46 -08:00
parent 7e06eadfd0
commit 7b450ad78c

View file

@ -1,18 +1,20 @@
#!/bin/sh #!/bin/sh
CONFIG=${CONFIG:-/data/config.yaml}
function fixperms { function fixperms {
chown -R $UID:$GID /var/log /data /opt/maubot chown -R $UID:$GID /var/log /data /opt/maubot
} }
function fixconfig { function fixconfig {
# If the DB path is the default relative path, replace it with an absolute /data path # If the DB path is the default relative path, replace it with an absolute /data path
_db_url=$(yq e '.database' /data/config.yaml) _db_url=$(yq e '.database' ${CONFIG})
if [[ _db_url == "sqlite:///maubot.db" ]]; then if [[ _db_url == "sqlite:///maubot.db" ]]; then
yq e -i '.database = "sqlite:////data/maubot.db"' /data/config.yaml yq e -i '.database = "sqlite:////data/maubot.db"' ${CONFIG}
fi fi
_log_path=$(yq e '.logging.handlers.file.filename' /data/config.yaml) _log_path=$(yq e '.logging.handlers.file.filename' ${CONFIG})
if [[ _log_path == "./maubot.log" ]]; then if [[ _log_path == "./maubot.log" ]]; then
yq e -i '.logging.handlers.file.filename = "/var/log/maubot.log"' /data/config.yaml yq e -i '.logging.handlers.file.filename = "/var/log/maubot.log"' ${CONFIG}
fi fi
# Set the correct resource paths # Set the correct resource paths
yq e -i ' yq e -i '
@ -21,26 +23,26 @@ function fixconfig {
.plugin_directories.load = ["/data/plugins"] | .plugin_directories.load = ["/data/plugins"] |
.plugin_directories.trash = "/data/trash" | .plugin_directories.trash = "/data/trash" |
.plugin_directories.db = "/data/dbs" .plugin_directories.db = "/data/dbs"
' /data/config.yaml ' ${CONFIG}
} }
cd /opt/maubot cd /opt/maubot
mkdir -p /var/log/maubot /data/plugins /data/trash /data/dbs mkdir -p /var/log/maubot /data/plugins /data/trash /data/dbs
if [ ! -f /data/config.yaml ]; then if [ ! -f ${CONFIG} ]; then
cp example-config.yaml /data/config.yaml cp example-config.yaml ${CONFIG}
# Apply some docker-specific adjustments to the config # Apply some docker-specific adjustments to the config
echo "Config file not found. Example config copied to /data/config.yaml" echo "Config file not found. Example config copied to ${CONFIG}"
echo "Please modify the config file to your liking and restart the container." echo "Please modify the config file to your liking and restart the container."
fixperms fixperms
fixconfig fixconfig
exit exit
fi fi
alembic -x config=/data/config.yaml upgrade head alembic -x config=${CONFIG} upgrade head
fixperms fixperms
fixconfig fixconfig
mv -n /data/plugins/*.db /data/dbs/ mv -n /data/plugins/*.db /data/dbs/
exec su-exec $UID:$GID python3 -m maubot -c /data/config.yaml exec su-exec $UID:$GID python3 -m maubot -c ${CONFIG}