-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedia
More file actions
executable file
·79 lines (77 loc) · 1.52 KB
/
media
File metadata and controls
executable file
·79 lines (77 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
# check if stdout is a terminal...
if [ -t 1 ]
then
__echo() {
echo "$@"
}
else
__echo() {
dunstify -a media "$@"
}
fi
INTERACTIVE=false
ARGS=true
PATTERN=
process_args() {
if [ -z "$PATTERN" ]
then
PATTERN="$1"
INTERACTIVE=true
else
PATTERN="$PATTERN|$1"
fi
}
while [ "$#" -gt 0 ]
do
if $ARGS
then
case "$1" in
(--)
ARGS=false
;;
(-i)
INTERACTIVE=true
;;
(*)
process_args "$1"
;;
esac
else
process_args "$1"
fi
shift
done
IFS='
'
for DEVICE in $(lsblk -psrno NAME,TYPE,MOUNTPOINT,HOTPLUG,FSTYPE,LABEL \
| sed 's/\\x20/ /g' | grep -E "(part|disk) 1 [^ ].*($PATTERN)")
do
if $INTERACTIVE
then
IFS=' '
read -p "Mount $(echo "$DEVICE" | sed 's/part 1//') [Y/n]? " RESPONSE
IFS='
'
case $RESPONSE in
[Nn]*)
continue
;;
esac
fi
OUTPUT="$(udisksctl mount -b "$(echo "$DEVICE" | cut -d' ' -f1)")"
OUTPUT="${OUTPUT%.}"
__echo "$OUTPUT"
DEV_PATH="/${OUTPUT##* at /}"
if [ -n "$SUDO_UID" ] && [ "$(stat -c "%u" "$DEV_PATH")" -ne "$SUDO_UID" ]
then
NAME="$(basename "$DEV_PATH")"
mkdir -p "$HOME/mnt/$NAME"
if bindfs -u $SUDO_UID -g $SUDO_GID "$DEV_PATH" "$HOME/mnt/$NAME"
then
__echo "Binded at $HOME/mnt/$NAME"
else
rmdir "$HOME/mnt/$NAME"
fi
fi
done