[settings] Expose current working URI and directory URI via settings

iPXE maintains a concept of a current working URI, which is used when
resolving relative URIs and allows scripts to download files using
URIs relative to the script itself.

There are situations in which it is valuable for a script to be able
to access the URI explicitly as a string, not just implicitly as a
base URI for subsequent downloads.  For example, when booting a Fedora
installer, the "inst.repo" command-line parameter may be used to pass
the URI of the repository to the installer.

Expose the current working URI as ${cwuri}.  Since relative URIs may
be constructed as strings only from a directory URI (not from a full
URI), also expose the current working directory URI as ${cwduri}.

This feature may be used as e.g.

  #!ipxe
  echo Booting from ${cwuri}
  prompt -k 0x197e -t 2000 Press F12 to install Fedora... || exit
  kernel images/pxeboot/vmlinux inst.repo=${cwduri}
  initrd images/pxeboot/initrd.img
  boot

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2024-03-19 13:22:57 +00:00
parent 926816c58f
commit 88c2a01e1a
2 changed files with 123 additions and 0 deletions

View File

@@ -754,6 +754,20 @@ static struct uri_resolve_test uri_fragment = {
"http://192.168.0.254/test#bar",
};
/** Empty relative URI resolution test */
static struct uri_resolve_test uri_self = {
"http://192.168.0.1/path/to/me",
"",
"http://192.168.0.1/path/to/me",
};
/** Current directory URI resolution test */
static struct uri_resolve_test uri_cwd = {
"http://192.168.0.1/path/to/me",
".",
"http://192.168.0.1/path/to/",
};
/** PXE URI with absolute URI */
static struct uri_pxe_test uri_pxe_absolute = {
{
@@ -996,6 +1010,8 @@ static void uri_test_exec ( void ) {
uri_resolve_ok ( &uri_absolute_uri_path );
uri_resolve_ok ( &uri_query );
uri_resolve_ok ( &uri_fragment );
uri_resolve_ok ( &uri_self );
uri_resolve_ok ( &uri_cwd );
/* PXE URI construction tests */
uri_pxe_ok ( &uri_pxe_absolute );