start: combine sudo arguments

This commit is contained in:
Sameer Naik
2015-07-12 23:11:14 +05:30
parent 87857b903f
commit 8d4025257f
+10 -10
View File
@@ -106,19 +106,19 @@ if [ ! -d ${PG_DATADIR} ]; then
if [ "${PSQL_MODE}" == "slave" ] || [ "${PSQL_MODE}" == "snapshot" ]; then
echo "Replicating database..."
if [ "${PSQL_MODE}" == "snapshot" ]; then
sudo -u ${PG_USER} -H \
sudo -Hu ${PG_USER} \
PGPASSWORD=$REPLICATION_PASS "${PG_BINDIR}/pg_basebackup" -D "${PG_DATADIR}" \
-h "${REPLICATION_HOST}" -p "${REPLICATION_PORT}" -U "${REPLICATION_USER}" -w -x -v -P
elif [ "${PSQL_MODE}" == "slave" ]; then
# Setup streaming replication.
sudo -u ${PG_USER} -H \
sudo -Hu ${PG_USER} \
PGPASSWORD=$REPLICATION_PASS "${PG_BINDIR}/pg_basebackup" -D "${PG_DATADIR}" \
-h "${REPLICATION_HOST}" -p "${REPLICATION_PORT}" -U "${REPLICATION_USER}" -w -v -P
echo "Setting up hot standby configuration..."
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF
hot_standby = on
EOF
sudo -u ${PG_USER} touch ${PG_DATADIR}/recovery.conf
sudo -Hu ${PG_USER} touch ${PG_DATADIR}/recovery.conf
cat >> ${PG_DATADIR}/recovery.conf <<EOF
standby_mode = 'on'
primary_conninfo = 'host=${REPLICATION_HOST} port=${REPLICATION_PORT} user=${REPLICATION_USER} password=${REPLICATION_PASS} sslmode=${PSQL_SSLMODE}'
@@ -131,7 +131,7 @@ EOF
PG_OLD_VERSION=$(find ${PG_HOME}/[0-9].[0-9]/main -maxdepth 1 -name PG_VERSION 2>/dev/null | sort -r | head -n1 | cut -d'/' -f5)
echo "Initializing database..."
sudo -u ${PG_USER} -H "${PG_BINDIR}/initdb" --pgdata="${PG_DATADIR}" \
sudo -Hu ${PG_USER} "${PG_BINDIR}/initdb" --pgdata="${PG_DATADIR}" \
--username=${PG_USER} --encoding=unicode --auth=trust >/dev/null
fi
fi
@@ -155,7 +155,7 @@ if [ -n "${PG_OLD_VERSION}" ]; then
# migrate ${PG_OLD_VERSION} data
echo "Migration in progress. This could take a while, please be patient..."
sudo -u ${PG_USER} -H ${PG_BINDIR}/pg_upgrade \
sudo -Hu ${PG_USER} ${PG_BINDIR}/pg_upgrade \
-b ${PG_OLD_BINDIR} -B ${PG_BINDIR} \
-d ${PG_OLD_DATADIR} -D ${PG_DATADIR} \
-o "-c config_file=${PG_OLD_CONFDIR}/postgresql.conf" \
@@ -175,7 +175,7 @@ if [ "${PSQL_MODE}" == "standalone" ] || [ "${PSQL_MODE}" == "master" ]; then
else
echo "Creating user \"${REPLICATION_USER}\"..."
echo "CREATE ROLE ${REPLICATION_USER} WITH REPLICATION LOGIN ENCRYPTED PASSWORD '${REPLICATION_PASS}';" |
sudo -u ${PG_USER} -H ${PG_BINDIR}/postgres --single \
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
fi
fi
@@ -190,7 +190,7 @@ if [ "${PSQL_MODE}" == "standalone" ] || [ "${PSQL_MODE}" == "master" ]; then
else
echo "Creating user \"${DB_USER}\"..."
echo "CREATE ROLE ${DB_USER} with LOGIN CREATEDB PASSWORD '${DB_PASS}';" |
sudo -u ${PG_USER} -H ${PG_BINDIR}/postgres --single \
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
fi
fi
@@ -199,20 +199,20 @@ if [ "${PSQL_MODE}" == "standalone" ] || [ "${PSQL_MODE}" == "master" ]; then
for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
echo "Creating database \"${db}\"..."
echo "CREATE DATABASE ${db};" | \
sudo -u ${PG_USER} -H ${PG_BINDIR}/postgres --single \
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
if [ "${DB_UNACCENT}" == "true" ]; then
echo "Installing unaccent extension..."
echo "CREATE EXTENSION IF NOT EXISTS unaccent;" | \
sudo -u ${PG_USER} -H ${PG_BINDIR}/postgres --single ${db} \
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single ${db} \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
fi
if [ -n "${DB_USER}" ]; then
echo "Granting access to database \"${db}\" for user \"${DB_USER}\"..."
echo "GRANT ALL PRIVILEGES ON DATABASE ${db} to ${DB_USER};" |
sudo -u ${PG_USER} -H ${PG_BINDIR}/postgres --single \
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
fi
done