11#! /bin/bash
22set -e
33
4+ PG_VERSION=" 9.1"
5+ PG_CONFDIR=" /etc/postgresql/${PG_VERSION} /main"
6+ PG_BINDIR=" /usr/lib/postgresql/${PG_VERSION} /bin"
7+ PG_DATADIR=" /var/lib/postgresql/${PG_VERSION} /main"
8+
49# fix permissions and ownership of /var/lib/postgresql
510chown -R postgres:postgres /var/lib/postgresql
611chmod 700 /var/lib/postgresql
712
813# disable ssl
9- sed ' s/ssl = true/#ssl = true/' -i /etc/postgresql/9.1/main /postgresql.conf
14+ sed ' s/ssl = true/#ssl = true/' -i ${PG_CONFDIR} /postgresql.conf
1015
1116# listen on all interfaces
12- cat >> /etc/postgresql/9.1/main /postgresql.conf << EOF
17+ cat >> ${PG_CONFDIR} /postgresql.conf << EOF
1318listen_addresses = '*'
1419EOF
1520
1621# allow remote connections to postgresql database
17- cat >> /etc/postgresql/9.1/main /pg_hba.conf << EOF
22+ cat >> ${PG_CONFDIR} /pg_hba.conf << EOF
1823host all all 0.0.0.0/0 md5
1924EOF
2025
2126# initialize PostgreSQL data directory
22- if [ ! -d /var/lib/postgresql/9.1/main ]; then
27+ if [ ! -d ${PG_DATADIR} ]; then
2328 echo " Initializing database..."
2429 PG_PASSWORD=$( pwgen -c -n -1 14)
2530 echo " ${PG_PASSWORD} " > /var/lib/postgresql/pwfile
26- sudo -u postgres -H /usr/lib/postgresql/9.1/bin/ initdb \
27- --pgdata=/var/lib/postgresql/9.1/main --pwfile=/var/lib/postgresql/pwfile \
31+ sudo -u postgres -H " ${PG_BINDIR} / initdb" \
32+ --pgdata=" ${PG_DATADIR} " --pwfile=/var/lib/postgresql/pwfile \
2833 --username=postgres --encoding=unicode --auth=trust > /dev/null
2934fi
3035
@@ -40,6 +45,5 @@ if [ -f /var/lib/postgresql/pwfile ]; then
4045fi
4146
4247echo " Starting PostgreSQL server..."
43- exec sudo -u postgres -H /usr/lib/postgresql/9.1/bin/postgres \
44- -D /var/lib/postgresql/9.1/main \
45- -c config_file=/etc/postgresql/9.1/main/postgresql.conf
48+ exec sudo -u postgres -H ${PG_BINDIR} /postgres \
49+ -D ${PG_DATADIR} -c config_file=${PG_CONFDIR} /postgresql.conf
0 commit comments