quasseldocker/postgres/start.sh

36 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# removing the database cluster if it exists and prepping everything for posgresql operation
# be careful, Will Robinson!
# we need to be root for this
if [[ `whoami` != 'root' ]]; then
echo "we need to be root for this, quitting"
exit 1
fi
# work the directory
cd /var/lib/postgresql
chown -R postgres:postgres ./
chmod -R 0700 ./
# do we need to init the db?
if [ ! -e /var/lib/postgresql/9.3/main ]; then
# initdb as postgres
su -c '/usr/lib/postgresql/9.3/bin/initdb /var/lib/postgresql/9.3/main' postgres
# config
echo "host all all `hostname -I | sed 's/ //g'`/16 trust" >> /var/lib/postgresql/9.3/main/pg_hba.conf
echo "listen_addresses='*'" >> /var/lib/postgresql/9.3/main/postgresql.conf
# let quassel db
/etc/init.d/postgresql start
su -c 'psql --command "CREATE USER quassel;"' postgres
su -c "psql --command \"CREATE DATABASE quassel WITH OWNER quassel TEMPLATE template0 ENCODING 'UTF8';\"" postgres
/etc/init.d/postgresql stop
fi
# run postgres as user postgres
su -c '/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main' postgres