forked from BrowserBox/BrowserBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparec-server.sh
executable file
·122 lines (97 loc) · 2.83 KB
/
parec-server.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
#!/usr/bin/env bash
echo "starting audio service..."
command -v pulseaudio &>/dev/null;
export PULSE_INSTALLED=$?
function finish {
echo "Shutting down PA"
if [ $PULSE_INSTALLED -eq 0 ]; then
pulseaudio -k
fi
}
trap finish EXIT
get_install_dir() {
# Find potential directories containing .bbpro_install_dir
pwd="$(pwd)"
install_path1=$(find "$pwd" -name .bbpro_install_dir -print 2>/dev/null)
# Loop through each found path to check if node_modules also exists in the same directory
IFS=$'\n' # Change Internal Field Separator to newline for iteration
for path in "$install_path1"; do
dir="$(dirname $path)"
if [ -d "$dir/node_modules" ]; then
echo "$dir"
return 0
fi
done
install_path2=$(find "$HOME" -name .bbpro_install_dir -print 2>/dev/null)
IFS=$'\n' # Change Internal Field Separator to newline for iteration
for path in "$install_path2"; do
dir=$(dirname $path)
if [ -d "$dir/node_modules" ]; then
echo "$dir"
return 0
fi
done
echo "No valid install directory found."
return 1
}
echo "Finding bbpro installation..."
INSTALL_DIR=$(get_install_dir)
echo "Found bbpro at: $INSTALL_DIR"
echo "starting nvm"
unset npm_config_prefix
cd "$HOME"
source "${HOME}/.nvm/nvm.sh"
source $1
node="$(command -v node)"
username=$(whoami)
let "audio_port = $APP_PORT - 2"
if [[ -z "${TRACE_WARNINGS}" ]]; then
traceOptions="--trace-warnings"
else
traceOptions=""
fi
cd "${INSTALL_DIR}/src/services/instance/parec-server"
PLATFORM_IS=$("$node" -p process.platform)
echo "Using node" $("$node" --version)
echo "Will run audio on port" $audio_port
if [[ $PLATFORM_IS == win* ]]; then
echo "Windows detected. Not running linux and macos steps..."
else
echo "User id" $UID
users_gid=$(sudo id -g $UID | xargs)
rgid=$(ps -o rgid -p $$ | tail -n +2 | xargs)
PidFile=/run/user/$UID/pulse/pid
PidFileGroup=$HOME/.config/pulse/$(hostname)-runtime/pid
echo "Real GID" $rgid
echo "User GID" $users_gid
if [ $users_gid -eq $rgid ] && [ -f $PidFile ]; then
pidFile=$PidFile
else
pidFile=$PidFileGroup
fi
echo "Pid File" $pidFile
if [[ -z "${RENICE_VALUE}" ]]; then
reniceValue=-15
else
reniceValue=$RENICE_VALUE
fi
if [ $PULSE_INSTALLED -eq 0 ]; then
echo "Starting pulseaudio (PID file: $pidFile)"
if pulseaudio --check; then
echo "pulse is started already"
echo "Not shutting pulse down"
#pulseaudio -k
else
pulseaudio --start --use-pid-file=true --log-level=debug
until pulseaudio --check
do
sleep 2
done
fi
fi
pa_pid=$(cat $pidFile || pgrep pulseaudio)
sudo renice -n $reniceValue -p $pa_pid
echo "Pulseaudio (pid: $pa_pid) is reniced to priority $reniceValue"
fi
echo "Starting parec-server"
"$node" $traceOptions index.js $audio_port rtp.monitor $COOKIE_VALUE $LOGIN_TOKEN