This repository has been archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
start-trident-installer
executable file
·233 lines (213 loc) · 5.75 KB
/
start-trident-installer
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash
INSTALLER="/bin/trident-installer"
TITLE="Project Trident Installer"
LOGFILE="/tmp/install.log"
echo "Launching Installer..."
get_dlg_ans(){
# INPUTS:
# TITLE: Title to use for the dialog
# CLI Args : Arguments for dialog (option_name, option_text, repeat...)
# OUTPUTS:
# ANS: option_name selected by user
local TANS="/tmp/.dlg.ans.$$"
if [ -e "$TANS" ] ; then rm ${TANS}; fi
if [ -e "$TANS.dlg" ] ; then rm ${TANS}.dlg; fi
while :
do
echo "dialog --title \"$TITLE\" ${@}" >${TANS}.dlg
sh ${TANS}.dlg 2>${TANS}
local _ret=$?
if [ $_ret -ne 0 ] || [ ! -e "$TANS" ] ; then
#echo "Cancel detected : ${CURMENU} ${_ret}"
#sleep 1
rm ${TANS} 2>/dev/null
fi
if [ ! -e "$TANS" ] ; then
ANS=""
else
ANS=`cat ${TANS}`
rm ${TANS}
fi
#echo "Got Ans: ${ANS}"
#sleep 2
rm ${TANS}.dlg
return ${_ret}
done
}
getPassword(){
TMP="1"
TMP2="2"
while [ "${TMP}" != "${TMP2}" ]
do
get_dlg_ans "--passwordbox \"Enter password for ${1}\n(Note: Hidden Text)\" 0 0"
TMP="${ANS}"
get_dlg_ans "--passwordbox \"Repeat password for ${1}\" 0 0"
TMP2="${ANS}"
done
ANS="${TMP}"
unset TMP
unset TMP2
}
PingTest(){
#echo "Checking for network connection..."
ping -q -c 1 -W 2 github.com > /dev/null 2> /dev/null
return $?
}
GetWifiDevice(){
# exports "WIFIDEV" variable with name of wifi
local _devs=`ip link | grep "UP" | grep ": wl" | cut -d : -f 2`
num=`echo "${_devs}" | wc -w`
if [ ${num} -lt 1 ] ; then
#No wifi devices available
get_dlg_ans "--msgbox \"ERROR : No wireless devices available!\n\nManual setup via the terminal may be required for this system.\" 0 0"
WIFIDEV=""
elif [ ${num} -eq 1 ] ; then
#exactly 1 wifi device - use it
WIFIDEV="${_devs}"
else
#More than 1 wifi device: ask user to pick one
opts=""
for dev in ${_devs}
do
opts="${opts} ${dev} \"\""
done
get_dlg_ans "--menu \"Select a wireless device to scan for networks\" 0 0 0 ${opts}"
WIFIDEV="${ANS}"
fi
#Make sure to remove any whitespace in the device variable before we are done
WIFIDEV=`echo "${WIFIDEV}" | tr -d '[:space:]'`
}
GetWifiSSID(){
wpa_cli -i${WIFIDEV} scan > /dev/null
results=`wpa_cli -i${WIFIDEV} scan_results`
opts=""
opts=$(wpa_cli -i${WIFIDEV} scan_results | grep -v "bssid / " | while read _line
do
echo -n " $(echo $_line | rev | cut -d ' ' -f 1 | rev) \"$(echo $_line | cut -d ' ' -f 1)\""
done )
get_dlg_ans "--menu \" \" 0 0 0 Rescan \"\" ${opts}"
}
SetupWifi(){
GetWifiDevice
if [ -z "${WIFIDEV}" ] ; then
#No wifi or cancelled
return
fi
#generate the SSID list
GetWifiSSID
while [ "${ANS}" = "Rescan" ]
do
GetWifiSSID
done
if [ -z "${ANS}" ] ; then
#No wifi or cancelled
return
fi
local SSID="${ANS}"
getPassword " ${SSID} access point"
wpa_passphrase "${SSID}" "${ANS}" | grep -v "#psk" >> "/etc/wpa_supplicant/wpa_supplicant.conf"
sv restart wpa_supplicant
sleep 1
}
ViewLog(){
get_dlg_ans "--textbox ${LOGFILE} 0 0"
ANS="dummy"
}
InstallSuccessful(){
if [ ! -e "${LOGFILE}" ] ; then return 1 ; fi
grep -q "[SUCCESS] " "${LOGFILE}"
return $?
}
StartInstall(){
PingTest
if [ $? -ne 0 ] ; then
get_dlg_ans "--msgbox \"Networking not available. Please configure it first!\" 0 0"
ANS="dummy"
return 0
fi
# Now download the latest install script
if [ ! -e "${INSTALLER}" ] || [ "${1}" = "-f" ] ; then
if [ -e "${INSTALLER}" ] ; then rm "${INSTALLER}" ; fi
wget https://raw.githubusercontent.com/project-trident/trident-installer/master/src-sh/void-install-zfs.sh -O "${INSTALLER}"
chmod 755 "${INSTALLER}"
fi
# And run it
${INSTALLER} "${LOGFILE}"
local msg="Installation Finished"
InstallSuccessful
if [ $? -eq 0 ] ; then
msg="${msg} Successfully!\n\nReboot the system and remove the installation media to boot into the new system."
else
msg="${msg} Unsuccessfully.\n\nPlease view the installation log for details."
fi
get_dlg_ans "--msgbox \"${msg}\" 0 0"
ANS="dummy" #Ensure it returns to the main menu next
}
#Make sure wpa_supplicant service is started
if [ ! -d "/var/service/wpa_supplicant" ] ; then
ln -s "/etc/sv/wpa_supplicant" "/var/service/wpa_supplicant"
sv start wpa_supplicant
fi
get_dlg_ans "--msgbox \"WARNING: This is an ALPHA image of the Void-Linux based system and only assists with setting up a ZFS-on-root installation.\n\n Packages and graphical tools are not setup yet.\n\nwww.project-trident.org\" 0 0"
ANS="anything"
while [ -n "${ANS}" ]
do
#Show the main menu
#Generate info header
info=""
opts=""
InstallSuccessful
if [ $? -eq 0 ] ; then
info="Installation Successful: Ready to reboot"
else
status="OFFLINE"
PingTest
if [ $? -eq 0 ] ; then
status="ONLINE"
info="Ready to begin installation"
opts="Begin \"Start Installation Steps\""
else
info="Networking setup needed"
opts="Configure \"Setup Networking\" Rescan \"Check network status\""
fi
info="${info}\nNetwork Status: ${status}"
fi
#Generate options
if [ -e "${LOGFILE}" ] ; then
opts="${opts} Log \"View installation log\""
fi
opts="${opts} Terminal \"Drop to shell\" Reboot \"\" Poweroff \"\""
#Now prompt and do
get_dlg_ans "--menu \"${info}\n\nSelect an option below:\" 0 0 0 ${opts}"
case "${ANS}" in
Begin)
StartInstall
;;
Log)
ViewLog
;;
Configure)
SetupWifi
ANS="dummy"
;;
Terminal)
clear
echo "Run 'exit' or 'start-trident-installer' to launch the installer again"
echo "---------------------------------------------"
/bin/bash
#ANS=""
;;
Reboot)
reboot
clear
echo "Rebooting system...."
sleep 5
;;
Poweroff)
poweroff
clear
echo "Powering off system...."
sleep 5
;;
esac
done