Thanks vehystrix for sharing your wrapper script. I recently used it to mount a directory inside a users's home. I found two issues I wanted to improve with your script:
- renaming the original
mont.posixovl
binary means it could brake as soon as the packet manager of your distribution installs a new update
- the original
mount.posixovl
is always started as root and it seems to ignore uid=
and gid=
mount options. This resulted int he filesytem being inaccessible for the user who's home it was mounted to
I slightly changed your script and saved it to /sbin/mount.fuse-posixovl
instead (which correlates with the ubuntu package name), so i could use a type fuse-posixovl
in fstab to mount it.
Here is the modified version of your script:
#!/bin/bash
# wrapper for mount.posixovl to conform with common mount syntax
# with this wrapper posixovl can be used in fstab
# location of the original mount.posixovl
origposixovl="/sbin/mount.posixovl"
# gather inputs
while [ $# -gt 0 ]; do
if [[ "$1" == -* ]]; then
# var is an input switch
# we can only use the -o or -F switches
if [[ "$1" == *F* ]]; then
optsF="-F"
else
optsF=""
fi
if [[ "$1" == *o* ]]; then
shift
if [[ "$1" == *uid=* ]]; then
runas=$(getent passwd $(echo "$1" | sed -E -e 's/^.*uid=([^,]+)(,.*)?$/\1/') | cut -d: -f1)
fi
optsfuse="-- -o $1"
else
optsfuse=""
fi
shift
else
# var is a main argument
sourcedir="$1"
shift
if [[ "$1" != -* ]]; then
targetdir="$1"
shift
else
targetdir="$sourcedir"
fi
fi
done
# verify inputs
if [ "$sourcedir" == "" ]; then
echo "no source specified"
exit 1
fi
if [ "$targetdir" == "" ]; then
echo "no target specified"
exit 1
fi
# build mount.posixovl command
if [[ -n "$runas" ]]; then
su - "${runas}" -c "\"$origposixovl\" $optsF -S \"$sourcedir\" \"$targetdir\" $optsfuse"
else
"$origposixovl" $optsF -S "$sourcedir" "$targetdir" $optsfuse
fi
and here is an example of a fstab line using it:
/home/myuser/Nextcloud/homebin /home/myuser/bin fuse-posixovl uid=1000,gid=1000 0 0