From eecc064b5e16a46041f6fe7b4618962aa0e7f33f Mon Sep 17 00:00:00 2001 From: "committer@tuxwarrior" Date: Thu, 27 Feb 2025 10:43:18 -0500 Subject: [PATCH] + script to switch ownership on directory --- dots/bin/quick_pgDatadirChownSwitch.sh | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 dots/bin/quick_pgDatadirChownSwitch.sh diff --git a/dots/bin/quick_pgDatadirChownSwitch.sh b/dots/bin/quick_pgDatadirChownSwitch.sh new file mode 100755 index 0000000..5328e89 --- /dev/null +++ b/dots/bin/quick_pgDatadirChownSwitch.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# klevstul :: 25.02 + +dir_psqdata=/home/poq/syncDir/quick/onedrive/swas/postgresql/dataLnx + + + +if ! [ -d "${dir_psqdata}" ]; then + echo "error: non-existing directory '${dir_psqdata}'" + exit 1 +else + echo "postgresql data directory: '${dir_psqdata}'" +fi + +username=$(stat -c '%U' ${dir_psqdata}) + +if [[ ${username} == "postgres" ]]; then + echo "change owner to ${USER} (postgres ➔ ${USER})?" + + echo "do you want to continue? (y/n)" + read user_input + if [[ ${user_input} != "y" ]]; then + echo "bye!" + exit 1 + fi + + sudo chown ${USER}:${USER} -R ${dir_psqdata} + +elif [[ ${username} == "${USER}" ]]; then + echo "change owner to 'postgres' (${USER} ➔ postgres)?" + + echo "do you want to continue? (y/n)" + read user_input + if [[ ${user_input} != "y" ]]; then + echo "bye!" + exit 1 + fi + + sudo chown postgres:postgres -R ${dir_psqdata} +else + echo "error: unknown username - not sure what to do in this case, except for quitting. bye!" + exit 1 +fi