forked from steve8x8/filehub-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
45usb_remove.sh
36 lines (30 loc) · 1 KB
/
45usb_remove.sh
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
# Kill rsync when a USB drive is removed
# Delete existing modification from file, if it exists
sed -i '/#START_MOD/,/#END_MOD/d' /etc/udev/script/remove_usb_storage.sh
# Add call to usb backup script after drive mounts
cat <<'EOF' >> /etc/udev/script/remove_usb_storage.sh
#START_MOD
# Kill the rsync process if the USB drive or SD card is removed
if [ -e /tmp/backup.pid ]; then
kill $(cat /tmp/backup.pid)
killall rsync
rm /tmp/backup.pid
fi
# Turn off swap if the store drive is removed
STORE_DIR=.vst
# Check if a USB drive is attached which is initialize for storing monitoring data
check_storedrive() {
while read device mountpoint fstype remainder; do
if [ ${device:0:7} == "/dev/sd" -a -e "$mountpoint/$STORE_DIR"/rsync ];then
return 1
fi
done < /proc/mounts
return 0
}
# If the store drive is no longer attached, turn off swap
check_storedrive
if [ $? -eq 0 ]; then
swapoff "$mountpoint/$STORE_DIR"/swapfile
fi
#END_MOD
EOF