From b67ced0f2eac48387ce46cb5b5ea9dfe0eb210ee Mon Sep 17 00:00:00 2001 From: Andreas Hrubak Date: Tue, 30 Jul 2024 16:58:03 +0200 Subject: [PATCH] add new mount helper (virtual fstype) : mount.abshelper --- mount/Makefile | 5 ++++- mount/mount.abshelper | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100755 mount/mount.abshelper diff --git a/mount/Makefile b/mount/Makefile index 83d989e..20181b8 100644 --- a/mount/Makefile +++ b/mount/Makefile @@ -1,5 +1,5 @@ -TOOLS = mount.bindfs mount.posixovlfs mount.xattrovlfs mount.fusefile \ +TOOLS = mount.bindfs mount.posixovlfs mount.xattrovlfs mount.fusefile mount.abshelper \ mount.restic TARGETS = $(foreach name,$(TOOLS),/sbin/$(name)) @@ -15,3 +15,6 @@ install-all: $(TARGETS) $(TARGETS): /sbin/%: % install --compare $< $@ @echo remove $@ >> uninstall.sh + + +# TODO: discover usage of /sbin/fs.d and /sbin/fs directories. diff --git a/mount/mount.abshelper b/mount/mount.abshelper new file mode 100755 index 0000000..9136a2c --- /dev/null +++ b/mount/mount.abshelper @@ -0,0 +1,48 @@ +#!/bin/bash + +# this wrapper mount script makes relative device paths to absolute. +# some mount fs types needs them to be absolute, but I'd like to keep +# the option to be able to mount different devices in different directories, +# only their relative paths being the same. + +set -e +set -u + +mount_opts=() + +dev=$1 +shift +moutpoint=$1 +shift + +while [ $# -gt 0 ] +do + case "$1" in + (-t) + shift + fstype=$1 + if [[ $fstype =~ abshelper\.(.+) ]] + then + fstype_encoded=${BASH_REMATCH[1]} + fstype=${fstype_encoded//\//.} + fi + if [[ $fstype =~ ([^.]+) ]] + then + fstype_master=${BASH_REMATCH[1]} + else + fstype_master=$fstype + fi + ;; + (*) + mount_opts+=("$1") + ;; + esac + shift +done + +if [ "${dev:0:1}" != / ] +then + dev=$PWD/$dev +fi + +exec /sbin/"mount.$fstype_master" "$dev" "$moutpoint" -t "$fstype" "${mount_opts[@]}" -- 2.11.4.GIT