summaryrefslogtreecommitdiffstats
path: root/data/ipxe-embed.template
blob: 2150ea68f449fd9ccd93f8b5055c527734e911fd (plain) (blame)
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
#!ipxe

console || goto cmd_fail

# This should always be the case since this is the embed script, but making it dynamic is more flexible during testing
set slxtest:string something || goto cmd_fail
iseq \${slxtest:md5} \${} && set slxext 0 || set slxext 1 ||

set dosleep:int32 0 ||
set idx:int32 -1 ||

# This will be set to usb or pxe
#goto %mode%

:PXE

set retlbl:string next_open
:next_open
inc idx
iseq 20 ${idx} && goto retry_sleep ||
echo Now checking if net${idx} is open...
# No MAC -- done
iseq ${net${idx}/mac} ${} && goto retry_sleep ||
echo net${idx} has MACaddr ${net${idx}/mac}
# Has no IP -- ignore
iseq ${net${idx}/ip} ${} && goto cleaniface ||
echo net${idx} has IPaddr ${net${idx}/ip}
ifopen net${idx} || goto cleaniface
# Success
set retlbl dochain
goto setvars

# Now try to chain to main script
:dochain
echo Now chaining to main script
set self:string http://%ipaddress%/boot/ipxe?uuid=${uuid}&mac=${mac}&manuf=${manufacturer:uristring}&product=${product:uristring}&platform=${platform:uristring}&slx-extensions=${slxext}
chain -ar ${self} || goto fail
echo How the hell did I get here?
:fail
echo Failed.
set retlbl retry_sleep
goto cleaniface
:retry_sleep
echo Trying again in ${dosleep} seconds...
sleep ${dosleep} ||
iseq 0 ${dosleep} && set idx:int32 -1 ||
set dosleep 5 ||
:USB
iseq 20 ${idx} && set idx:int32 -1 ||
set retlbl:string next_dhcp
:next_dhcp
inc idx
iseq 20 ${idx} && goto retry_sleep ||
echo Now trying dhcp on net${idx}
# No MAC -- done
iseq ${net${idx}/mac} ${} && goto next_dhcp ||
echo Trying net${idx} via DHCP
dhcp net${idx} || goto cleaniface
# Success
set retlbl dochain
goto setvars

# Clear interface IP address and close it
# Jumps back to label stored in ${retlbl}
:cleaniface
echo Cleaning Interface net${idx}
clear net${idx}/ip ||
clear net${idx}.dhcp/ip ||
ifclose net${idx} ||
goto ${retlbl}

# Force global variables to have the values of the interface we succeeded on
# Jumps back to label stored in ${retlbl}
:setvars
set ip ${net${idx}/ip} ||
set mac ${net${idx}/mac} ||
set netmask ${net${idx}/netmask} ||
set gateway ${net${idx}/gateway} ||
goto ${retlbl}

:cmd_fail
echo This iPXE was compiled with important commands/features missing
echo Essential are: console, menu, param, set, clear
echo Optionally, reboot and poweroff would be nice
prompt Press any key to reboot ||
reboot || echo OK, reboot is apparently missing, so....
prompt Press any key to exit iPXE and return control to the BIOS ||
exit 1