new type to manage mounts, either via fstab or manually

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2014-01-14 21:39:24 +01:00
parent 746d9ec12b
commit 33c8f83fa6
10 changed files with 212 additions and 0 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
#
path="$(cat "$__object/parameter/path" 2>/dev/null || echo "/$__object_id")"
if mountpoint -q "$path"; then
echo yes
else
echo no
fi

View file

@ -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 <http://www.gnu.org/licenses/>.
#
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

View file

@ -0,0 +1,80 @@
cdist-type__mount(7)
====================
Steven Armstrong <steven-cdist--@--armstrong.cc>
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).

View file

@ -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 <http://www.gnu.org/licenses/>.
#
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

View file

@ -0,0 +1 @@
nofstab

View file

@ -0,0 +1 @@
none

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,7 @@
device
dump
options
pass
path
state
type