1.1 --- a/tools/config.sh Sun Apr 03 22:39:53 2016 +0200
1.2 +++ b/tools/config.sh Sun Apr 03 22:41:28 2016 +0200
1.3 @@ -9,7 +9,8 @@
1.4
1.5 # Store-specific settings.
1.6
1.7 -# For STORE_TYPE=postgresql:
1.8 +# For STORE_TYPE=postgresql...
1.9
1.10 POSTGRESQL_DB=imip_agent
1.11 POSTGRESQL_USERS="imip-agent www-data"
1.12 +AS_POSTGRES="sudo -u postgres"
2.1 --- a/tools/init.sh Sun Apr 03 22:39:53 2016 +0200
2.2 +++ b/tools/init.sh Sun Apr 03 22:41:28 2016 +0200
2.3 @@ -92,7 +92,7 @@
2.4
2.5 # Check for the database.
2.6
2.7 - if psql -tA -c 'select datname from pg_database' postgres | grep -q ^"$POSTGRESQL_DB"$ ; then
2.8 + if $AS_POSTGRES psql -tA -c 'select datname from pg_database' postgres | grep -q ^"$POSTGRESQL_DB"$ ; then
2.9 cat 1>&2 <<EOF
2.10 Database $POSTGRESQL_DB already exists.
2.11 EOF
2.12 @@ -101,7 +101,7 @@
2.13
2.14 # Attempt to create the database.
2.15
2.16 - if ! createdb "$POSTGRESQL_DB" ; then
2.17 + if ! $AS_POSTGRES createdb "$POSTGRESQL_DB" ; then
2.18 cat 1>&2 <<EOF
2.19 Could not create database $POSTGRESQL_DB using createdb.
2.20 EOF
2.21 @@ -110,7 +110,7 @@
2.22
2.23 # Attempt to initialise the schema.
2.24
2.25 - if ! psql -f "$SCHEMA" "$POSTGRESQL_DB" ; then
2.26 + if ! $AS_POSTGRES psql -f "$SCHEMA" "$POSTGRESQL_DB" ; then
2.27 cat 1>&2 <<EOF
2.28 Could not initialise schema in database $POSTGRESQL_DB using psql.
2.29 EOF
2.30 @@ -121,12 +121,12 @@
2.31 # privileges on the tables.
2.32
2.33 for USER in $POSTGRESQL_USERS ; do
2.34 - if ! createuser -D -R -S "$USER" ; then
2.35 + if ! $AS_POSTGRES createuser -D -R -S "$USER" ; then
2.36 cat 1>&2 <<EOF
2.37 Could not create database user $USER using createuser.
2.38 EOF
2.39 fi
2.40 - if ! psql -Atc '\dt' "$POSTGRESQL_DB" \
2.41 + if ! $AS_POSTGRES psql -Atc '\dt' "$POSTGRESQL_DB" \
2.42 | cut -d '|' -f 2 \
2.43 | xargs -I{} psql -c "grant all privileges on table {} to \"$USER\"" "$POSTGRESQL_DB" ; then
2.44