From 25a40d213112305cc6c652f9e05caba7f554088c Mon Sep 17 00:00:00 2001 From: Zachary Klosko Date: Mon, 7 Dec 2020 15:35:31 -0500 Subject: [PATCH] Attempting database install fix --- .github/scripts/install.sh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/scripts/install.sh b/.github/scripts/install.sh index 35d4c95d0..b944b7eee 100644 --- a/.github/scripts/install.sh +++ b/.github/scripts/install.sh @@ -31,7 +31,22 @@ apt-get install -y gstreamer1.0-plugins-base \ postgresql-client # Creating database for testing -psql -c 'CREATE DATABASE libretime;' -U postgres -psql -c "CREATE USER libretime WITH PASSWORD 'libretime';" -U postgres -psql -c 'GRANT CONNECT ON DATABASE libretime TO libretime;' -U postgres -psql -c 'ALTER USER libretime CREATEDB;' -U postgres \ No newline at end of file + setupAirtimePostgresUser() { + # here-doc to execute this block as postgres user + su postgres <<'EOF' + set +e + count=$(psql -d postgres -tAc "SELECT count(*) FROM pg_roles WHERE rolname='airtime';") + if [[ $count -eq 0 ]]; then + psql -d postgres -tAc "CREATE USER airtime WITH ENCRYPTED PASSWORD 'airtime'; ALTER USER airtime CREATEDB; CREATE DATABASE libretime; GRANT CONNECT ON DATABASE libretime TO libretime;" + [[ $? -eq 0 ]] && + echo "Created airtime user in PostgreSQL" || + echo "$0:${FUNCNAME}(): ERROR: Can't create airtime user in PostgreSQL!" + else + echo "airtime user already exists in PostgreSQL" + fi + set -e +# don't indent this! +EOF + } + +setupAirtimePostgresUser \ No newline at end of file