-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.sh
executable file
·191 lines (153 loc) · 4.54 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
#!/usr/bin/env bash
BASE=$(dirname $(readlink -f $0))
function die(){ warn $*; exit 1; }
function warn(){ echo $* >&2; }
[ -f "$BASE/config.sh" ] && source "$BASE/config.sh"
[ -z "$NFSHOST" ] && die variable NFSHOST not defined
export NFSPREFIX=${NFSPREFIX:-$BASE/pixie}
export BASE_SYSTEMS_rel=systems
export MIRROR=${MIRROR:-http://mirrors.kernel.org/ubuntu}
export BASE_SYSTEMS=$NFSPREFIX/$BASE_SYSTEMS_rel
export BASEURL_NFS=$NFSHOST:$NFSPREFIX
export BASEURL_HTTP=http://$NFSHOST/
export CONFIG=$NFSPREFIX/pxelinux.cfg/default
export CONFIG_IPXE=bootstrap.ipxe.0
export FILE_CONFIG_IPXE=$NFSPREFIX/$CONFIG_IPXE
export DIR_RECIPES=${DIR_RECIPES:-$BASE/recipes/}
export DIR_INTEGRATIONS=${DIR_INTEGRATIONS:-$BASE/integrations/}
mkdir -p $BASE_SYSTEMS
step_integrate(){
local integrations=$(ls $DIR_INTEGRATIONS)
[ -n "$INTEGRATIONS_ENABLED" ] && integrations="$INTEGRATIONS_ENABLED"
for integration in $integrations; do
[ -x "$DIR_INTEGRATIONS/$integration" ] && $DIR_INTEGRATIONS/$integration
done
}
step_system_install(){
local systems=$(ls $DIR_RECIPES)
[ -n "$SYSTEMS_ENABLED" ] && systems="$SYSTEMS_ENABLED"
for system in $systems; do
[ -x "$DIR_RECIPES/$system/recipe" ] && $DIR_RECIPES/$system/recipe install >$BASE_SYSTEMS/$system-install.log 2>&1 &
done
wait
}
step_config_write(){
local systems=$(ls $DIR_RECIPES)
[ -n "$SYSTEMS_ENABLED" ] && systems="$SYSTEMS_ENABLED"
mkdir -p $(dirname $CONFIG)
cat > $CONFIG <<-END
# DO NOT EDIT THIS FILE
#
# this is autogenerated.
#
# look into $NFSPREFIX/setup/ and create there a new entry
DEFAULT menu.c32
ALLOWOPTIONS 1
PROMPT 0
TIMEOUT 0
MENU TITLE BOOT OVER NETWORK
END
for system in $systems; do
[ -x "$DIR_RECIPES/$system/recipe" ] && $DIR_RECIPES/$system/recipe config >> $CONFIG
done
}
step_config_write_iPXE(){
local systems=$(ls $DIR_RECIPES)
[ -n "$SYSTEMS_ENABLED" ] && systems="$SYSTEMS_ENABLED"
mkdir -p $(dirname $FILE_CONFIG_IPXE)
cat > $FILE_CONFIG_IPXE <<-END
#!ipxe
# Figure out if client is 64-bit capable
cpuid --ext 29 && set arch x64 || set arch x86
cpuid --ext 29 && set archl amd64 || set archl i386
###################### MAIN MENU ####################################
:start
menu --name ubu16 Ubuntu 16.04
menu --name ubu14 Ubuntu 14.04
menu --name iso Plain ISO Images
menu Main iPXE boot menu
item --gap -- ------------------------- Groups ------------------------------
item menu-ubu14 Show Ubuntu 14 Menu
item menu-ubu16 Show Ubuntu 16 Menu
item menu-iso Show Plain ISO Images
item --gap -- ------------------------- Operating systems ------------------------------
$(
for system in $systems; do
echo "goto menujump-$system ||"
echo ":backjump-$system"
done
)
item --gap -- ------------------------- Advanced options -------------------------------
item --key c config Configure settings
item shell Drop to iPXE shell
item reboot Reboot computer
item reload Reload config
item
item --key x exit Exit iPXE and continue BIOS boot
choose selected || goto cancel
goto \${selected} || goto failed
:reload
chain ${BASEURL_HTTP}${CONFIG_IPXE} || goto failed
:menu-iso
item --menu iso --key 0x08 back Back to top menu...
choose --menu iso selected || goto start
goto \${selected} || goto :menu-iso
:menu-ubu14
item --menu ubu14 --key 0x08 back Back to top menu...
choose --menu ubu14 selected || goto start
goto \${selected} || goto :menu-ubu14
:menu-ubu16
item --menu ubu16 --key 0x08 back Back to top menu...
choose --menu ubu16 selected || goto start
goto \${selected} || goto :menu-ubu16
:cancel
echo You cancelled the menu, dropping you to a shell
:shell
echo Type 'exit' to get the back to the menu
shell
goto start
:failed
echo Booting failed, dropping to shell
goto shell
:reboot
reboot
:exit
exit
:config
config
goto start
:back
goto start
############ MAIN MENU ITEMS ############
$(
for system in $systems; do
[ -x "$DIR_RECIPES/$system/recipe" ] && $DIR_RECIPES/$system/recipe config_ipxe
done
)
# Go to start if any of these scripts fail badly
goto :start
END
}
case "$1" in
"")
step_system_install
step_config_write
[ "$IPXE_ENABLED" != 0 ] && step_config_write_iPXE
step_integrate
;;
system-install)
step_system_install
step_config_write
[ "$IPXE_ENABLED" != 0 ] && step_config_write_iPXE
;;
config-write)
step_config_write
[ "$IPXE_ENABLED" != 0 ] && step_config_write_iPXE
;;
integrate)
step_integrate
;;
*)
die "Please specify one of the following actions: (integrate|system-install|config-write)"
;;
esac