37 lines
1.2 KiB
Bash
Executable File
37 lines
1.2 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
|
|
# TODO: this needs to be much mroe specific for production!
|
|
echo "host all any `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
|
|
|
|
# create the needed databases
|
|
/etc/init.d/postgresql start
|
|
#su -c 'psql --command "CREATE USER some_user;"' postgres
|
|
#su -c "psql --command \"CREATE DATABASE some_db WITH OWNER some_user 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 |