postgres-init-dev-db: Fix shellcheck warnings.

In tools/setup/postgres-init-dev-db line 10:
ROOT_POSTGRES="sudo -i -u "$DEFAULT_USER" psql"
                           ^-- SC2027: The surrounding quotes actually unquote this. Remove or escape them.

In tools/setup/postgres-init-dev-db line 46:
    echo 'ERROR: Try `sudo service postgresql start`?'
         ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

In tools/setup/postgres-init-dev-db line 64:
PGPASS_ESCAPED_PREFIX="*:\*:\*:$USERNAME:"
                         ^-- SC1117: Backslash is literal in "\*". Prefer explicit escaping: "\\*".
                            ^-- SC1117: Backslash is literal in "\*". Prefer explicit escaping: "\\*".

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2018-08-03 00:14:50 +00:00 committed by Tim Abbott
parent 310027f970
commit b15063155c
1 changed files with 6 additions and 5 deletions

View File

@ -7,10 +7,10 @@ if [ "$(uname)" = "OpenBSD" ]; then
DEFAULT_USER="_postgresql"
fi
ROOT_POSTGRES="sudo -i -u "$DEFAULT_USER" psql"
ROOT_POSTGRES=(sudo -i -u "$DEFAULT_USER" psql)
DEFAULT_DB=""
if [ "$(uname)" = "Darwin" ]; then
ROOT_POSTGRES="psql"
ROOT_POSTGRES=(psql)
DEFAULT_DB="postgres"
fi
@ -43,12 +43,13 @@ if ! pg_isready -U "$DEFAULT_USER" -q; then
set +x
echo
echo 'ERROR: PostgreSQL Server is not running! Ensure the service is enabled.'
# shellcheck disable=SC2016
echo 'ERROR: Try `sudo service postgresql start`?'
echo "ERROR: You can easily test if you fixed it using: pg_isready -U \$DEFAULT_USER"
exit 1
fi
$ROOT_POSTGRES "$DEFAULT_DB" << EOF
"${ROOT_POSTGRES[@]}" "$DEFAULT_DB" << EOF
CREATE USER $USERNAME;
ALTER USER $USERNAME PASSWORD '$PASSWORD';
ALTER USER $USERNAME CREATEDB;
@ -61,7 +62,7 @@ EOF
umask go-rw
PGPASS_PREFIX="*:*:*:$USERNAME:"
PGPASS_ESCAPED_PREFIX="*:\*:\*:$USERNAME:"
PGPASS_ESCAPED_PREFIX="*:\\*:\\*:$USERNAME:"
if ! grep -q "$PGPASS_ESCAPED_PREFIX" ~/.pgpass; then
echo "$PGPASS_PREFIX$PASSWORD" >> ~/.pgpass
else
@ -81,7 +82,7 @@ psql -h localhost "$DBNAME_BASE" "$USERNAME" <<EOF
CREATE SCHEMA zulip;
EOF
$ROOT_POSTGRES "$DBNAME_BASE" << EOF
"${ROOT_POSTGRES[@]}" "$DBNAME_BASE" << EOF
CREATE EXTENSION tsearch_extras SCHEMA zulip;
CREATE EXTENSION pgroonga;
GRANT USAGE ON SCHEMA pgroonga TO $USERNAME;