-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsetup.sh
executable file
·214 lines (184 loc) · 6.22 KB
/
setup.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
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
#!/bin/bash
#
# mainmenu - choose which image should be installed
#
# (c) 2007-2016, Hetzner Online GmbH
#
# read global variables and functions
# disable because old shellcheck on travis fails here
# TODO: check in the future
# shellcheck disable=SC1091
. /tmp/install.vars
# check if the script is temporary disabled due some maintenance or something
debug "# checking if the script is disabled"
if [ -f "$DISABLEDFILE" ]; then
debug "=> script is DISABLED"
echo_red 'Due to maintenance the installimage-script is temporarily unavailable.\nWe are sorry for the inconvenience.'
exit 1
fi
if [ "$OPT_AUTOMODE" ] ; then
### automatic mode ------------------------------------------------
debug "# AUTOMATIC MODE: start"
# create config
debug "# AUTOMATIC MODE: create config"
create_config "$IMAGENAME" ; EXITCODE=$?
if [ $EXITCODE != 0 ] ; then
debug "=> FAILED"
exit 1
fi
# validate config
VALIDATED="false"
CANCELLED="false"
while [ "$VALIDATED" = "false" ]; do
debug "# validating config ..."
validate_vars "$FOLD/install.conf"; EXITCODE=$?
if [ "$CANCELLED" = "true" ]; then
echo "Cancelled."
exit 1
fi
if [ $EXITCODE = 0 ]; then
VALIDATED="true"
else
debug "=> FAILED"
mcedit "$FOLD/install.conf"
fi
done
# display information about automatic mode
echo -e '\n\033[01;32mStarting AUTOMATIC MODE\033[00m'
echo -e '\033[01;33mRunning unattended installimage installation ...\033[00m'
echo ""
grep -v "^#" "$FOLD/install.conf" | grep -v "^$"
echo ""
echo ""
# print warning
if [ "$SLEEP_BEFORE_START" -gt 0 ]; then
echo -e '\033[01;31mWARNING:'
echo -e "\\033[01;33m Starting installation in $SLEEP_BEFORE_START seconds ..."
echo -e '\033[01;33m Press X to continue immediately ...\033[00m'
echo -e '\033[01;31m Installation will DELETE ALL DATA ON DISK(s)!'
echo -e '\033[01;33m Press CTRL-C to abort now!\033[00m'
echo -n ' => '
for ((i=0; i<=SLEEP_BEFORE_START; i++)); do
echo -n "."
read -r -t1 -n1 anykey
if [ "$anykey" = "x" ] || [ "$anykey" = "X" ] ; then break ; fi
done
echo
fi
# start install
debug "# AUTOMATIC MODE: start installation"
# shellcheck disable=SC1090
. "$INSTALLFILE" ; EXITCODE=$?
[ $EXITCODE != 0 ] && debug "=> FAILED"
else
### interactive mode ----------------------------------------------
# start the mainmenu and loop while not chosen "exit" or a config and finished configuration
ACCEPTED=""
while [ -z "$ACCEPTED" ]; do
if [ "$OPT_IMAGE" ] ; then
# use image from option, do not display image menu
NOIMAGEMENU=true
else
# display the image menu
IMAGENAME=""
debug "# starting menu..."
debug "$OSMENULIST"
debug "$DIATITLE"
debug "$FOLD"
while [ -z "$IMAGENAME" ] || [ "$IMAGENAME" = "back" ]; do
OLDIFS="$IFS"
IFS=$'\n'
# we want $OSMENULIST to expand here
# shellcheck disable=SC2086
dialog --backtitle "$DIATITLE" --title "o/s list" --no-cancel --menu "choose o/s" 0 0 0 ${OSMENULIST[*]} "exit" "" 2> "$FOLD/mainmenu.chosen"
IFS="$OLDIFS"
MAINMENUCHOSEN=$(cat "$FOLD/mainmenu.chosen")
case "$MAINMENUCHOSEN" in
"exit")
debug "=> user exited from menu"
exit 1
;;
"custom image")
IMAGENAME="custom"
;;
*)
generate_menu "$MAINMENUCHOSEN"
;;
esac
done
fi
debug "# chosen image: [ $IMAGENAME ]"
debug "# copy & create config..."
create_config "$IMAGENAME"; EXITCODE=$?
if [ $EXITCODE != 0 ] ; then
debug "=> FAILED"
exit 1
fi
if [ "$PROXMOX" = "true" ]; then
graph_notice "\\nPlease note: This image isn't supported by us.";
fi
text='\n An editor will now show you the config for the image.\n
You can edit the parameters for your needs.\n
To accept all changes and continue the installation\n
just save and exit the editor with F10.'
[ "$COUNT_DRIVES" -gt 1 ] && text=$text'\n\n\Z1 Please note!: by default all disks are used for software raid\n
change this to (SWRAID 0) if you want to leave your other harddisk(s)\n untouched!\Zn'
dialog --backtitle "$DIATITLE" --title " NOTICE " --colors --msgbox "$text" 14 75
VALIDATED="false"
CANCELLED="false"
while [ "$VALIDATED" = "false" ]; do
debug "# starting mcedit..."
whoami "$IMAGENAME"
mcedit "$FOLD/install.conf"; EXITCODE=$?
[ $EXITCODE != 0 ] && debug "=> FAILED"
debug "# validating vars..."
validate_vars "$FOLD/install.conf"; EXITCODE=$?
if [ $EXITCODE = 0 ]; then
VALIDATED="true"
else
if [ "$CANCELLED" = "true" ]; then
debug "=> CANCELLED"
VALIDATED="true"
else
debug "=> FAILED"
fi
fi
done
if [ "$LVM" = "1" ]; then
graph_notice "Please note that ALL existing LVs and VGs will be removed during the installation!"
fi
if [ "$CANCELLED" = "false" ]; then
debug "# asking for confirmation..."
for i in $(seq 1 "$COUNT_DRIVES") ; do
ask_format="$(eval echo "\$FORMAT_DRIVE$i")"
ask_drive="$(eval echo "\$DRIVE$i")"
if [ "$SWRAID" = "1" ] || [ "$ask_format" = "1" ] || [ "$i" -eq 1 ]; then
if dialog --backtitle "$DIATITLE" --title "Confirmation" --colors --yesno "\\n\\Z1WARNING!: DATA ON THE FOLLOWING DRIVE WILL BE DELETED:\\n\\n $ask_drive\\n\\nDo you want to continue?\\Zn\\n" 0 0; then
debug "# Confirmation for drive $ask_drive accepted"
ACCEPTED="true"
else
debug "# Confirmation for drive $ask_drive NOT accepted"
ACCEPTED=""
if [ "$NOIMAGEMENU" ]; then
exit
else
break
fi
fi
fi
done
fi
done
debug "# executing installfile..."
if [ -f "$INSTALLFILE" ] && [ "$ACCEPTED" = "true" ] && [ "$VALIDATED" = "true" ] && [ "$IMAGENAME" ] ; then
# shellcheck disable=SC1090
. "$INSTALLFILE" ; EXITCODE=$?
else
debug "=> FAILED"
echo -e '\n\033[01;31mERROR: Cant find files\033[00m'
fi
fi
if [ "$EXITCODE" = "1" ]; then
exit 1
fi
# vim: ai:ts=2:sw=2:et