SHA256
70 lines
1.7 KiB
Bash
Executable File
70 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
PREFIX="$(dirname $(realpath $0))/.."
|
|
source "${PREFIX}/share/config.sh"
|
|
|
|
usage() {
|
|
echo "usage: airup-mount [-t type] [-o options] [-n name] [-d dependencies] [from] [to]"
|
|
echo
|
|
echo "Create Airup service that mounts given filesystem."
|
|
echo
|
|
echo "options:"
|
|
echo " -t limit the set of filesystem types"
|
|
echo " -o comma-separated list of mount options"
|
|
echo " -n name of the mount service"
|
|
echo " -d dependencies of the mount service"
|
|
exit 1
|
|
}
|
|
|
|
deps_to_array() {
|
|
[ -z "$1" ] && { printf '[]'; return; }
|
|
|
|
printf '%s' "$1" \
|
|
| sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' \
|
|
-e 's/[[:space:]]*,[[:space:]]*/", "/g' \
|
|
-e 's/^/["/' -e 's/$/"]/'
|
|
}
|
|
|
|
generate() {
|
|
echo "[service]"
|
|
echo "display-name = \"Filesystem ${dst}\""
|
|
echo "description = \"This service mounts from ${src} to ${dst}.\""
|
|
echo "kind = \"oneshot\""
|
|
echo "dependencies = $(deps_to_array ${dependencies})"
|
|
echo
|
|
echo "[exec]"
|
|
echo "start = \"mount -o '${options}' -t '${type}' '${src}' '${dst}'\""
|
|
echo "stop = \"umount '${dst}'\""
|
|
}
|
|
|
|
type="auto"
|
|
options="defaults"
|
|
|
|
while getopts ":t:o:d:n:rh" opt; do
|
|
case "$opt" in
|
|
t) type="$OPTARG" ;;
|
|
o) options="$OPTARG" ;;
|
|
d) dependencies="$OPTARG" ;;
|
|
n) name="$OPTARG" ;;
|
|
r) raw=1 ;;
|
|
:) usage ;;
|
|
\?) usage ;;
|
|
h) usage ;;
|
|
*) usage ;;
|
|
esac
|
|
done
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
src="$1"
|
|
dst="$2"
|
|
|
|
[ -z "$name" ] && name=mount-$(echo "${dst#/}" | tr "/" "-")
|
|
|
|
if [ "$raw" = "1" ]; then
|
|
generate
|
|
else
|
|
mkdir -p "${SERVICEDIR}" || exit 1
|
|
generate >> "${SERVICEDIR}/${name}.airs"
|
|
fi
|