bin/moul: add unmounting and fstab integration

This commit is contained in:
xeruf 2021-10-31 20:30:52 +01:00
parent 74db6ce06d
commit b34c375ea0
1 changed files with 17 additions and 4 deletions

View File

@ -1,8 +1,21 @@
#!/bin/sh -e #!/bin/sh -e
# Mount a partition by label or device identifier automatically # Mount a partition by label or device identifier automatically
#test "$1" = "-u" && umount "$mountpoint"; exit $? test "$1" = "--help" && echo "$0 <device> [mountpoint] [options...]" && exit 0
mountpoint="${2:-${XDG_RUNTIME_DIR:-/mnt}/$1}" if test "$1" = "-u"
case "$1" in (sd*|loop*) partition="/dev/$1";; (*) partition="-L $1";; esac then shift
mountpoint "$mountpoint" >/dev/null || sudo mount -v -o users,X-mount.mkdir $partition "$mountpoint" "${@:3}" mountpoint=$(test -d "$1" && echo "$1" || echo "${XDG_RUNTIME_DIR}/mnt/$1")
sudo umount "$mountpoint"
code=$?
sudo rm -d "$mountpoint"
exit $?
fi
mountpoint="${2:-${XDG_RUNTIME_DIR}/mnt/$1}"
grep -e "[^\w/]$1[^\w/]" /etc/fstab && mount "$1" && exit 0
grep -e "[^\w/]$mountpoint[^\w/]" /etc/fstab && mount "$mountpoint" && exit 0
case "$1" in (sd*|loop*|nvme*) partition="/dev/$1";; (*) partition="-L $1";; esac
#uid=$(id --user),gid=$(id --group), \
mountpoint "$mountpoint" >/dev/null 2>&1 || sudo mount -vo \
users,X-mount.mkdir $partition "$mountpoint" "${@:3}"
cd $mountpoint cd $mountpoint
exec $SHELL exec $SHELL