lets try archivemount

This commit is contained in:
Q
2023-01-01 00:45:42 +02:00
parent 6b24386b42
commit 6207e39396
2 changed files with 78 additions and 0 deletions

1
bin/archivefs-mount Symbolic link
View File

@@ -0,0 +1 @@
../files/archivefs-mount

77
files/archivefs-mount Executable file
View File

@@ -0,0 +1,77 @@
#!/bin/bash
_helpexit() {
printf "Usage: %s [-u] archive.file
arhchive is iso/tar/zip/rar whatever archivemount can handle
-u will unmount all FUSE.archivemount paths if no path given!
" "$( basename $0 )"
echo Current mounts:
cat /proc/mounts | grep fuse.archivemount | awk '{ print $1 "\t" $2 }'
exit 1
}
[[ -z "$1" ]] && _menu
for (( i=1; i<=$#; i++ )); do
[[ ${!i} = "-h" ]] && _helpexit
[[ ${!i} = "--help" ]] && _helpexit
done
unmount=false
for (( i=1; i<=$#; i++ )); do
[[ ${!i} = "-u" ]] && { unmount=true; continue; }
if [[ -z "$archive" ]]; then
archive="${!i}"
fi
done
mkdir -p ~/mnt/am
valid_name=$( basename "$archive" | sed -e 's/\s/_/g' )
mountpath=~/mnt/am/"$valid_name"
if [[ "$unmount" = true ]]; then
cd ~/mnt
if [[ -n "$archive" ]]; then
fusermount -u -z "$mountpath"
rmdir --ignore-fail-on-non-empty "$mountpath" &>/dev/null
else
# no path, unmount all
cat /proc/mounts | grep fuse.archivemount | awk '{ print $2 }' | while read dir; do
echo Unmounting $dir
fusermount -u -z "$dir"
rmdir --ignore-fail-on-non-empty "$dir" &>/dev/null
done
fi
exit
fi
if [[ -z "$archive" ]]; then
echo "No archive given"
_helpexit
fi
if [[ -d "$mountpath" ]]; then
device1=$( stat -c "%d" "$mountpath" )
device2=$( stat -c "%d" ~/mnt/am )
else
device1=valid
device2=valid
fi
if [[ $device1 = $device2 ]]; then
echo "Mounting $archive in ~/mnt/am/$valid_name"
mkdir -p "$mountpath"
archivemount \
-o readonly \
-o intr \
-o uid=`id -u` \
-o gid=`id -g` \
"$archive" "$mountpath"
if [[ $? -gt 0 ]]; then
rmdir "$mountpath"
fi
else
echo "~/mnt/$valid_name is already mounted"
fi