/
part-hotplug-handler
49 lines (41 loc) · 1.04 KB
/
part-hotplug-handler
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
#!/bin/sh
# part-hotplug-handler: a handler executed by part-hotplug-monitor when a
# partition-related event occurs; the partition details
# (e.g its name) are passed through the environment
case "$ACTION" in
add)
# get the partition name
device_name="${DEVNAME##*/}"
if [ -d /mnt/$device_name ]
then
mountpoint -q /mnt/$device_name
[ 0 -eq $? ] && exec xdg-open /mnt/$device_name
else
# create a mount point
mkdir /mnt/$device_name
[ 0 -ne $? ] && exit 1
fi
# mount the partition
mount "$DEVNAME" /mnt/$device_name
[ 0 -ne $? ] && exit 1
# open the mount point
exec xdg-open /mnt/$device_name
;;
remove)
# get the partition name
device_name="${DEVNAME##*/}"
if [ -d /mnt/$device_name ]
then
mountpoint -q /mnt/$device_name
if [ 0 -eq $? ]
then
# unmount the partition and delete the mount point
umount /mnt/$device_name
[ 0 -eq $? ] && rmdir /mnt/$device_name
fi
fi
;;
change)
# when a change event occurs, do nothing
;;
esac