-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsync-loop.sh
executable file
·76 lines (65 loc) · 1.93 KB
/
rsync-loop.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Executables
rsync="/usr/bin/rsync"
command -v $rsync >/dev/null 2>&1 || { echo >&2 "I require $rsync but it's not installed"; exit 1; }
# TODO other commands like ls, lsusb, mount, etc
if [ -z "$MEDIA_PATH" ]
then
echo >&2 "MEDIA_PATH must be set"; exit 1;
fi
CARD_DEV='sda1'
CARD_MOUNT_POINT='/media/card'
STORAGE_DIR="$MEDIA_PATH/storage"
echo start
# Set the ACT LED to heartbeat
sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger"
echo heartbeat
# Wait for a USB SD reader (ID 8564:4000 Transcend Information, Inc. RDF8)
# Wait for a USB SD reader (ID 05e3:0749 Genesys Logic, Inc.)
echo wait reader
while [ -z "$(lsusb -d 8564:4000 )$(lsusb -d 05e3:0749)" ]
do
sleep 1
done
echo wait card
# Handle cards as long as the reader is plugged in
while [ -n "$(lsusb -d 8564:4000 )$(lsusb -d 05e3:0749)" ]
do
if [ -n "$(ls /dev/* | grep $CARD_DEV | cut -d"/" -f3)" ]
then
echo found card
# TODO make this reference the mount point var
if [ -z "$(ls /media/card)" ]
then
mount /dev/$CARD_DEV $CARD_MOUNT_POINT
fi
echo mounted card
echo running tasks...
# Set the ACT LED to blink at 1000ms to indicate that the storage device has been mounted
sudo sh -c "echo timer > /sys/class/leds/led0/trigger"
sudo sh -c "echo 1000 > /sys/class/leds/led0/delay_on"
echo blinking
echo start rsync
shopt -s globstar
JPEGS="$CARD_MOUNT_POINT/**/*JPG"
rsync --bwlimit=5m -avh $JPEGS $STORAGE_DIR/
echo end rsync
# Unmount the SD card
umount /dev/$CARD_DEV
echo unmounted card
# Set the ACT LED to heartbeat
echo heartbeat
sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger"
echo waiting for card removal
# Wait for SD card removal
while [ -n "$(ls /dev/* | grep $CARD_DEV | cut -d"/" -f3)" ]
do
sleep 1
done
echo card removed
fi
sleep 1
done
# reboot once the reader is ejected
echo shutting down
sudo shutdown -h now