[gPXE] Crazy Scripting Library

Miller, Shao Shao.Miller at yrdsb.edu.on.ca
Wed Mar 17 23:33:05 EDT 2010


Good day,

I just wanted to offer the attached scripting "library" which has minor
capabilities, but is usable with gPXE 1.0.0+'s current scripting system.
Sometimes it's handy to set a value with a space in it, for instance
(see '${spc}').  You can put this "library" at the top of your gPXE
script.

- Shao Miller

-----

#!gpxe
# Crazy scripting library for gPXE
# (C) 2010 Shao Miller <shao.miller at yrdsb.edu.on.ca>

# Commonly used items
set dollar $
set lb {
set rb }
set exp:hex ${dollar:hex}:${lb:hex}
set space:hex 20
set colon :
set ashex :hex

# :)
set set set
# :)


# '${take}' and '${take2}'
# ------------------------
# '${take} <value>' sets "taken" setting to "value"
# '${take2} <value>' sets "taken2" setting to "value"

set taken taken
set take:hex ${set:hex}:${space:hex}:${taken:hex}:${space:hex}
set takenhex:hex ${exp:hex}:${taken:hex}:${ashex:hex}:${rb:hex}
set taken2 taken2
set take2:hex ${set:hex}:${space:hex}:${taken2:hex}:${space:hex}
set taken2hex:hex ${exp:hex}:${taken2:hex}:${ashex:hex}:${rb:hex}
# For internal use
set takeni takeni
set takei:hex ${set:hex}:${space:hex}:${takeni:hex}:${space:hex}
set takenihex:hex ${exp:hex}:${takeni:hex}:${ashex:hex}:${rb:hex}


# '${join}'
# ---------
# '${join}' will concatenate "taken" and "taken2" settings
# and store the result to "taken" setting

set join:hex
${set:hex}:${space:hex}:${taken:hex}:${ashex:hex}:${space:hex}:${takenhe
x:hex}:${colon:hex}:${taken2hex:hex}


# '${wrapvar}'
# ------------
# '${wrapvar}' will take the value in "taken" setting and wrap it
# with $ { .. } and store the result to "taken" setting

set tmp ${exp:hex}
set tmp2 ${rb:hex}
set wrapvar:hex
${set:hex}:${space:hex}:${taken:hex}:${ashex:hex}:${space:hex}:${tmp:hex
}:${colon:hex}:${takenhex:hex}:${colon:hex}:${tmp2:hex}
set wrapvari:hex
${set:hex}:${space:hex}:${takeni:hex}:${ashex:hex}:${space:hex}:${tmp:he
x}:${colon:hex}:${takenihex:hex}:${colon:hex}:${tmp2:hex}
clear tmp
clear tmp2


# '${if1}', '${if2}', '${if3}'
# ----------------------------
# You run these three commands in order to set the "cond" setting
# with either a comment-marker ('#') or nothing, depending on
# whether the "taken" setting is clear, or set with a non-NUL
# value, respectively
# For example:
# gPXE> clear taken
# gPXE> ${if1}
# gPXE> ${if2}
# gPXE> ${if3}
# gPXE> ${cond} echo hello
# gPXE> ${take} foo
# gPXE> ${if1}
# gPXE> ${if2}
# gPXE> ${if3}
# gPXE> ${cond} echo hello
# hello

set nop #
${takei} takei
${wrapvari}
set tmp:hex ${takeni:hex}
set tmp2 nop
set if1:hex
${tmp:hex}:${space:hex}:${tmp2:hex}:${exp:hex}:${taken:hex}:${rb:hex}
${takei} wrapvari
${wrapvari}
set if2:hex ${takeni:hex}
set tmp cond
set if3:hex
${set:hex}:${space:hex}:${tmp:hex}:${ashex:hex}:${space:hex}:${takenihex
:hex}
clear tmp
clear tmp2


# '${hexpand}'
# ------------
# Take the value stored in the setting "taken", expand it
# to its hexadecimal representation and store the result
# back into the "taken" setting

set hexpand:hex
${set:hex}:${space:hex}:${taken:hex}:${space:hex}:${takenhex:hex}


# '${hexclose}'
# -------------
# Take the value stored in the setting "taken", interpret
# it as a hexadecimal sequence and store the result back
# into the "taken" setting

set hexclose:hex
${set:hex}:${space:hex}:${taken:hex}:${ashex:hex}:${space:hex}:${exp:hex
}:${taken:hex}:${rb:hex}


# '${spc}'
# --------
# Append a space character to the "taken" setting
# For example:
# gPXE> ${take} a
# gPXE> ${spc}
# gPXE> ${take2} b
# gPXE> ${join}
# gPXE> show taken
#taken = a b

set spc:hex
${set:hex}:${space:hex}:${taken:hex}:${ashex:hex}:${space:hex}:${takenhe
x:hex}:${colon:hex}:32:30


clear taken
clear taken2

# :)
clear set
# :)

#################################################

-------------- next part --------------
A non-text attachment was scrubbed...
Name: lib.gpxe
Type: application/octet-stream
Size: 3405 bytes
Desc: lib.gpxe
Url : http://etherboot.org/pipermail/gpxe/attachments/20100317/99a626bd/attachment.obj 


More information about the gPXE mailing list