-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathricoh-download.sh
executable file
·88 lines (64 loc) · 1.57 KB
/
ricoh-download.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
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/zsh
set -e
IP_CAMERA=192.168.0.1
URI_BASE="http://$IP_CAMERA/v1"
ESSID_CAMERA=GR_4CF5C6
usage="$0 Nimages
Nimages is how many most-recent photos to download
"
N=$1
[[ -z "$N" ]] && {
echo $usage
exit 1
}
function wifi_connect {
ESSID=$1
iwctl station $WLAN scan
iwctl station $WLAN connect $ESSID
sudo killall udhcpc || true
sudo udhcpc -i $WLAN
}
function wifi_params {
# Return first device that has an essid
/sbin/iw dev \
| awk '/Interface/ && $2 { interface=$2 }
/ssid/ && $2 && interface { print interface,$2; exit}'
}
function wifi_reset {
wifi_connect $ESSID_BASE
}
wifi_params | read WLAN ESSID_BASE
[[ -z "$ESSID_BASE" ]] && {
echo "Couldn't get the WLAN interface and the current ESSID. Giving up" > /dev/stderr
exit 1
}
wifi_connect $ESSID_CAMERA
photos_json=$(curl -s "$URI_BASE/photos")
[[ -z "$photos_json" ]] &&
{
echo "No 'photos' json output"
wifi_reset
exit 1
}
dir_last=$(echo $photos_json |
jq ".dirs[-1].name" |
perl -nE '/[a-zA-Z0-9_]+/p && say ${^MATCH}')
[[ -z "$dir_last" ]] &&
{
echo "No last-directory found"
wifi_reset
exit 1
}
photos_last=($(echo $photos_json |
jq ".dirs[-1].files[-$N:]" |
perl -nE '/R.*JPG/p && say ${^MATCH}'))
[[ -z "$photos_last" ]] &&
{
echo "No last photos found"
wifi_reset
exit 1
}
for photo ($photos_last) {
curl "$URI_BASE/photos/$dir_last/$photo" --output $photo
}
wifi_reset