Skip to content

Commit cbf58ca

Browse files
author
Sameer Naik
committed
defined macros for path variables
1 parent e9fb3c4 commit cbf58ca

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

start

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
#!/bin/bash
22
set -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
510
chown -R postgres:postgres /var/lib/postgresql
611
chmod 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
1318
listen_addresses = '*'
1419
EOF
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
1823
host all all 0.0.0.0/0 md5
1924
EOF
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
2934
fi
3035

@@ -40,6 +45,5 @@ if [ -f /var/lib/postgresql/pwfile ]; then
4045
fi
4146

4247
echo "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

Comments
 (0)