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