#! /bin/sh
## Writefreely wrapper for Docker
## Copyright (C) 2019 Gergely Nagy
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see .
set -e
cd /data
WRITEFREELY=/writefreely/writefreely
if [ -e ./config.ini ] && [ -e ./writefreely.db ] && [ -e ./keys/email.aes256 ]; then
BACKUP="writefreely.$(date +%s).db"
cp writefreely.db ${BACKUP}
${WRITEFREELY} -migrate
if cmp writefreely.db ${BACKUP}; then
rm ${BACKUP}
else
echo "Database backed up at /data/${BACKUP}"
fi
exec ${WRITEFREELY}
fi
if [ -e ./config.ini ]; then
if [ ! -s ./writefreely.db ]; then
${WRITEFREELY} -init-db
fi
if [ ! -e ./keys/email.aes256 ]; then
${WRITEFREELY} -gen-keys
fi
BACKUP="writefreely.$(date +%s).db"
cp writefreely.db ${BACKUP}
${WRITEFREELY} -migrate
if cmp writefreely.db ${BACKUP}; then
rm ${BACKUP}
else
echo "Database backed up at /data/${BACKUP}"
fi
exec ${WRITEFREELY}
fi
WRITEFREELY_BIND_PORT="${WRITEFREELY_BIND_PORT:-8080}"
WRITEFREELY_BIND_HOST="${WRITEFREELY_BIND_HOST:-0.0.0.0}"
WRITEFREELY_SITE_NAME="${WRITEFREELY_SITE_NAME:-A Writefreely blog}"
cat >./config.ini <