#!/bin/sh # # FUSE mount helper # Petr Klima # Thanks to Miklos Szeredi # to kick me to the right way # VERSION="0.0.2" PRGNAME=`basename $0` if [ -z "$HOME" ]; then HOME=/root fi export HOME USAGE="${PRGNAME} version ${VERSION} usage: ${PRGNAME} fusefs_type#[mountpath] mountpoint [FUSE options] example: ${PRGNAME} sshfs#root@tux:/ /mnt/tuxssh -o rw " function die { echo -e "$PRGNAME# $1" >&2 [ -z "$2" ] && exit 128 exit "$2" } [ "$#" -ge 2 ] || die "${USAGE}" # for now i have to be same as FUSE mount binary # should be configurable eval `echo "$1" | sed -n 's,\(^[^#][^#]*\)\(#\(.*\)\)*,FSTYPE="\1" MOUNTPATH="\3",p'` export PATH FSBIN=`which ${FSTYPE} 2>/dev/null` \ || die "Can not find FUSE mount binary for FS ${FSTYPE}" 1 # was there an # in $1 [ "$1" = "$MOUNTPATH" ] && MOUNTPATH="" MOUNTPOINT="$2" [ -d "${MOUNTPOINT}" ] || die "Directory ${MOUNTPOINT} does not exist" shift shift eval `echo $@ | sed -n "s/\([^,]*,\)*setuid=\([^,]*\).*/SETUID=\2/p"` ignore_opts='\(-o\|user\|nouser\|users\|auto\|noauto\|_netdev\|setuid=[^,]*\)' # loop over each mount option and skip all that should be ignored IFS="," for OPT in $@; do OPT=`echo $OPT | sed "s/^$ignore_opts$/IGNORE/"` if [ "$OPT" == "IGNORE" ]; then continue; fi OPTIONS="$OPTIONS$OPT," done IFS=" " # add "-o " and remove trailing comma OPTIONS="-o `echo $OPTIONS | sed "s/,$//"`" if test -z "$SETUID"; then ${FSTYPE} ${MOUNTPATH} ${MOUNTPOINT} ${OPTIONS} else su - "$SETUID" -c "${FSTYPE} ${MOUNTPATH} ${MOUNTPOINT} ${OPTIONS}" fi