1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!/bin/sh
usage() {
printf 'usage: %s [-hv] [-o ro|force|allow_others[,...]]... device|image mountpoint\n\nUse fuse2fs instead.\n' "${0##*/}"
exit 9
}
args="$(getopt -o 'hvo:' --long 'help,verbose,options:' -n "${0##*/}" -s 'sh' -- "$@")" || exit
eval set -- "$args"
original_options=
readonly=
force=
while :; do
case "$1" in
-o|--options)
original_options="$original_options,$2"
shift 2
;;
-h|--help)
usage
shift
;;
-v|--verbose)
shift
;;
--)
shift
break
;;
esac
done
[ $# -eq 2 ] || usage
device="$1"
mountpoint="$2"
# let fuse2fs check $device
options=
while [ -n "${original_options#,}" ]; do
original_options="${original_options#,}"
full="${original_options%%,*}"
original_options="${original_options#*,},"
case "${full%%=*}" in
"ro" ) readonly=y ;; # Read-only mount.
"rw" ) readonly= ;; # Read-write mount
"rw+" ) readonly=; force=y ;; # Read-write mount
"silent") ;; # keep silent
"force" ) force=y ;; # enable read/write
* ) options="$options,$full"; continue ;;
esac
[ "$full" = "${full%=*}" ] || {
printf '%s: %s: value given but not allowed\n' "${0##*/}" "$full" >&2
exit 254
}
done
[ -z "$readonly" ] && [ -z "$force" ] && {
printf '%s: Mounting %s Read-Only. Use '\''force'\'' or '\''rw+'\'' options to enable Read-Write mode\n' "${0##*/}" "$device" >&2
readonly=y
}
[ -n "$readonly" ] && options="$options,ro" || options="$options,rw"
exec /usr/bin/fuse2fs "$device" "$mountpoint" -o "${options#,}"
|