Spotter-VM/lxc-apps/kanboard/install.sh

46 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
set -ev
# Prepare variables
POSTGRES_DATA_DIR=${VOLUMES_DIR}/kanboard/postgres_data
KANBOARD_DATA_DIR=${VOLUMES_DIR}/kanboard/kanboard_data
KANBOARD_CONF_DIR=${VOLUMES_DIR}/kanboard/kanboard_conf
POSTGRES_NSUID=100070
POSTGRES_NSGID=100070
KANBOARD_NSUID=100102
KANBOARD_NSGID=100102
# Create Postgres instance
install -d -o ${POSTGRES_NSUID} -g ${POSTGRES_NSGID} -m 700 ${POSTGRES_DATA_DIR}
spoc-container exec kanboard-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf ${POSTGRES_DATA_DIR}/postgresql.conf
cp postgres_data/pg_hba.conf ${POSTGRES_DATA_DIR}/pg_hba.conf
# Configure Kanboard
export KANBOARD_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
mkdir -p ${KANBOARD_CONF_DIR} ${KANBOARD_DATA_DIR}
envsubst <kanboard_conf/config.php >${KANBOARD_CONF_DIR}/config.php
chown -R ${KANBOARD_NSUID}:${KANBOARD_NSGID} ${KANBOARD_CONF_DIR} ${KANBOARD_DATA_DIR}
# Populate database
spoc-container start kanboard-postgres
envsubst <createdb.sql | spoc-container exec kanboard-postgres -- psql
spoc-container exec kanboard -- cat /srv/kanboard/app/Schema/Sql/postgres.sql | spoc-container exec kanboard-postgres -- sh -c "PGPASSWORD=${KANBOARD_PWD} psql kanboard kanboard"
# Create admin account
export KANBOARD_ADMIN_USER=admin
export KANBOARD_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
export KANBOARD_ADMIN_HASH=$(python3 -c "import bcrypt; print(bcrypt.hashpw('${KANBOARD_ADMIN_PWD}'.encode(), bcrypt.gensalt()).decode().replace('2b', '2y'))")
envsubst <adminpwd.sql | spoc-container exec kanboard-postgres -- psql kanboard
# Install config update script
cp update-conf.sh ${VOLUMES_DIR}/kanboard/update-conf.sh
# Stop services required for setup
spoc-container stop kanboard-postgres
# Register application
vmmgr register-app kanboard kb "${KANBOARD_ADMIN_USER}" "${KANBOARD_ADMIN_PWD}"