Spotter-VM/kanboard/setup.sh

36 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
# Check prerequisites
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
# Populate database
export KANBOARD_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
cat /var/lib/lxc/kanboard/kanboard/srv/kanboard/app/Schema/Sql/postgres.sql | lxc-attach -u 5432 -g 5432 postgres -- sh -c "PGPASSWORD=${KANBOARD_PWD} psql kanboard kanboard"
# Configure Kanboard
mkdir -p /srv/kanboard/conf /srv/kanboard/data
chown -R 8009:8009 /srv/kanboard/data
envsubst <${SOURCE_DIR}/srv/kanboard/conf/config.php >/srv/kanboard/conf/config.php
export KANBOARD_ADMIN_USER=admin
export KANBOARD_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
export KANBOARD_ADMIN_HASH=$(python3 -c "import bcrypt; print(bcrypt.hashpw('${KANBOARD_ADMIN_PWD}'.encode(), bcrypt.gensalt()).decode().replace('2b', '2y'))")
envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql kanboard
vmmgr update-login kanboard "${KANBOARD_ADMIN_USER}" "${KANBOARD_ADMIN_PWD}"
# Install cron job
cp ${SOURCE_DIR}/etc/periodic/daily/kanboard /etc/periodic/daily/kanboard
# Install service
cp ${SOURCE_DIR}/etc/init.d/kanboard /etc/init.d/kanboard
rc-update -u
# Install config update script
cp ${SOURCE_DIR}/srv/kanboard/update-conf.sh /srv/kanboard/update-conf.sh
# Stop services required for build
[ ! -z ${STOP_POSTGRES} ] && service postgres stop