-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws-run
115 lines (101 loc) · 2.69 KB
/
ws-run
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# WildlifeSystems
#
# This script is part of the WildlifeSystems project. For further information
# please refer to https://docs.wildlife.systems, or for more information on
# the project itself, please refer to https://wildlife.systems.
# Return codes
#
# Further information on WildlifeSystems standard reurn codes can be found
# at https://docs.wildlife.systems/return-codes.html
# 0 - Success
# 1 - Already running
# 11 - Incorrect filename pattern
#Check if this script already running
if [[ "$(pgrep -c ws-run)" -gt 1 ]]; then
exit 1
fi
#Config
CONFIG=$(cat /home/pi/.ws.conf)
COUNTDOWN=5
FNTYPE=$(echo "$CONFIG" | jq -r '.init .filenaming')
function onOff {
pi-pwr off $(echo "$CONFIG" | jq -r '.init .off[]' | tr '\n' ' ')
pi-pwr on $(echo "$CONFIG" | jq -r '.init .on[]' | tr '\n' ' ')
}
if [[ "$1" != "cron" ]]; then
#Send heartbeat message
ws-heartbeat countdown&
#Indicate countdown and heartbeat
echo Preparing to run...
ws-indicate countdown $COUNTDOWN
ws-indicate heartbeat &
fi
while true;
do
case $FNTYPE in
timestamp)
FN=$(date +%s)
;;
*)
echo "Incorrect filename pattern"
exit 11;
;;
esac
N=$(echo "$CONFIG" | jq -r ".run | length")
I=0
while [ $I -lt $N ];
do
pi-pwr off $(echo "$CONFIG" | jq -r ".run[$I] .off[]" | tr '\n' ' ')
pi-pwr on $(echo "$CONFIG" | jq -r ".run[$I] .on[]" | tr '\n' ' ')
ACTION=`echo $CONFIG| jq -r ".run[$I] .action"`
echo $ACTION
ws-heartbeat $ACTION &
case $ACTION in
record)
DURATION=`echo $CONFIG| jq -r ".run[$I] .duration"`
CHANNELS=`echo $CONFIG| jq -r ".run[$I] .channels"`
BITRATE=`echo $CONFIG| jq -r ".run[$I] .bitrate"`
FORMAT=`echo $CONFIG| jq -r ".run[$I] .format"`
ws-indicate record "arecord -c $CHANNELS -r $BITRATE -f $FORMAT -d $DURATION $FN.wav"
;;
sleep)
sleep `echo $CONFIG| jq -r ".run[$I] .duration"`
;;
upload)
;;
upload-delete)
METHOD=`echo $CONFIG| jq -r ".run[$I] .method"`
UPPATH=`echo $CONFIG| jq -r ".run[$I] .path"`
EXTENSION=`echo $CONFIG| jq -r ".run[$I] .extension"`
ASYNC=`echo $CONFIG| jq -r ".run[$I] .async"`
case $METHOD in
s3cmd)
S3UP=`eval echo "s3cmd put $FN.$EXTENSION s3://$UPPATH"`
S3UP="$S3UP && rm $FN.$EXTENSION"
if [[ "$ASYNC" == "true" ]]; then
S3UP="( $S3UP )&";
fi
eval $S3UP
;;
mv)
MVUP=`eval echo "mv $FN.$EXTENSION $UPPATH"`
if [[ "$ASYNC" == "true" ]]; then
MVUP="( $MVUP )&";
fi
eval $MVUP
;;
esac
;;
clearup)
;;
esac
I=$(($I + 1))
ws-indicate heartbeat
onOff
done
#Exit after one iteration if called form cron
if [[ "$1" == "cron" ]]; then
exit 0
fi
done