diff --git a/start b/start index 65e3fac..ef273e3 100755 --- a/start +++ b/start @@ -14,7 +14,7 @@ DB_UNACCENT=${DB_UNACCENT:false} # by default postgresql will start up as a standalone instance. # set this environment variable to master, slave or snapshot to use replication features. # "snapshot" will create a point in time backup of a master instance. -PSQL_MODE=${PSQL_MODE:-"standalone"} +PSQL_MODE=${PSQL_MODE:-standalone} REPLICATION_USER=${REPLICATION_USER:-} REPLICATION_PASS=${REPLICATION_PASS:-} @@ -22,7 +22,7 @@ REPLICATION_HOST=${REPLICATION_HOST:-} REPLICATION_PORT=${REPLICATION_PORT:-5432} # set this env variable to "require" to enable encryption and "verify-full" for verification. -PSQL_SSLMODE=${PSQL_SSLMODE:-"disable"} +PSQL_SSLMODE=${PSQL_SSLMODE:-disable} ## Adapt uid and gid for ${PG_USER}:${PG_USER} USERMAP_ORIG_UID=$(id -u ${PG_USER}) @@ -47,7 +47,7 @@ mkdir -p -m 0755 /run/postgresql /run/postgresql/${PG_VERSION}-main.pg_stat_tmp chown -R ${PG_USER}:${PG_USER} /run/postgresql chmod g+s /run/postgresql -if [ "${PSQL_SSLMODE}" == "disable" ]; then +if [[ ${PSQL_SSLMODE} == disable ]]; then sed 's/ssl = true/#ssl = true/' -i ${PG_CONFDIR}/postgresql.conf fi @@ -56,7 +56,7 @@ cat >> ${PG_CONFDIR}/postgresql.conf <> ${PG_CONFDIR}/pg_hba.conf <> ${PG_CONFDIR}/pg_hba.conf <> ${PG_CONFDIR}/postgresql.conf <> ${PG_CONFDIR}/postgresql.conf </dev/null | sort -r | head -n1 | cut -d'/' -f5) echo "Initializing database..." - sudo -Hu ${PG_USER} "${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 - -if [ -n "${PG_OLD_VERSION}" ]; then +if [[ -n ${PG_OLD_VERSION} ]]; then echo "Migrating postgresql ${PG_OLD_VERSION} data..." PG_OLD_CONFDIR="/etc/postgresql/${PG_OLD_VERSION}/main" PG_OLD_BINDIR="/usr/lib/postgresql/${PG_OLD_VERSION}/bin" @@ -156,11 +155,10 @@ if [ -n "${PG_OLD_VERSION}" ]; then -O "-c config_file=${PG_CONFDIR}/postgresql.conf" >/dev/null fi - # Hot standby (slave and snapshot) servers can ignore the following code. -if [ "${PSQL_MODE}" == "standalone" ] || [ "${PSQL_MODE}" == "master" ]; then - if [ -n "${REPLICATION_USER}" ]; then - if [ -z "${REPLICATION_PASS}" ]; then +if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then + if [[ -n ${REPLICATION_USER} ]]; then + if [[ -z ${REPLICATION_PASS} ]]; then echo "" echo "WARNING: " echo " Please specify a password for replication user \"${REPLICATION_USER}\". Skipping user creation..." @@ -174,8 +172,8 @@ if [ "${PSQL_MODE}" == "standalone" ] || [ "${PSQL_MODE}" == "master" ]; then fi fi - if [ -n "${DB_USER}" ]; then - if [ -z "${DB_PASS}" ]; then + if [[ -n ${DB_USER} ]]; then + if [[ -z ${DB_PASS} ]]; then echo "" echo "WARNING: " echo " Please specify a password for \"${DB_USER}\". Skipping user creation..." @@ -189,21 +187,21 @@ if [ "${PSQL_MODE}" == "standalone" ] || [ "${PSQL_MODE}" == "master" ]; then fi fi - if [ -n "${DB_NAME}" ]; then + if [[ -n ${DB_NAME} ]]; 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 -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \ -D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null - if [ "${DB_UNACCENT}" == "true" ]; then + if [[ ${DB_UNACCENT} == true ]]; then echo "Installing unaccent extension..." echo "CREATE EXTENSION IF NOT EXISTS unaccent;" | \ 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 + 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 -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \