Payload configuration
Often for more complex payloads you will want to give the user (or even just yourself) a simple way to change the payload behavior.
The easiest way to accomplish this is with standard variables.
Variables
Variables are assigned in payloads by setting a name to the value; for instance:
SETTING_ONE="abc"Variables can be set to strings or numbers, or even the output of other commands:
# Set the variable SPACE to the output of the USB_FREE command
SPACE=$(USB_FREE)Simple tests
To actually use the results of a configuration option, there are multiple ways to test how it is set.
The simplest test is to compare if a variable is equal to a fixed value:
SETTING_ONE="Y"
if [ ${SETTING_ONE} = "Y" ]; then
LED SUCCESS
fiThis can, of course, also be combined with the else construct:
Complex tests
More complex tests can be created with the case statement:
The case test allows us to match multiple options with a default final option if nothing else matches.
Payload configuration
When making a payload that accepts configuration options, we recommend placing all the options at the top of the payload so that they are easy to find. This way, users of your payload (or your own future self who has forgotten all the complexities of the payload) can easily change the setup.
It's also a good idea to include a description of the configuration variable, and how to use it, as a comment.
Whenever possible, provide a default value that makes sense.
Since a payload does not typically run interactively (the user will never see the output of echo or similar), the LED command is the primary way to communicate errors. For example continuing the payload from above,
Here we confirm the user has entered a sane configuration option, set the LED to error state, and exit the payload entirely.
Configuration names
There is no strict requirement when it comes to the naming of configuration variables, however it is a good idea to:
Keep them entirely upper case. This makes it easy to spot them in the code.
Give them meaningful names. This helps you remember them during the rest of the payload. Naming configuration variables
A,B, and so on is certainly possible, but don't.
Last updated
Was this helpful?
