-
Notifications
You must be signed in to change notification settings - Fork 337
/
run-app.sh
executable file
·76 lines (60 loc) · 1.53 KB
/
run-app.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
#!/bin/bash
set -e -x
WEBTHINGS_HOME="${WEBTHINGS_HOME:=${HOME}/.webthings}"
args=""
start_task="run-only"
is_container() {
if [ -f /.dockerenv ]; then
return 0
fi
if [ -f /run/.containerenv ]; then
return 0
fi
if grep -q ':\/docker\/' /proc/1/cgroup 2>&1; then
return 0
fi
if [ -d /pantavisor ]; then
return 0
fi
return 1
}
run_app() {
# load nvm
export NVM_DIR="${HOME}/.nvm"
[ ! -s "${NVM_DIR}/nvm.sh" ] || \. "${NVM_DIR}/nvm.sh"
if [ ! is_container ]; then
sudo /sbin/ldconfig
(sudo timedatectl set-local-rtc 0 && sudo timedatectl set-ntp 1) || true
fi
echo "node version"
node --version
echo "npm version"
npm --version
echo "Starting gateway ..."
npm run "${start_task}" -- $args
}
if ! is_container; then
if [ ! -f .post_upgrade_complete ]; then
./tools/post-upgrade.sh
fi
else
_node_version=$(node --version | egrep -o '[0-9]+' | head -n1)
if [[ ! -f "${WEBTHINGS_HOME}/.node_version" ||
"$(< "${WEBTHINGS_HOME}/.node_version")" != "${_node_version}" ]]; then
cd "${HOME}/webthings/gateway"
mkdir -p "${WEBTHINGS_HOME}/config"
./tools/update-addons.sh
cd -
echo "${_node_version}" > "${WEBTHINGS_HOME}/.node_version"
fi
fi
if [[ "$WEBTHINGS_HOME" == "$HOME/.webthings" &&
-d "$HOME/.mozilla-iot" &&
! -e "$HOME/.webthings" ]]; then
mv "$HOME/.mozilla-iot" "$HOME/.webthings"
fi
mkdir -p "${WEBTHINGS_HOME}/log"
if [ -f "${WEBTHINGS_HOME}/log/run-app.log" ]; then
rm -f "${WEBTHINGS_HOME}/log/run-app.log"
fi
run_app