init_functions: add getarg function for arbitrary cmdline args
adding shell-compatible cmdline arguments to the global environment is
not a great idea, and can possibly cause bad behaviour if an important
variable is overridden in this way. That functionality in parse_cmdline
should be deprecated and removed in the future. This cannot be done
immediately because there are certainly a number of first- and
third-party hooks that rely on this behaviour.
The new API is similar to dracut, but much simpler:
getarg name [default]
for example:
foo="$(getarg 'foo')"
bar="$(getarg 'bar' 'a default')"
baz="$(getarg 'foo.baz')"
- if
name
exists and has a value, the value is returned - if
name
exists without a value,y
is returned (this is the same as the current parsing of boolean options) - if
name
does not exist,default
is returned (which defaults to''
) - if
name
is specified multiple times, the last value is returned - this supports arbitrary
name
s, including ones that are not valid shell variables, likefoo.bar
.
TODO
-
documentation of getarg
-
replace usage in first-party hooks and mkinitcpio itself -
testing
Edited by classabbyamp