#!/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 } 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 echo Unmounting "$mountpath" 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/am/$valid_name is already mounted" fi