[type/__postgres_role] Lint
This commit is contained in:
parent
71f2283117
commit
932e2496ed
2 changed files with 58 additions and 52 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/sh -e
|
||||||
#
|
#
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
#
|
#
|
||||||
|
@ -18,23 +18,23 @@
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
case "$("${__explorer}/os")"
|
case $("${__explorer:?}/os")
|
||||||
in
|
in
|
||||||
netbsd)
|
(netbsd)
|
||||||
postgres_user='pgsql'
|
postgres_user='pgsql'
|
||||||
;;
|
;;
|
||||||
openbsd)
|
(openbsd)
|
||||||
postgres_user='_postgresql'
|
postgres_user='_postgresql'
|
||||||
;;
|
;;
|
||||||
*)
|
(*)
|
||||||
postgres_user='postgres'
|
postgres_user='postgres'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
name="$__object_id"
|
rolename=${__object_id:?}
|
||||||
|
|
||||||
if test -n "$(su - "$postgres_user" -c "psql postgres -twAc \"SELECT 1 FROM pg_roles WHERE rolname='$name'\"")"
|
if test -n "$(su - "${postgres_user}" -c "psql postgres -twAc \"SELECT 1 FROM pg_roles WHERE rolname='${rolename}'\"")"
|
||||||
then
|
then
|
||||||
echo 'present'
|
echo 'present'
|
||||||
else
|
else
|
||||||
|
|
|
@ -18,48 +18,54 @@
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
case "$(cat "${__global}/explorer/os")"
|
case $(cat "${__global:?}/explorer/os")
|
||||||
in
|
in
|
||||||
netbsd)
|
(netbsd)
|
||||||
postgres_user='pgsql'
|
postgres_user='pgsql'
|
||||||
;;
|
;;
|
||||||
openbsd)
|
(openbsd)
|
||||||
postgres_user='_postgresql'
|
postgres_user='_postgresql'
|
||||||
;;
|
;;
|
||||||
*)
|
(*)
|
||||||
postgres_user='postgres'
|
postgres_user='postgres'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
name="$__object_id"
|
rolename=${__object_id:?}
|
||||||
state_is="$(cat "$__object/explorer/state")"
|
state_is=$(cat "${__object:?}/explorer/state")
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should=$(cat "${__object:?}/parameter/state")
|
||||||
|
|
||||||
[ "$state_is" = "$state_should" ] && exit 0
|
if test "${state_is}" = "${state_should}"
|
||||||
|
then
|
||||||
case "$state_should" in
|
exit 0
|
||||||
present)
|
|
||||||
if [ -f "$__object/parameter/password" ]; then
|
|
||||||
password="$(cat "$__object/parameter/password")"
|
|
||||||
fi
|
fi
|
||||||
booleans=""
|
|
||||||
for boolean in login createdb createrole superuser; do
|
case ${state_should}
|
||||||
if [ ! -f "$__object/parameter/$boolean" ]; then
|
in
|
||||||
|
(present)
|
||||||
|
if test -f "${__object:?}/parameter/password"
|
||||||
|
then
|
||||||
|
password=$(cat "${__object:?}/parameter/password")
|
||||||
|
fi
|
||||||
|
booleans=
|
||||||
|
for boolean in login createdb createrole superuser
|
||||||
|
do
|
||||||
|
if test ! -f "${__object:?}/parameter/${boolean}"
|
||||||
|
then
|
||||||
boolean="no${boolean}"
|
boolean="no${boolean}"
|
||||||
fi
|
fi
|
||||||
upper=$(echo $boolean | tr '[:lower:]' '[:upper:]')
|
booleans="${booleans} $(echo ${boolean} | tr '[:lower:]' '[:upper:]')"
|
||||||
booleans="$booleans $upper"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
[ -n "$password" ] && password="PASSWORD '$password'"
|
[ -n "${password}" ] && password="PASSWORD '${password}'"
|
||||||
cat << EOF
|
cat << EOF
|
||||||
su - '$postgres_user' -c "psql postgres -wc \"CREATE ROLE \\\\\"$name\\\\\" WITH $password $booleans;\""
|
su - '${postgres_user}' -c "psql postgres -wc 'CREATE ROLE \\"${rolename}\\" WITH ${password} ${booleans};'"
|
||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
absent)
|
(absent)
|
||||||
cat << EOF
|
cat << EOF
|
||||||
su - '$postgres_user' -c "dropuser \"$name\""
|
su - '${postgres_user}' -c "dropuser '${rolename}'"
|
||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue