From f2313649159210ae666606ae9b70dc02b783e115 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install b/install index 86c2a71d9..9835cd669 100755 --- a/install +++ b/install @@ -421,10 +421,10 @@ if $LIBRETIME_SETUP_POSTGRESQL; then install_packages postgresql postgresql-client if $is_first_install; then - if ! sudo -u postgres psql --csv --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 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 @@ -432,9 +432,9 @@ if $LIBRETIME_SETUP_POSTGRESQL; then warning "PostgreSQL user '$LIBRETIME_POSTGRESQL_USER' already exists!" fi - if ! sudo -u postgres psql --csv --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 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