2017-06-28 11:19:32 +00:00
|
|
|
#!/bin/sh -e
|
2013-08-29 20:33:43 +00:00
|
|
|
#
|
2013-09-17 20:41:10 +00:00
|
|
|
# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc)
|
2013-08-29 20:33:43 +00:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
get_type_from_mkfs() {
|
|
|
|
_device="$1"
|
2018-10-05 11:05:01 +00:00
|
|
|
find "$__global/object/__install_mkfs" -type d -name "$__cdist_object_marker" |
|
|
|
|
while IFS= read -r mkfs_object
|
|
|
|
do
|
2013-08-29 20:33:43 +00:00
|
|
|
mkfs_device="$(cat "$mkfs_object/parameter/device")"
|
|
|
|
if [ "$_device" = "$mkfs_device" ]; then
|
|
|
|
cat "$mkfs_object/parameter/type"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset _device
|
|
|
|
unset mkfs_device
|
|
|
|
unset mkfs_object
|
|
|
|
}
|
|
|
|
|
|
|
|
device="$(cat "$__object/parameter/device")"
|
|
|
|
dir="$(cat "$__object/parameter/dir")"
|
|
|
|
prefix="$(cat "$__object/parameter/prefix")"
|
|
|
|
if [ -f "$__object/parameter/type" ]; then
|
|
|
|
type="$(cat "$__object/parameter/type")"
|
|
|
|
else
|
|
|
|
type="$(get_type_from_mkfs "$device")"
|
|
|
|
# store for later use by others
|
|
|
|
echo "$type" > "$__object/parameter/type"
|
|
|
|
fi
|
2015-07-10 14:39:27 +00:00
|
|
|
[ -n "$type" ] || {
|
|
|
|
echo "Can't determine type for $__object" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2013-08-29 20:33:43 +00:00
|
|
|
if [ "$type" = "swap" ]; then
|
2017-02-01 06:16:19 +00:00
|
|
|
printf 'swapon "%s"\n' "$device"
|
2013-08-29 20:33:43 +00:00
|
|
|
else
|
2017-02-01 06:16:19 +00:00
|
|
|
mount_point="${prefix}${dir}"
|
|
|
|
printf '[ -d "%s" ] || mkdir -p "%s"\n' "$mount_point" "$mount_point"
|
|
|
|
printf 'mount'
|
|
|
|
if [ "$type" = "bind" ]; then
|
|
|
|
printf ' --bind'
|
2017-02-01 06:42:06 +00:00
|
|
|
device="${prefix}${device}"
|
2013-08-29 20:33:43 +00:00
|
|
|
else
|
2017-02-01 06:16:19 +00:00
|
|
|
printf ' -t "%s"' "$type"
|
2013-08-29 20:33:43 +00:00
|
|
|
fi
|
2017-02-01 06:16:19 +00:00
|
|
|
if [ -f "$__object/parameter/options" ]; then
|
|
|
|
printf ' -o %s' "$(cat "$__object/parameter/options")"
|
|
|
|
fi
|
|
|
|
printf ' "%s"' "$device"
|
|
|
|
printf ' "%s"\n' "$mount_point"
|
2013-08-29 20:33:43 +00:00
|
|
|
fi
|