From 33c8f83fa6e5cfb8b5765d95b6ca4dc396f44506 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 14 Jan 2014 21:39:24 +0100 Subject: [PATCH] new type to manage mounts, either via fstab or manually Signed-off-by: Steven Armstrong --- cdist/conf/type/__mount/explorer/mounted | 27 +++++++ cdist/conf/type/__mount/gencode-remote | 51 ++++++++++++ cdist/conf/type/__mount/man.text | 80 +++++++++++++++++++ cdist/conf/type/__mount/manifest | 42 ++++++++++ cdist/conf/type/__mount/parameter/boolean | 1 + .../type/__mount/parameter/default/device | 1 + .../conf/type/__mount/parameter/default/dump | 1 + .../conf/type/__mount/parameter/default/pass | 1 + .../conf/type/__mount/parameter/default/state | 1 + cdist/conf/type/__mount/parameter/optional | 7 ++ 10 files changed, 212 insertions(+) create mode 100755 cdist/conf/type/__mount/explorer/mounted create mode 100755 cdist/conf/type/__mount/gencode-remote create mode 100644 cdist/conf/type/__mount/man.text create mode 100755 cdist/conf/type/__mount/manifest create mode 100644 cdist/conf/type/__mount/parameter/boolean create mode 100644 cdist/conf/type/__mount/parameter/default/device create mode 100644 cdist/conf/type/__mount/parameter/default/dump create mode 100644 cdist/conf/type/__mount/parameter/default/pass create mode 100644 cdist/conf/type/__mount/parameter/default/state create mode 100644 cdist/conf/type/__mount/parameter/optional diff --git a/cdist/conf/type/__mount/explorer/mounted b/cdist/conf/type/__mount/explorer/mounted new file mode 100755 index 00000000..81f8e454 --- /dev/null +++ b/cdist/conf/type/__mount/explorer/mounted @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2014 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +path="$(cat "$__object/parameter/path" 2>/dev/null || echo "/$__object_id")" + +if mountpoint -q "$path"; then + echo yes +else + echo no +fi diff --git a/cdist/conf/type/__mount/gencode-remote b/cdist/conf/type/__mount/gencode-remote new file mode 100755 index 00000000..2626f3de --- /dev/null +++ b/cdist/conf/type/__mount/gencode-remote @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2014 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +path="$(cat "$__object/parameter/path" 2>/dev/null || echo "/$__object_id")" +state_should="$(cat "$__object/parameter/state")" +state_is="$(grep -q -x yes "$__object/explorer/mounted" && echo present || echo absent)" + +if [ "$state_should" = "$state_is" ]; then + # nothing to do + exit 0 +fi + +case "$state_should" in + present) + if [ -f "$__object/parameter/nofstab" ]; then + # mount manually + printf 'mount' + if [ -f "$__object/parameter/type" ]; then + printf ' -t %s' "$(cat "$__object/parameter/type")" + fi + if [ -f "$__object/parameter/options" ]; then + printf ' -o %s' "$(cat "$__object/parameter/options")" + fi + printf ' %s' "$(cat "$__object/parameter/device")" + printf " %s\n" "$path" + else + # mount using existing fstab entry + printf 'mount "%s"\n' "$path" + fi + ;; + absent) + printf 'umount "%s"\n' "$path" + ;; +esac diff --git a/cdist/conf/type/__mount/man.text b/cdist/conf/type/__mount/man.text new file mode 100644 index 00000000..89a7df77 --- /dev/null +++ b/cdist/conf/type/__mount/man.text @@ -0,0 +1,80 @@ +cdist-type__mount(7) +==================== +Steven Armstrong + + +NAME +---- +cdist-type__mount - manage filesystem mounts + + +DESCRIPTION +----------- +Manage filesystem mounts either via /etc/fstab or manually. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +device:: + device to mount at path, defaults to 'none'. see mount(8) + +dump:: + value for the dump field in fstab. see fstab(5) + defaults to 0. + +options:: + comma separated string of options, see mount(8) + +pass:: + value for the pass field in fstab. see fstab(5) + defaults to 0. + +path:: + mount point where to mount the device, see mount(8). + Defaults to __object_id + +state:: + either present or absent. Defaults to present. + +type:: + vfstype, see mount(8) + + +BOOLEAN PARAMETERS +------------------ +nofstab:: + do not manage an entry in /etc/fstab + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__mount /some/dir \ + --device /dev/sdc3 \ + --type xfs \ + --options "defaults,ro" + --dump 0 \ + --pass 1 + +__mount /var/lib/one \ + --device mfsmount \ + --type fuse \ + --options "mfsmaster=mfsmaster.domain.tld,mfssubfolder=/one,nonempty,_netdev" +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2014 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__mount/manifest b/cdist/conf/type/__mount/manifest new file mode 100755 index 00000000..ff891bb8 --- /dev/null +++ b/cdist/conf/type/__mount/manifest @@ -0,0 +1,42 @@ +#!/bin/sh +# +# 2014 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +path="$(cat "$__object/parameter/path" 2>/dev/null || echo "/$__object_id")" +state="$(cat "$__object/parameter/state")" + +if [ ! -f "$__object/parameter/nofstab" ]; then + # Generate an entry for /etc/fstab + ( +printf "%s" "$(cat "$__object/parameter/device")" +printf " %s" "$path" +type="$(cat "$__object/parameter/type" || echo "auto")" +printf " %s" "$type" +options="$(cat "$__object/parameter/options" || echo "defaults")" +printf " %s" "$options" +printf " %s" "$(cat "$__object/parameter/dump")" +printf " %s\n" "$(cat "$__object/parameter/pass")" +) | \ +__block "$__object_name" \ + --file "/etc/fstab" \ + --prefix "#cdist:$__object_name" \ + --suffix "#/cdist:$__object_name" \ + --state "$state" \ + --text - +fi diff --git a/cdist/conf/type/__mount/parameter/boolean b/cdist/conf/type/__mount/parameter/boolean new file mode 100644 index 00000000..ac6f41a8 --- /dev/null +++ b/cdist/conf/type/__mount/parameter/boolean @@ -0,0 +1 @@ +nofstab diff --git a/cdist/conf/type/__mount/parameter/default/device b/cdist/conf/type/__mount/parameter/default/device new file mode 100644 index 00000000..621e94f0 --- /dev/null +++ b/cdist/conf/type/__mount/parameter/default/device @@ -0,0 +1 @@ +none diff --git a/cdist/conf/type/__mount/parameter/default/dump b/cdist/conf/type/__mount/parameter/default/dump new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/cdist/conf/type/__mount/parameter/default/dump @@ -0,0 +1 @@ +0 diff --git a/cdist/conf/type/__mount/parameter/default/pass b/cdist/conf/type/__mount/parameter/default/pass new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/cdist/conf/type/__mount/parameter/default/pass @@ -0,0 +1 @@ +0 diff --git a/cdist/conf/type/__mount/parameter/default/state b/cdist/conf/type/__mount/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__mount/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__mount/parameter/optional b/cdist/conf/type/__mount/parameter/optional new file mode 100644 index 00000000..29d3e5ef --- /dev/null +++ b/cdist/conf/type/__mount/parameter/optional @@ -0,0 +1,7 @@ +device +dump +options +pass +path +state +type