From 1213ff7f0a1f6a0610ffc9978010dbeab7690b49 Mon Sep 17 00:00:00 2001 From: zachir Date: Fri, 26 May 2023 12:57:17 -0500 Subject: add dmount flag to give user permission when mounting --- dmount | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'dmount') diff --git a/dmount b/dmount index 8b0b2b7..0aeb89f 100755 --- a/dmount +++ b/dmount @@ -14,10 +14,14 @@ error_msg () { exit 1 } -while getopts "xwhd:" o; do case "${o}" in +while getopts "xwhpPugd:" o; do case "${o}" in x) DMENU="dmenu" ;; w) DMENU="bemenu" ;; d) ARGS="$ARGS $OPTARG" ;; + p) USE_USER_ID="y" ;; + P) unset USE_USER_ID ;; + u) USERID="$OPTARG" ;; + g) GROUPID="$OPTARG" ;; h) printhelp exit @@ -87,7 +91,20 @@ getmount() { \ mount_device () { getmount "/mnt /media /mount /home -maxdepth 3 -type d -empty $alreadymounted" - doas mount "$1" "$mp" && show "Mounted successfully\n" + if [ -z "$USE_USER_ID" ]; then + doas mount "$1" "$mp" && show "Mounted successfully\n" + else + if [ -n "$USERID" -a -n "$GROUPID" ]; then + MOUNTPROPS="uid=$USERID,gid=$GROUPID" + elif [ -n "$USERID" ]; then + MOUNTPROPS="uid=$USERID" + elif [ -n "$GROUPID" ]; then + MOUNTPROPS="gid=$GROUPID" + else + MOUNTPROPS="$(grep "$(whoami)" /etc/passwd | sed 's/:/ /g' | awk '{print "uid="$3",gid="$4}')" + fi + doas mount -o "$MOUNTPROPS" "$1" "$mp" && show "Mounted successfully\n" + fi } DEVICE="$(get_available | $DMENU -p "Devices" $ARGS -l 15)" -- cgit v1.2.3