2021-10-27 08:00:54 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
# Mount a partition by label or device identifier automatically
|
2021-10-31 19:30:52 +00:00
|
|
|
test "$1" = "--help" && echo "$0 <device> [mountpoint] [options...]" && exit 0
|
|
|
|
if test "$1" = "-u"
|
|
|
|
then shift
|
|
|
|
mountpoint=$(test -d "$1" && echo "$1" || echo "${XDG_RUNTIME_DIR}/mnt/$1")
|
|
|
|
sudo umount "$mountpoint"
|
|
|
|
code=$?
|
|
|
|
sudo rm -d "$mountpoint"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
2021-11-04 11:19:43 +00:00
|
|
|
grep -e "[^\w=/]$1[^\w/]" /etc/fstab && mount "$@" && exit 0
|
|
|
|
case "$1" in
|
|
|
|
(sd*|loop*|nvme*|md*|dm*|vg*) partition="/dev/$1"
|
|
|
|
mountpoint="${2:-${MNT:-${XDG_RUNTIME_DIR}/mnt}/$1}"
|
|
|
|
grep -e "[^\w=/]$mountpoint[^\w/]" /etc/fstab && shift && mount "$mountpoint" "$@" && exit 0;;
|
|
|
|
(*) partition="-L $1";;
|
|
|
|
esac
|
|
|
|
shift $(expr 2 \& $# \> 1 \| 1)
|
2021-10-31 19:30:52 +00:00
|
|
|
#uid=$(id --user),gid=$(id --group), \
|
|
|
|
mountpoint "$mountpoint" >/dev/null 2>&1 || sudo mount -vo \
|
2021-11-04 11:19:43 +00:00
|
|
|
users,X-mount.mkdir,noatime $partition $mountpoint "$@"
|
2021-10-27 08:00:54 +00:00
|
|
|
cd $mountpoint
|
|
|
|
exec $SHELL
|