From dd71ed32b92f2a9995945a8b3cb7b64b8dd0370b Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Tue, 2 Jan 2024 02:54:27 +1300 Subject: [PATCH] Don't use sudo for createdb (#237) We should have a working database user, so we shouldn't need sudo (and sudo wouldn't help if the database is remote). Aside: The syntax `cmd=(...)` creates a bash array, it is required to properly handle empty strings and avoid other quoting issues. --- script/install/postgresql.bash | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/script/install/postgresql.bash b/script/install/postgresql.bash index 1256956a..27f65195 100644 --- a/script/install/postgresql.bash +++ b/script/install/postgresql.bash @@ -41,9 +41,9 @@ fi if [[ $DATABASE ]] ; then psql -U "$DATABASE_USERNAME" "$DATABASE" -c '' &> /dev/null || { bash script/confirm.bash "Create new PostgreSQL database $DATABASE" && { - cmd="sudo -u postgres createdb $DATABASE" - echo "$ $cmd" - $cmd + cmd=(createdb -U "$DATABASE_USERNAME" "$DATABASE") + echo "$ ${cmd[@]}" + "${cmd[@]}" } || exit 1 } fi @@ -52,10 +52,10 @@ fi if [[ $TEST_DATABASE ]] ; then psql -U "$DATABASE_USERNAME" "$TEST_DATABASE" -c '' &> /dev/null || { bash script/confirm.bash "Create new PostgreSQL database $TEST_DATABASE" && { - cmd="sudo -u postgres createdb $TEST_DATABASE" - echo "$ $cmd" - $cmd - } || exit + cmd=(createdb -U "$DATABASE_USERNAME" "$TEST_DATABASE") + echo "$ ${cmd[@]}" + "${cmd[@]}" + } || exit 1 } fi