From: Roman Bazalevsky Date: Mon, 20 Nov 2017 13:33:29 +0000 (+0300) Subject: Scripts and triggerhappy configs X-Git-Url: https://git.rvb.name/n2100.git/commitdiff_plain/d5fdca706866a9492ef3b193a497d7fd18914b9e Scripts and triggerhappy configs --- diff --git a/copy.conf b/copy.conf new file mode 100644 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 index 0000000..fe913c1 --- /dev/null +++ b/key_pressed @@ -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 index 0000000..8570738 --- /dev/null +++ b/key_released @@ -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 index 0000000..2ad85f0 --- /dev/null +++ b/scriptenv.conf @@ -0,0 +1,2 @@ +LAST_PRESSED=/var/run/thd.last +DIR_BASE=/srv/usbcopy \ No newline at end of file