Skip to content

Commit

Permalink
Don't use sudo for createdb (#237)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tom93 committed Jan 2, 2024
1 parent 0c9b238 commit dd71ed3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions script/install/postgresql.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit dd71ed3

Please sign in to comment.