Improve OpenBSD support (#720)

* [type/__timezone] Whitelist OpenBSD

OpenBSD ships /etc/localtime and /usr/share/zoneinfo by default.

* [type/__postgres_{database,role}] Add explorer support for OpenBSD

On OpenBSD the "postgres" user is called "_postgresql".
The "postgres" database must me specifically specified as it differs from the
user name.

* [type/__postgres_{database,role}] Add gencode support for OpenBSD

On OpenBSD the "postgres" user is called "_postgresql".
The "postgres" database must me specifically specified when using psql as it
differs from the user name.

* [type/__postgres_role] Query DB if role exists instead of screen scaping

* [type/__postgres_database] Query DB if database exists instead

* [type/__postgres_{database,role}] Add user for NetBSD

* [type/__postgres_extension] Add support for OpenBSD and NetBSD

* [__ssh_authorized_key] Add OpenBSD support to entry explorer

Make sure to adhere to re_format(7) for OpenBSD compatibility.

https://man.openbsd.org/re_format.7

* [type/__start_on_boot] Add support for OpenBSD
This commit is contained in:
sideeffect42 2018-11-03 19:17:56 +01:00 committed by Darko Poljak
parent 6d70205319
commit a34060d703
9 changed files with 105 additions and 17 deletions

View file

@ -18,10 +18,25 @@
# 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")"
in
netbsd)
postgres_user='pgsql'
;;
openbsd)
postgres_user='_postgresql'
;;
*)
postgres_user='postgres'
;;
esac
name="$__object_id" name="$__object_id"
if su - postgres -c "echo '\\q' | psql '$name'" 2>/dev/null; then if test -n "$(su - "$postgres_user" -c "psql postgres -tAc \"SELECT 1 FROM pg_database WHERE datname='$name'\"")"
echo "present" then
echo 'present'
else else
echo "absent" echo 'absent'
fi fi

View file

@ -18,6 +18,20 @@
# 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")"
in
netbsd)
postgres_user='pgsql'
;;
openbsd)
postgres_user='_postgresql'
;;
*)
postgres_user='postgres'
;;
esac
name="$__object_id" name="$__object_id"
state_should="$(cat "$__object/parameter/state")" state_should="$(cat "$__object/parameter/state")"
state_is="$(cat "$__object/explorer/state")" state_is="$(cat "$__object/explorer/state")"
@ -29,10 +43,10 @@ if [ "$state_should" != "$state_is" ]; then
if [ -f "$__object/parameter/owner" ]; then if [ -f "$__object/parameter/owner" ]; then
owner="-O '$(cat "$__object/parameter/owner")'" owner="-O '$(cat "$__object/parameter/owner")'"
fi fi
echo "su - postgres -c \"createdb $owner '$name'\"" echo "su - '$postgres_user' -c \"createdb $owner '$name'\""
;; ;;
absent) absent)
echo "su - postgres -c \"dropdb '$name'\"" echo "su - '$postgres_user' -c \"dropdb '$name'\""
;; ;;
esac esac
fi fi

View file

@ -22,6 +22,20 @@
# 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")"
in
netbsd)
postgres_user='pgsql'
;;
openbsd)
postgres_user='_postgresql'
;;
*)
postgres_user='postgres'
;;
esac
dbname=$( echo "$__object_id" | cut -d":" -f1 ) dbname=$( echo "$__object_id" | cut -d":" -f1 )
extension=$( echo "$__object_id" | cut -d":" -f2 ) extension=$( echo "$__object_id" | cut -d":" -f2 )
@ -30,10 +44,10 @@ state_should=$( cat "$__object/parameter/state" )
case "$state_should" in case "$state_should" in
present) present)
cmd="CREATE EXTENSION IF NOT EXISTS $extension" cmd="CREATE EXTENSION IF NOT EXISTS $extension"
echo "su - postgres -c 'psql -c \"$cmd\" \"$dbname\"'" echo "su - '$postgres_user' -c 'psql -c \"$cmd\" \"$dbname\"'"
;; ;;
absent) absent)
cmd="DROP EXTENSION IF EXISTS $extension" cmd="DROP EXTENSION IF EXISTS $extension"
echo "su - postgres -c 'psql -c \"$cmd\" \"$dbname\"'" echo "su - '$postgres_user' -c 'psql -c \"$cmd\" \"$dbname\"'"
;; ;;
esac esac

View file

@ -18,10 +18,25 @@
# 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")"
in
netbsd)
postgres_user='pgsql'
;;
openbsd)
postgres_user='_postgresql'
;;
*)
postgres_user='postgres'
;;
esac
name="$__object_id" name="$__object_id"
if su - postgres -c "psql -c '\\du' | grep -q '^ *$name *|'"; then if test -n "$(su - "$postgres_user" -c "psql postgres -tAc \"SELECT 1 FROM pg_roles WHERE rolname='$name'\"")"
echo "present" then
echo 'present'
else else
echo "absent" echo 'absent'
fi fi

View file

@ -18,6 +18,20 @@
# 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")"
in
netbsd)
postgres_user='pgsql'
;;
openbsd)
postgres_user='_postgresql'
;;
*)
postgres_user='postgres'
;;
esac
name="$__object_id" name="$__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")"
@ -38,12 +52,12 @@ case "$state_should" in
booleans="$booleans $upper" booleans="$booleans $upper"
done done
[ -n "$password" ] && password="PASSWORD '$password'" [ -n "$password" ] && password="PASSWORD '$password'"
cmd="CREATE ROLE $name WITH $password $booleans" cmd="CREATE ROLE $name WITH $password $booleans"
echo "su - postgres -c \"psql -c \\\"$cmd\\\"\"" echo "su - '$postgres_user' -c \"psql postgres -c '$cmd'\""
;; ;;
absent) absent)
echo "su - postgres -c \"dropuser \\\"$name\\\"\"" echo "su - '$postgres_user' -c \"dropuser '$name'\""
;; ;;
esac esac

View file

@ -27,5 +27,8 @@ then
file="$(cat "$__object/parameter/file")" file="$(cat "$__object/parameter/file")"
# get any entries that match the type and key # get any entries that match the type and key
grep ".*$type_and_key\\([ \\n]\\|$\\)" "$file" || true
# NOTE: Do not match from the beginning of the line as there may be options
# preceeding the key.
grep "${type_and_key}\\([ \\n].*\\)*$" "$file" || true
fi fi

View file

@ -83,6 +83,10 @@ else
state="absent" state="absent"
service -e | grep "/$name$" && state="present" service -e | grep "/$name$" && state="present"
;; ;;
openbsd)
state='absent'
# OpenBSD 5.7 and higher
rcctl ls on | grep "^${name}$" && state='present'
*) *)
echo "Unsupported os: $os" >&2 echo "Unsupported os: $os" >&2
exit 1 exit 1

View file

@ -81,6 +81,11 @@ case "$state_should" in
: # handled in manifest : # handled in manifest
;; ;;
openbsd)
# OpenBSD 5.7 and phigher
echo "rcctl enable '$name'"
;;
*) *)
echo "Unsupported os: $os" >&2 echo "Unsupported os: $os" >&2
exit 1 exit 1

View file

@ -34,7 +34,11 @@ case "$os" in
__package timezone __package timezone
export require="__package/timezone" export require="__package/timezone"
;; ;;
freebsd|netbsd|coreos) freebsd|netbsd|openbsd)
# whitelist
:
;;
coreos)
# whitelist # whitelist
: :
;; ;;