Scripts and triggerhappy configs master
authorRoman Bazalevsky <rvb@kerberos.rvb-home.lan>
Mon, 20 Nov 2017 13:33:29 +0000 (16:33 +0300)
committerRoman Bazalevsky <rvb@kerberos.rvb-home.lan>
Mon, 20 Nov 2017 13:33:29 +0000 (16:33 +0300)
copy.conf [new file with mode: 0644]
key_pressed [new file with mode: 0755]
key_released [new file with mode: 0755]
scriptenv.conf [new file with mode: 0644]

diff --git a/copy.conf b/copy.conf
new file mode 100644 (file)
index 0000000..364f8d9
--- /dev/null
+++ b/copy.conf
@@ -0,0 +1,2 @@
+KEY_COPY 1 /usr/local/bin/key_pressed
+KEY_COPY 0 /usr/local/bin/key_released
diff --git a/key_pressed b/key_pressed
new file mode 100755 (executable)
index 0000000..fe913c1
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. /etc/triggerhappy/scriptenv.conf
+
+touch $LAST_PRESSED
diff --git a/key_released b/key_released
new file mode 100755 (executable)
index 0000000..8570738
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+. /etc/triggerhappy/scriptenv.conf
+
+if [ -e $LAST_PRESSED ]; then
+  seconds=$(($(date +%s) - $(date +%s -r $LAST_PRESSED)))
+else
+  seconds=0
+fi
+
+if [ $seconds -lt 3 ]; then
+
+  beep -l 200
+
+  for dev in /media/usb*; do
+  
+    if [ ! -L $dev ]; then
+  
+      blkdev=`findmnt -nr $dev | awk '{ print $2; }'`
+      if [ "$blkdev" != "" ]; then
+
+        label=`blkid -s LABEL -o value $blkdev`
+        uuid=`blkid -s UUID -o value $blkdev`
+        if [ "$label" != "" ]; then
+          dirname="$uuid ($label)"
+        else
+          dirname="$uuid"
+        fi
+
+       dir="$DIR_BASE/$dirname"
+       
+       echo $dev $dir
+       mkdir -p "$dir"
+       rsync -rv "$dev" "$dir" --exclude="lost+found"
+
+      fi
+      
+    fi
+  
+  done    
+
+fi
+
+
+sync
+umount /media/usb*
+beep -l 500
diff --git a/scriptenv.conf b/scriptenv.conf
new file mode 100644 (file)
index 0000000..2ad85f0
--- /dev/null
@@ -0,0 +1,2 @@
+LAST_PRESSED=/var/run/thd.last
+DIR_BASE=/srv/usbcopy
\ No newline at end of file