summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2023-05-26 12:57:17 -0500
committerzachir <zachir@librem.one>2023-05-26 12:57:17 -0500
commit1213ff7f0a1f6a0610ffc9978010dbeab7690b49 (patch)
tree9ae0fffafbba178495a9557dc6a76b83693ca622
parentab332accaee3126f04893cceffd58d6d089decf5 (diff)
add dmount flag to give user permission when mounting
-rwxr-xr-xdmount21
1 files changed, 19 insertions, 2 deletions
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)"