Repository navigation
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·239 lines (201 loc) · 7.86 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·239 lines (201 loc) · 7.86 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/bash
if [[ -z "$GW_ID" ]]; then
echo "Must provide GW_ID in environment"
exit 1
fi
proxyRegister() {
PAIRING_TIMEOUT=$((PAIRING_CODE_TIMEOUT/GW_PROXY_REG_TIMEOUT))
PAIRING_TIMEOUT=$((GW_PROXY_REG_TIMEOUT*PAIRING_TIMEOUT-4))
resp=$(curl -s -X POST "$GW_PROXY/register" \
-H "Authorization: Bearer $PROXY_TOKEN" \
-H "Content-Type: application/json" \
-d "$(printf '{"gw_id":"%s","gw_ip":"%s","gw_type":"%s", "pairing_code":"%s", "pairing_timeout":"%d"}' \
"$GW_NAME" "$HOST_IP:$GW_API_PORT" "$MAIN_APP" "$PAIRING_CODE" "$PAIRING_TIMEOUT")")
echo "Registration response: $resp" | logParse -p "ProxyRegister"
pairing_code=$(echo "$resp" | jq -r '.pairing_code // empty')
if [[ -n "$pairing_code" ]]; then
# Update /etc/environment with PAIRING_CODE
if grep -q '^PAIRING_CODE=' /etc/environment; then
sudo sed -i "s/^PAIRING_CODE=.*/PAIRING_CODE=\"$pairing_code\"/" /etc/environment
else
echo "PAIRING_CODE=\"$pairing_code\"" | sudo tee -a /etc/environment > /dev/null
fi
. /etc/environment
echo "Pairing code set: $PAIRING_CODE" | logParse -p "ProxyRegister"
fi
}
# If GW_PROXY is set => register the gateway in the Redis Proxy
if [[ -n "$GW_PROXY" && -n "$GW_NAME" ]]; then
echo "Registering gateway $GW_NAME form $HOST_IP type $MAIN_APP at $GW_PROXY" | logParse -p "ProxyRegister"
proxyRegister
(
while true; do
proxyRegister
sleep $GW_PROXY_REG_TIMEOUT
done
) &
fi
if [[ -z "$ROOM_NAME" && "$MAIN_APP" != "baresip" && "$MAIN_APP" != "browser" ]]; then
echo "Must provide ROOM_NAME with $MAIN_APP"
exit 1
fi
if [[ -z "$USER_NAME" && ( "$MAIN_APP" != "baresip" ) ]]; then
USER_NAME=$MAIN_APP
fi
### Init logging ###
HISTORY="/var/logs/gw"$GW_ID"_history"
STATE="/var/logs/gw"$GW_ID"_state"
> $STATE
cleanup() {
echo "Cleaning up..."
### Quit Selenium/Chrome ###
xdotool key ctrl+W
### Quit Baresip ###
echo "/quit" | netcat -q 1 127.0.0.1 5555
sleep 10
killall -SIGINT ffmpeg Xvfb
}
trap 'cleanup | logParse -p "Trap"' SIGINT SIGQUIT SIGTERM EXIT
### Assets download ###
if [[ -n "$ASSETS_URL" ]]; then
wget -qO- "$ASSETS_URL" | tar xvJ -C /var/browsing/assets | logParse -p "Assets"
fi
checkX() {
# 5 seconds timeout before exit
timeOut=5
timer=0
state=$(xdpyinfo -display "$1" >/dev/null 2>&1; echo $?)
while [[ ($state == "1") && ($timer -lt $timeOut) ]]; do
timer=$(($timer + 1))
sleep 1
state=$(xdpyinfo -display "$1" >/dev/null 2>&1; echo $?)
done
if [ $timer -eq $timeOut ]; then
echo "Xvfb $1 failed to launch" | logParse -p "Xvfb"
exit 1
fi
}
checkEventSrv() {
# 5 seconds timeout before exit
timeOut=5
timer=0
state=$(netstat -a | grep :4444 | grep -c LISTEN)
while [[ ($state != "1") && ($timer -lt $timeOut) ]] ; do
timer=$(($timer + 1))
state=$(netstat -a | grep :4444 | grep -c LISTEN)
sleep 1
done
if [ $timer -eq $timeOut ]; then
echo "The gateway failed to launch" | logParse -p "EventSrv"
exit 1
fi
}
envsubst < /var/browsing/assets/config.template.json > /var/browsing/assets/config.json
if [[ "$MAIN_APP" == "recording" && $(ls /var/recording/*.mp4 2>/dev/null) ]]; then
echo "Start recording post-processing" | logParse -p "Recording"
firstRec=$(ls -rt /var/recording/*.mp4 | head -n 1)
DATE_TIME=$(TZ=$TZ stat --format='%W' "$firstRec" | awk '{print strftime("%Y_%m_%d_%H%M", $1)}')
FINAL_VIDEO="RendezVous_$DATE_TIME.mp4"
if [ "$WITH_TRANSCRIPT" == "true" ]; then
python3 /var/transcript/transcript.py 1> >( logParse -p "Transcript") \
2> >( logParse -p "Transcript")
FINAL_TRANSCRIPT="RendezVous_$DATE_TIME.srt"
mv /var/recording/final_transcript.srt "/var/recording/"$FINAL_TRANSCRIPT
fi
# Generate mp4 file list for concatenation
> "/var/recording/segments_list.txt"
for f in /var/recording/segment_*.mp4; do
echo "file '$f'" >> "/var/recording/segments_list.txt"
done
# Concatenate segments into one file
ffmpeg -y -f concat -safe 0 -i "/var/recording/segments_list.txt" -c copy "/var/recording/$FINAL_VIDEO"
rm /var/recording/segment*.mp4
rm /var/recording/segment*.txt
echo "Processing finished : video merged in $FINAL_VIDEO and transcriptions in $FINAL_TRANSCRIPT"
cd /var/recording
{
python3 filesender.py \
-u $FS_USER_MAIL -r $FS_RECIPIENT_MAIL -a $FS_API_KEY \
$FINAL_VIDEO $FINAL_TRANSCRIPT \
1> >( logParse -p "FileSender") \
2> >( logParse -p "FileSender") && \
rm $FINAL_VIDEO $FINAL_TRANSCRIPT && \
echo "Files sent and removed" | logParse -p "FileSender"
} || {
mv $FINAL_VIDEO $FINAL_TRANSCRIPT /var/logs && \
echo "Files moved in log directory" | logParse -p "FileCopy";
}
exit 1
else
echo "start_gw:$(TZ=$TZ date +'%b %d %H:%M:%S')"> $HISTORY
echo "main_app:$MAIN_APP" > $HISTORY
fi
### Configure audio devices ###
if [[ -z "$DISPLAY" ]]; then
if [ -z "${PULSE_SERVER+x}" ] || [ -z "$PULSE_SERVER" ]; then
unset PULSE_SERVER
fi
if [ "$WITH_ALSA" == "true" ]; then
ALSA_DEV='plug:baresip'
HW0=$(( 2*$GW_ID ))
(($HW0)) || HW0=""
HW1=$(( 2*$GW_ID + 1 ))
ALSA_CARD0="Loopback"${HW0:+'_'$HW0}
ALSA_CARD1="Loopback"${HW1:+'_'$HW1}
sed -i 's/Loopback,/'$ALSA_CARD0',/g' /etc/asound.conf
sed -i 's/Loopback_1,/'$ALSA_CARD1',/g' /etc/asound.conf
else
./pulseaudio_init.sh 1> >( logParse -p "Pulse") \
2> >( logParse -p "Pulse")
fi
fi
if [[ "$AUDIO_ONLY" != "true" ]]; then
### Configure video display ###
VID_FPS="30"
PIX_DEPTH="24"
IFS="x" read -r VID_W_APP VID_H_APP <<<$VID_SIZE_APP
VID_WX2_APP=$(( 2*$VID_W_APP ))
mkdir -p /tmp/.X11-unix
sudo chmod 1777 /tmp/.X11-unix
sudo chown root /tmp/.X11-unix/
if [[ -z "$DISPLAY" ]]; then
echo "Display ID, web browser " $DISPLAY_WEB | logParse -p "Xvfb"
Xvfb $DISPLAY_WEB -screen 0 \
$VID_WX2_APP"x"$VID_H_APP"x"$PIX_DEPTH \
+extension RANDR -noreset | logParse -p "Xvfb" &
checkX $DISPLAY_WEB
DISPLAY=$DISPLAY_WEB xrandr --setmonitor screen0 \
$VID_W_APP"/640x"$VID_H_APP"/360+0+0" screen | logParse -p "xrandr"
DISPLAY=$DISPLAY_WEB xrandr --setmonitor screen1 \
$VID_W_APP"/640x"$VID_H_APP"/360+"$VID_W_APP"+0" none | logParse -p "xrandr"
DISPLAY=$DISPLAY_WEB fluxbox | logParse -p "fluxbox" &
DISPLAY=$DISPLAY_WEB unclutter -idle 1 &
else
DISPLAY=$DISPLAY_WEB xrandr -s $VID_SIZE_APP | logParse -p "xrandr"
fi
echo "Display ID, main application " $DISPLAY_APP | logParse -p "Xvfb"
Xvfb $DISPLAY_APP -screen 0 $VID_SIZE_WEBRTC"x"$PIX_DEPTH \
+extension RANDR -noreset| logParse -p "Xvfb" &
checkX $DISPLAY_APP
fi
### Main application ###
if [[ -n "$MAIN_APP" && -f "$MAIN_APP/$MAIN_APP.sh" ]]; then
source "$MAIN_APP/$MAIN_APP.sh"
else
### Event server ###
exec python3 src/eventServer.py 1> >( logParse -p "Event Server") \
2> >( logParse -p "Event Server") &
fi
if [ "$WITH_TRANSCRIPT" == "true" ]; then
exec python3 transcript/transcript.py 1> >( logParse -p "Transcript") \
2> >( logParse -p "Transcript") &
fi
### Check if event server is ready ###
checkEventSrv
### Event handler ###
if [[ -n "$ROOM_NAME" ]]; then
roomParam="-r "$ROOM_NAME
fi
DISPLAY=$DISPLAY_WEB exec python3 src/event_handler.py -s $VID_SIZE_APP \
$roomParam $fromUri \
1> >( logParse -p "Event" -i $HISTORY )