From 3b8638cd15e2604de7a4a0a98baac68138d45c7a Mon Sep 17 00:00:00 2001 From: jo Date: Thu, 8 Dec 2022 16:03:36 +0100 Subject: [PATCH] fix(installer): set home and login when running as postgres Remove warnings if the current dir is not writable by postgres --- install | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/install b/install index 0baf1d83b..a13246117 100755 --- a/install +++ b/install @@ -434,11 +434,11 @@ if $LIBRETIME_SETUP_POSTGRESQL; then if $is_first_install; then # TODO: Swap lines when Bionic support is dropped - # if ! sudo -u postgres psql --csv --tuples-only --command='\du' | grep -qw "^$LIBRETIME_POSTGRESQL_USER"; then - if ! sudo -u postgres psql --tuples-only --command='\du' | grep -qw "$LIBRETIME_POSTGRESQL_USER"; then + # if ! sudo -iH -u postgres psql --csv --tuples-only --command='\du' | grep -qw "^$LIBRETIME_POSTGRESQL_USER"; then + if ! sudo -iH -u postgres psql --tuples-only --command='\du' | grep -qw "$LIBRETIME_POSTGRESQL_USER"; then info "creating PostgreSQL user '$LIBRETIME_POSTGRESQL_USER'" - sudo -u postgres createuser "$LIBRETIME_POSTGRESQL_USER" - sudo -u postgres psql -c "ALTER ROLE $LIBRETIME_POSTGRESQL_USER WITH PASSWORD '$LIBRETIME_POSTGRESQL_PASSWORD';" + sudo -iH -u postgres createuser "$LIBRETIME_POSTGRESQL_USER" + sudo -iH -u postgres psql -c "ALTER ROLE $LIBRETIME_POSTGRESQL_USER WITH PASSWORD '$LIBRETIME_POSTGRESQL_PASSWORD';" set_config "$LIBRETIME_POSTGRESQL_USER" database user set_config "$LIBRETIME_POSTGRESQL_PASSWORD" database password @@ -447,10 +447,10 @@ if $LIBRETIME_SETUP_POSTGRESQL; then fi # TODO: Swap lines when Bionic support is dropped - # if ! sudo -u postgres psql --csv --tuples-only --list | grep -qw "^$LIBRETIME_POSTGRESQL_DATABASE"; then - if ! sudo -u postgres psql --tuples-only --list | grep -qw "$LIBRETIME_POSTGRESQL_DATABASE"; then + # if ! sudo -iH -u postgres psql --csv --tuples-only --list | grep -qw "^$LIBRETIME_POSTGRESQL_DATABASE"; then + if ! sudo -iH -u postgres psql --tuples-only --list | grep -qw "$LIBRETIME_POSTGRESQL_DATABASE"; then info "creating PostgreSQL database '$LIBRETIME_POSTGRESQL_DATABASE' with owner '$LIBRETIME_POSTGRESQL_USER'" - sudo -u postgres createdb --template=template0 --encoding=UTF-8 --owner="$LIBRETIME_POSTGRESQL_USER" "$LIBRETIME_POSTGRESQL_DATABASE" + sudo -iH -u postgres createdb --template=template0 --encoding=UTF-8 --owner="$LIBRETIME_POSTGRESQL_USER" "$LIBRETIME_POSTGRESQL_DATABASE" set_config "$LIBRETIME_POSTGRESQL_DATABASE" database name else