Pre-Processor for iPXE scripting Language
Goto's are considered harmful, and really they are just a pain.
The iPXE scripting language was designed to be as lightweight as possible, and uses goto's extensively, but it looses out on several higher level scripting constructs like IF, WHILE, and SUB.
THe iPXE Pre-Processor will will translate a iPXE script with high level IF, WHILE, and SUB commands into native iPXE scripts.
Take for example an IF statement:
if ( ping google.com )
echo Google responded
else
echo Could not ping google.com
end if
this can be translated into iPXE format:
ping google.com && || goto if_0001_else
echo Google responded
goto if_0001_end
:if_0001_else
echo Could not ping google.com
:if_0001_end
IF statements make it easier to read. Right? :^)
I've written similar products in the past, but decided to code this from scratch ( Jan 2025 ) and make public for the iPXE community.
Standard IF statement against a single iPXE command and test the output.
if ( [not] <ipxecommand> [args...] ) # Comments...
echo true if
else # Comments...
echo false if
end if # Comments...
Must include the closing end if statement, else is optional. NOT ( or ! ) will test the negative case.
There can be any number of arguments passed to the test command.
Standard While loop statement against a single iPXE command and test the output.
while ( [not] <ipxecommand> [args...] ) # Comments...
echo Looping...
if ( ping google.com )
break # Comments...
end if
if ( ping 8.8.8.8 )
continue # Comments...
end if
end while # Comments...
Must include the closing end while statement, NOT ( or ! ) will test the negative case.
There can be any number of arguments passed to the test command.
break will exit the while loop. continue will jump back to the start of the while loop.
Include another iPXE script in this file.
#include <path> # Comments...
The Path can be relative to the existing script, the current directory, or the path must be absolute. The sub-script is pre-parsed before importing.
Subroutine Commands
sub <subroutinename> # Comments...
return # Comments...
end sub # Comments...
call <subroutinename> [args..] # Comments...
Calls a subroutine, really just a goto jump, where the subroutine keeps track of where to jump BACK to. call will accept a number of arguments, stored as global variables arg1, arg2, arg3 respectively.
forexample:
call mysubroutine One Two "Three Tres Drei"
turns into:
set arg1 One
set arg2 Two
set arg3 "Three Dres Drei"
console formatting
echo This Line will NOT show extra spaces
echo "This Line will SHOW extra spaces"
For text written to console, iPXE will trim all consecutive whitespace to a single space.
To allow for text alignment, we can add an empty escape: From: " " to " ${} "
This feature is only applicable for echo item prompt lines contain Double Quotes.
- Save your script with the .sh file extension. Visual Studio code will do a pretty good job of dispalying the iPXE code. Then save the output as *.ipxe for execution.
- Lines with
#regionand#endregionare striped out. - Lines that start with
##are removed.