-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauto_tasks.sh
executable file
·69 lines (58 loc) · 2.15 KB
/
auto_tasks.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
#!/bin/bash
watched_files="$1" # pass watched files as cmd line arguments
if [ -z "$watched_files" ]; then
echo "Nothing to watch, abort"
exit
else
echo "Watching: $watched_files"
fi
previous_checksum="dummy"
while [ 1 ]; do
case "$OSTYPE" in
darwin*) checksum=$(md5 $watched_files | md5) ;;
linux*) checksum=$(md5sum $watched_files | md5sum) ;;
esac
if [ "$checksum" != "$previous_checksum" ]; then
echo "File change detected..."
if grep -i Smartcitizen "$watched_files" ; then
echo "Found SmartCitizen..."
sleep 2
echo "Getting firmware version..."
cd ..
firmVer=$(python tools/get_info.py --sam --esp)
sam_firmVer=$(echo $firmVer | head -n 1 | cut -c 7-13)
esp_firmVer=$(echo $firmVer | tail -n 1 | cut -c 7-13)
echo "SAM firmware version: "$sam_firmVer
echo "ESP firmware version: "$esp_firmVer
currentVer=$(git rev-parse HEAD | cut -c 1-7)
echo "Firmware latest version: "$currentVer
if [ "$sam_firmVer" != "$currentVer" ]; then
echo "Flashing SAM..."
python make.py flash sam -v
sleep 5
fi
if [ "$esp_firmVer" != "$currentVer" ]; then
echo "Flashing ESP..."
python make.py flash esp -v
sleep 5
fi
#Only need to execute if option is present
if test "$2" = "--co2"; then
echo "CO2..."
python tools/co2.py -v --margin 10 --stab-time 300
case "$OSTYPE" in
darwin*) osascript -e 'display notification "CO2 sensor done!" with title "Smart Citizen"' ;;
linux*) echo "Not yet!" ;;
esac
fi
cd tools/
echo "Done for this kit!"
case "$OSTYPE" in
darwin*) osascript -e 'display notification "SCK done!" with title "Smart Citizen"' ;;
linux*) echo "Not yet!" ;;
esac
fi
fi
previous_checksum="$checksum"
sleep 1
done