11#! /bin/bash
22
33NODE_VERSION=$( < " ${SCRIPT_DIR} /../../../NODE_VERSION" )
4- NPM=" ${SCRIPT_DIR} /node/bin/npm"
54
65# Prints the arguments and their descriptions to the console
76function print_usage() {
@@ -32,6 +31,12 @@ function print_usage() {
3231 Other options: stored and passed to the server. All parameters printed once the script values are set.
3332 Command line options might be omitted to run with defaults and it is a good practice to omit specific ones when just starting the TURN or the STUN server alone, not the whole set of scripts.
3433 "
34+ if [[ -d " ${SCRIPT_DIR} /../../dist/" ]]; then
35+ pushd " ${SCRIPT_DIR} /../.."
36+ echo " Server options:"
37+ npm run start -- --help
38+ popd
39+ fi
3540 exit 1
3641}
3742
@@ -70,40 +75,21 @@ function parse_args() {
7075}
7176
7277function check_version() { # current_version #min_version
73- # check if same string
74- if [ -z " $2 " ] || [ " $1 " = " $2 " ]; then
78+ local current=" $1 "
79+ local minimum=" $2 "
80+
81+ # Check if no minimum or both are the same
82+ if [ -z " $minimum " ] || [ " $current " = " $minimum " ]; then
7583 return 0
7684 fi
7785
78- local i current minimum
79-
80- IFS=" ." read -r -a current <<< $1
81- IFS=" ." read -r -a minimum <<< $2
82-
83- # fill empty fields in current with zeros
84- for (( i= ${# current[@]} ; i< ${# minimum[@]} ; i++ ))
85- do
86- current[i]=0
87- done
86+ local ordered=$( printf " %s\n%s\n" " $minimum " " $current " | sort -V | head -n1)
8887
89- for (( i= 0 ; i< ${# current[@]} ; i++ ))
90- do
91- if [[ -z ${minimum[i]} ]]; then
92- # fill empty fields in minimum with zeros
93- minimum[i]=0
94- fi
95-
96- if (( 10 #${current[i]} > 10 #${minimum[i]} )) ; then
97- return 1
98- fi
99-
100- if (( 10 #${current[i]} < 10 #${minimum[i]} )) ; then
101- return 2
102- fi
103- done
104-
105- # if got this far string is the same once we added missing 0
106- return 0
88+ if [ " $ordered " = " $minimum " ]; then
89+ return 1
90+ else
91+ return 2
92+ fi
10793}
10894
10995function check_and_install() { # dep_name #get_version_string #version_min #install_command
@@ -162,15 +148,9 @@ function setup_node() {
162148 # navigate to project root
163149 pushd " ${SCRIPT_DIR} /../../.." > /dev/null
164150
165- # setup the path so we're using our node. required when calling npm
166- PATH=" ${SCRIPT_DIR} /node/bin:$PATH "
167-
168- node_version=" "
169- if [[ -f " ${SCRIPT_DIR} /node/bin/node" ]]; then
170- node_version=$( " ${SCRIPT_DIR} /node/bin/node" --version)
171- fi
151+ local node_version=$( " node" --version)
172152
173- node_url=" "
153+ local node_url=" "
174154 if [ " $( uname) " == " Darwin" ]; then
175155 arch=$( uname -m)
176156 if [[ $arch == x86_64* ]]; then
@@ -184,16 +164,27 @@ function setup_node() {
184164 else
185165 node_url=" https://nodejs.org/dist/$NODE_VERSION /node-$NODE_VERSION -linux-x64.tar.gz"
186166 fi
187- check_and_install " ${SCRIPT_DIR} /node/bin/node" " $node_version " " $NODE_VERSION " " curl $node_url --output node.tar.xz
167+
168+ check_and_install " node" " $node_version " " $NODE_VERSION " " curl $node_url --output node.tar.xz
188169 && tar -xf node.tar.xz
189170 && rm node.tar.xz
190171 && mv node-v*-*-* \" ${SCRIPT_DIR} /node\" "
191172
192- if [ $? -eq 1 ] || [ " $INSTALL_DEPS " == " 1" ]; then
173+ if [ $? -eq 1 ]; then
174+ # installed node, point PATH to it
175+ PATH=" ${SCRIPT_DIR} /node/bin:$PATH "
176+ fi
177+
178+ # if node_modules doesnt exist or the package-lock file is newer than node_modules, install deps
179+ if [ ! -d node_modules ] || [ ../package-lock.json -nt node_modules ] || [ " $INSTALL_DEPS " == " 1" ]; then
193180 echo " Installing dependencies..."
194- " ${NPM} " install
181+ npm install
195182 fi
196183
184+ # log node version for audits
185+ echo " Using node version: $( node --version) "
186+ echo " Using NPM version: $( npm --version) "
187+
197188 popd > /dev/null
198189}
199190
@@ -203,14 +194,14 @@ function setup_libraries() {
203194 if [ ! -d " ${SCRIPT_DIR} /../../../Common/dist/" ] || [ " $BUILD_LIBRARIES " == " 1" ]; then
204195 pushd " ${SCRIPT_DIR} /../../../Common" > /dev/null
205196 echo " Building common library."
206- " ${NPM} " run build:cjs
197+ npm run build:cjs
207198 popd > /dev/null
208199 fi
209200
210201 if [ ! -d " ${SCRIPT_DIR} /../../../Signalling/dist/" ] || [ " $BUILD_LIBRARIES " == " 1" ]; then
211202 pushd " ${SCRIPT_DIR} /../../../Signalling" > /dev/null
212203 echo " Building signalling library."
213- " ${NPM} " run build:cjs
204+ npm run build:cjs
214205 popd > /dev/null
215206 fi
216207
@@ -236,13 +227,13 @@ function setup_frontend() {
236227 echo " Building Typescript Frontend."
237228 # Using our bundled NodeJS, build the web frontend files
238229 pushd " ${SCRIPT_DIR} /../../../Frontend/library" > /dev/null
239- " ${NPM} " run build:cjs
230+ npm run build:cjs
240231 popd > /dev/null
241232 pushd " ${SCRIPT_DIR} /../../../Frontend/ui-library" > /dev/null
242- " ${NPM} " run build:cjs
233+ npm run build:cjs
243234 popd > /dev/null
244235 pushd " ${SCRIPT_DIR} /../../../Frontend/implementations/typescript" > /dev/null
245- " ${NPM} " run build:dev
236+ npm run build:dev
246237 popd > /dev/null
247238 else
248239 echo ' Skipping building Frontend because files already exist. Please run with "--build" to force a rebuild'
@@ -366,27 +357,25 @@ function start_process() {
366357
367358# Assumes the following are set
368359# SCRIPT_DIR = The path to the platform_scripts
369- # NPM = The npm command path
370360function build_wilbur() {
371361 if [ ! -d " ${SCRIPT_DIR} /../../dist" ] || [ " $BUILD_WILBUR " == " 1" ] ; then
372362 pushd " ${SCRIPT_DIR} /../.." > /dev/null
373363 echo Building wilbur
374- " ${NPM} " run build
364+ npm run build
375365 popd > /dev/null
376366 fi
377367}
378368
379369# Assumes the following are set
380370# SCRIPT_DIR = The path to the platform_scripts
381- # NPM = The npm command path
382371# SERVER_ARGS The arguments to be passed to the server
383372function start_wilbur() {
384373 pushd " ${SCRIPT_DIR} /../../../SignallingWebServer" > /dev/null
385374
386375 echo " Starting wilbur signalling server use ctrl-c to exit"
387376 echo " ----------------------------------"
388377
389- start_process " sudo PATH= \" $PATH \" \" $NPM \" start -- ${SERVER_ARGS} "
378+ start_process " sudo env \" PATH= $PATH \" npm start -- ${SERVER_ARGS} "
390379
391380 popd > /dev/null
392381}
0 commit comments