-
Notifications
You must be signed in to change notification settings - Fork 64
/
run-start.sh
executable file
·168 lines (156 loc) · 5.58 KB
/
run-start.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
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
#!/bin/bash
# use bash instead of sh
# get the folder for this file
DIR=$(dirname "$0")
# make sure we are running in that folder
cd "$DIR" >/dev/null
# check for the old untrack css script
[ -f ./untrack-css.sh ] && ./untrack-css.sh
# if running under docker
if grep docker /proc/1/cgroup -qa; then
# only start electron
electron js/electron.js $1;
else
# not running in docker
if [ -z "$DISPLAY" ]; then #If not set DISPLAY is SSH remote or tty
export DISPLAY=:0 # Set by default display
fi
# get the processor architecture
arch=$(uname -m)
false='false'
true='true'
# get the config option, if any
# only check non comment lines
serveronly=$(grep -v '^[[:blank:]]*//' config/config.js | grep -i serveronly: | tr -d ',"'\''\r' | tr -d ' ' | awk -F/ '{print $1}' | awk -F: '{print $2}')
# set default if not defined in config
serveronly=${serveronly:-false}
# check for xwindows running
while [ 1 -eq 1 ];
do
xorg=$(pgrep Xorg)
if [ "$xorg." == "." ]; then
# check for x on Lubuntu
xorg=$(pgrep X)
fi
# if user set wait_for_x to some value (ANY value)
if [ "$wait_for_x." != "." ]; then
if [ "$xorg." != "." ]; then
# then break from loop
break;
else
# sleep for 1 second
sleep 1
fi
else
# exit loop, not waiting, default
break;
fi
done
#check for macOS
mac=$(uname)
el_installed=$true
if [ ! -d node_modules/electron ]; then
el_installed=$false
fi
#
# if the user requested serveronly OR
# electron support for armv6l has been dropped OR
# system is in text mode
#
if [ "$serveronly." != "$false." -o "$arch" == "armv6l" -o "$arch" == "i686" -o $el_installed == $false ] || [ "$xorg." == "." -a $mac != 'Darwin' -a "$wait_for_x." != "." ]; then
t=$(ps -ef | grep "node serveronly" | grep -m1 -v color | awk '{print $2}')
if [ "$t." != '.' ]; then
sudo kill -9 $t >/dev/null 2>&1
fi
# if user explicitly configured to run server only (no ui local)
# OR there is no xwindows running, so no support for browser graphics
if [ "$serveronly." == "$true." ] || [ "$xorg." == "." -a $mac != 'Darwin' -a "$wait_for_x." != "." ]; then
# start server mode,
node serveronly
else
# start the server in the background
# wait for server to be ready
# need bash for this
exec 3< <(node serveronly)
# Read the output of server line by line until one line 'point your browser'
while read line; do
case "$line" in
*point\ your\ browser*)
echo $line
break
;;
*)
echo $line
#sleep .25
;;
esac
done <&3
# Close the file descriptor
#exec 3<&-
# lets use chrome to display here now
# get the server port address from the ready message
port=$(echo $line | awk -F\: '{print $4}')
# start chromium
# echo "Starting chromium browser now, have patience, it takes a minute"
# continue to spool stdout to console
tee <&3 &
if [ "$external_browser." == "." ]; then
# start chromium
echo "Starting chromium browser now, have patience, it takes a minute"
if [ $mac != 'Darwin' ]; then
b="chromium"
if [ $(which $b). == '.' -o $arch == 'armv6l' ]; then
b='chromium-browser'
fi
if [ $(which $b). != '.' ]; then
rm -rf ~/.config/$b 2>/dev/null
r=$(mktemp -d "${TMPDIR:-/tmp}"/tmp.XXXXXXXX)
"$b" -noerrdialogs -kiosk -start_maximized --new-window --site-per-process --no-zygote --no-sandbox --disable-infobars --app=http://localhost:$port --ignore-certificate-errors-spki-list --ignore-ssl-errors --ignore-certificate-errors --user-data-dir=$r 2>/dev/null
rm -rf $r >/dev/null
else
echo "Chromium_browser not installed"
# if we can't start chrome,
# get the server process id
ns=$(ps -ef | grep "node serveronly" | grep -m1 -v color | awk '{print $2}')
# if we have the process id
if [ "$ns". != "." ]; then
# kill server for restart
sudo kill -9 $ns >/dev/null 2>&1
fi
fi
else
open -a "Google Chrome" http://localhost:$port --args -noerrdialogs -kiosk -start_maximized --disable-infobars --ignore-certificate-errors-spki-list --ignore-ssl-errors --ignore-certificate-errors 2>/dev/null
fi
else
# if the external browser was specified
if [ "$(which $external_browser)." != "." ]; then
# launch it
case ${external_browser,,} in
midori )
# start midori
echo "Starting $external_browser browser now, have patience, it takes a minute"
"$external_browser" http://localhost:$port -e Fullscreen -e Navigationbar >/dev/null 2>&1
;;
firefox )
# start firefox
"$external_browser" http://localhost:$port -kiosk >/dev/null 2>&1
;;
surf )
# start surf
"$external_browser" -F http://localhost:$port >/dev/null 2>&1
;;
* )
#else
echo "don't know how to launch $external_browser"
esac
else
echo "couldn't locate $external_browser from the command shell,. check the PATH environment variable"
fi
fi
exit
fi
else
# we can use electron directly
node_modules/.bin/electron js/electron.js $1;
fi
fi