-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathentrypoint.sh
executable file
·139 lines (118 loc) · 3.94 KB
/
entrypoint.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
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
#!/bin/bash
if [[ -z "$GW_ID" ]]; then
echo "Must provide GW_ID in environment"
exit 1
fi
### Init logging ###
HISTORY="/var/logs/gw"$GW_ID"_history"
STATE="/var/logs/gw"$GW_ID"_state"
touch $STATE
echo "start_gw:$(date +'%b %d %H:%M:%S')"> $HISTORY
cleanup() {
echo "Cleaning up..."
### Quit Selenium/Chrome ###
DISPLAY=:${SERVERNUM0} 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
check_Xvfb() {
# 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
}
check_v4l2() {
# 5 seconds timeout before exit
timeOut=5
timer=0
state=$(grep -q $1 $STATE; echo $?)
while [[ ($state == "1") && ($timer -lt $timeOut) ]]; do
timer=$(($timer + 1))
sleep 1
state=$(grep -q $1 $STATE; echo $?)
done
if [ $timer -eq $timeOut ]; then
echo "V4l2 loopback failed to launch" | logParse -p "V4l2"
exit 1
fi
}
if [ "$MAIN_APP" == "recording" ]; then
for file in /var/recording/*.mp4; do
if [ -f "$file" ]; then
echo "Send and remove file: "$file | logParse -p "FileSender"
exec python3 /var/recording/filesender.py \
-u $USER_MAIL -r $USER_MAIL -a $API_KEY $file \
1> >( logParse -p "FileSender") \
2> >( logParse -p "FileSender")
rm "$file"
fi
done
if [ -f "$file" ]; then
exit 1
fi
fi
### Configure audio devices ###
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
### Configure video display ###
VID_FPS="30"
PIX_DEPTH="24"
IFS="x" read -r VID_W_SIP VID_H_SIP <<<$VID_SIZE_APP
VID_WX2_SIP=$(( 2*$VID_W_SIP ))
mkdir -p /tmp/.X11-unix
sudo chmod 1777 /tmp/.X11-unix
sudo chown root /tmp/.X11-unix/
SERVERNUM0=99
echo "Server 0 Number= " $SERVERNUM0 | logParse -p "Xvfb"
Xvfb :$SERVERNUM0 -screen 0 \
$VID_WX2_SIP"x"$VID_H_SIP"x"$PIX_DEPTH \
+extension RANDR -noreset | logParse -p "Xvfb" &
SERVERNUM1=100
echo "Server 1 Number= " $SERVERNUM1 | logParse -p "Xvfb"
Xvfb :$SERVERNUM1 -screen 0 $VID_SIZE_WEBRTC"x"$PIX_DEPTH \
+extension RANDR -noreset| logParse -p "Xvfb" &
### Check if Xvfb server is ready ###
check_Xvfb $SERVERNUM0
check_Xvfb $SERVERNUM1
DISPLAY=:$SERVERNUM0 xrandr --setmonitor screen0 \
$VID_W_SIP"/640x"$VID_H_SIP"/360+0+0" screen | logParse -p "xrandr"
DISPLAY=:$SERVERNUM0 xrandr --setmonitor screen1 \
$VID_W_SIP"/640x"$VID_H_SIP"/360+"$VID_W_SIP"+0" none | logParse -p "xrandr"
DISPLAY=:$SERVERNUM0 fluxbox | logParse -p "fluxbox" &
DISPLAY=:$SERVERNUM0 unclutter -idle 1 &
### Main application ###
source $MAIN_APP"/"$MAIN_APP".sh"
### Check if video device is ready ###
check_v4l2 "/dev/video0"
### Event handler ###
if [[ -n "$ROOM_NAME" ]]; then
roomParam="-r "$ROOM_NAME
fi
cp "./browsing/"$BROWSE_FILE src
DISPLAY=:$SERVERNUM0 exec python3 src/event_handler.py -b `pwd`"/browsing/"$BROWSE_FILE \
-s $VID_SIZE_APP \
$roomParam $fromUri \
1> >( logParse -p "Event" -i $HISTORY )