forked from stonfute/BashUSBCopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usbhook.sh
53 lines (39 loc) · 1.25 KB
/
usbhook.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
#################################################
# #
# Automatic copy on usb drive when plugged ! #
# Célestin PREAULT #
# #
#################################################
# Please add that command in /etc/udev/rules.d/99-usbhook.rules to run script when a usb drive is plugged in
#
# ACTION=="add",KERNEL=="sd*", SUBSYSTEMS=="usb", ATTRS{product}=="*", RUN+="/home/stf/usbhook.sh %k"
#
# (Change run command according to the location of that script)
#
# run that command to update udev rules : sudo udevadm control --reload-rules
#
################################################################################################################
# CONFIGURATION
LOG_FILE=/var/log/usbhook
exec > >(tee -a ${LOG_FILE} )
exec 2> >(tee -a ${LOG_FILE} >&2)
# CONFIGURATION: Source folder
SRC="/home/stf/usb_source"
DEVICE="$1" # the device name
NUMBER="${DEVICE: -1}"
if [ "$NUMBER" = "1" ]
then
exit 0
fi
mkdir /tmp/"$DEVICE"
# Mount ntfs usb drive
mount -t ntfs-3g /dev/"$DEVICE"1 /tmp/"$DEVICE"
cp -R "$SRC"/* /tmp/"$DEVICE"
chmod 777 -R /tmp/"$DEVICE"
umount /tmp/"$DEVICE"
rm -r /tmp/"$DEVICE"
echo "Copy to $DEVICE >> Done !"
export DISPLAY=:0
sudo -u stf notify-send "Copy to $DEVICE >> Done !" -t 5000
exit 0