-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathinit
executable file
·83 lines (71 loc) · 2.87 KB
/
init
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
#!/bin/bash
# Copyright (C) 2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
source /opt/bootstrap/functions
export CONSOLE_OUTPUT="/dev/console"
kernel_params=$(cat /proc/cmdline)
if [[ $kernel_params = *"bootstrap="* ]]; then
tmp="${kernel_params##*bootstrap=}"
param_bootstrap="${tmp%% *}"
else
clear
echo "" 2>&1 | tee -a ${CONSOLE_OUTPUT}
echo "[ ] 'bootstrap' kernel parameter missing!" 2>&1 | tee -a ${CONSOLE_OUTPUT}
sleep 30
# reboot
fi
if [[ $kernel_params = *"httpserver="* ]]; then
tmp="${kernel_params##*httpserver=}"
param_httpserver="${tmp%% *}"
else
clear
echo "" 2>&1 | tee -a ${CONSOLE_OUTPUT}
echo "[ ] 'httpserver' kernel parameter missing!" 2>&1 | tee -a ${CONSOLE_OUTPUT}
sleep 30
# reboot
fi
if [[ $kernel_params = *"proxy="* ]]; then
tmp="${kernel_params##*proxy=}"
param_proxy="${tmp%% *}"
export http_proxy=${param_proxy}
export https_proxy=${param_proxy}
export no_proxy="localhost,127.0.0.1,${param_httpserver}"
export HTTP_PROXY=${param_proxy}
export HTTPS_PROXY=${param_proxy}
export NO_PROXY="localhost,127.0.0.1,${param_httpserver}"
fi
if [[ $kernel_params = *"token="* ]]; then
tmp="${kernel_params##*token=}"
param_token="${tmp%% *}"
fi
if [ "$(ip route show 0.0.0.0/0 | awk '{print $5}')" == "" ]; then
echo "" 2>&1 | tee -a ${CONSOLE_OUTPUT}
echo "No routable network interface found." 2>&1 | tee -a ${CONSOLE_OUTPUT}
echo -e "Routes:\n$(ip route show)\n\nLANs:\n$(ip -o -4 addr list)\n" 2>&1 | tee -a ${CONSOLE_OUTPUT}
if [ -d "/sys/class/ieee80211" ]; then
if [ -f /opt/bootstrap/init.done ]; then
rm /opt/bootstrap/init.done
fi
touch /opt/bootstrap/wifi-scan.run
until [ -f /opt/bootstrap/wifi-scan.done ]; do
echo "[ ] Waiting for wifi-scan to finish."
sleep 5
done
fi
fi
touch /opt/bootstrap/init.done
if [ "$(ip route show 0.0.0.0/0 | awk '{print $5}')" != "" ]; then
if [ $( nc -vz ${param_httpserver} 80; echo $?; ) -ne 0 ] && [ $( nc -vz ${param_httpserver} 443; echo $?; ) -ne 0 ]; then
echo "Unable to connect to ${param_httpserver} and the network is up. Verify the service is up and running." 2>&1 | tee -a ${CONSOLE_OUTPUT}
echo "" 2>&1 | tee -a ${CONSOLE_OUTPUT}
echo -e "IP Address:\n$(ip -o -4 addr list $(ip route show 0.0.0.0/0 | awk '{print $5}') | head -1 | awk '{print $4}' | cut -d/ -f1)\n\nRoutes:\n$(ip route show)\n\nLANs:\n$(ip -o -4 addr list)\n" 2>&1 | tee -a ${CONSOLE_OUTPUT}
else
if [ $( nc -vz ${param_httpserver} 443; echo $?; ) -eq 0 ]; then
wget --no-check-certificate --header "Authorization: token ${param_token}" -O - ${param_bootstrap/http:/https:} 2> ${CONSOLE_OUTPUT} | bash -s - $param_httpserver
else
wget --header "Authorization: token ${param_token}" -O - ${param_bootstrap/https:/http:} 2> ${CONSOLE_OUTPUT} | bash -s - $param_httpserver
fi
fi
else
echo "No routable networks are up." 2>&1 | tee -a ${CONSOLE_OUTPUT}
fi