From 0e9e9e6b3a9198fb4f5a1e451e8be24f4d59abbf Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Mon, 15 Dec 2014 15:16:07 +0100 Subject: [PATCH] Allow specifying target in NOVABOOT_TARGET environment variable --- README.md | 19 +++++++++++++++---- novaboot | 21 ++++++++++++++++----- tests/novaboot.wv | 14 ++++++++++++++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fb1f402..7029f4f 100644 --- a/README.md +++ b/README.md @@ -132,9 +132,13 @@ instead of the novaboot script directory. - -t, --target=_target_ This option serves as a user configurable shortcut for other novaboot - options. The effect of this option is the same as the options stored - in the `%targets` configuration variable under key _target_. See - also ["CONFIGURATION FILE"](#configuration-file). + options. The effect of this option is the same as specifying the + options stored in the `%targets` configuration variable under key + _target_. See also ["CONFIGURATION FILE"](#configuration-file). + + When this option is not given, novaboot tries to determine the target + to use from either **NOVABOOT\_TARGET** environment variable or from + **$default\_target** configuration file variable. ## Script preprocessing phase @@ -720,7 +724,8 @@ Supported configuration variables include: - $default\_target Default target (see below) to use when no target is explicitly - specified on command line with the **--target** option. + specified with the **--target** command line option or + **NOVABOOT\_TARGET** environment variable. - %targets @@ -752,6 +757,12 @@ override the environment variables. Name of the novaboot configuration directory. When not specified `/etc/novaboot.d` is used. +- NOVABOOT\_TARGET + + Name of the novaboot target to use. This overrides the value of + **$default\_target** from the configuration file and can be overriden + with the **--target** command line option. + - NOVABOOT\_BENDER Defining this variable has the same meaning as **--bender** option. diff --git a/novaboot b/novaboot index 263fdee..3a1eda7 100755 --- a/novaboot +++ b/novaboot @@ -111,7 +111,7 @@ read_config($_) foreach $cfg or @cfgs; ## Command line handling -my $explicit_target; +my $explicit_target = $ENV{'NOVABOOT_TARGET'}; GetOptions ("target|t=s" => \$explicit_target); my ($amt, @append, $bender, @chainloaders, $concat, $config_name_opt, $dhcp_tftp, $dump_opt, $dump_config, @exiton, $exiton_timeout, @expect_raw, $gen_only, $grub_config, $grub_prefix, $grub_preamble, $grub2_prolog, $grub2_config, $help, $ider, $interaction, $iprelay, $iso_image, $interactive, $kernel_opt, $make, $man, $no_file_gen, $off_opt, $on_opt, $pulsar, $pulsar_root, $qemu, $qemu_append, $qemu_flags_cmd, $remote_cmd, $remote_expect, $remote_expect_silent, $reset, $reset_cmd, $rom_prefix, $rsync_flags, @scriptmod, $scons, $serial, $server, $stty, $tftp, $tftp_port, $uboot, %uboot_addr, $uboot_cmd, @uboot_init); @@ -1323,9 +1323,13 @@ Print short (B<-h>) or long (B<--help>) help. =item -t, --target=I This option serves as a user configurable shortcut for other novaboot -options. The effect of this option is the same as the options stored -in the C<%targets> configuration variable under key I. See -also L. +options. The effect of this option is the same as specifying the +options stored in the C<%targets> configuration variable under key +I. See also L. + +When this option is not given, novaboot tries to determine the target +to use from either B environment variable or from +B<$default_target> configuration file variable. =back @@ -1947,7 +1951,8 @@ file. =item $default_target Default target (see below) to use when no target is explicitly -specified on command line with the B<--target> option. +specified with the B<--target> command line option or +B environment variable. =item %targets @@ -1983,6 +1988,12 @@ one(s). Name of the novaboot configuration directory. When not specified F is used. +=item NOVABOOT_TARGET + +Name of the novaboot target to use. This overrides the value of +B<$default_target> from the configuration file and can be overriden +with the B<--target> command line option. + =item NOVABOOT_BENDER Defining this variable has the same meaning as B<--bender> option. diff --git a/tests/novaboot.wv b/tests/novaboot.wv index e76a4c8..da97b45 100755 --- a/tests/novaboot.wv +++ b/tests/novaboot.wv @@ -101,5 +101,19 @@ EOF WVPASS sh -c "./script --target=t1 2>&1 |tee output" WVPASS grep -q "Error in target definition" output +WVSTART Different ways of specifying target +cat > .novaboot <<'EOF' +%targets = ('t1' => '--remote-cmd="echo Target1 > t"', + 't2' => '--remote-cmd="echo Target2 > t"', + 't3' => '--remote-cmd="echo Target3 > t"'); +$default_target = 't1'; +EOF +WVPASSSH 'novaboot /dev/null' +WVPASS test "$(cat t)" = Target1 +WVPASSSH 'NOVABOOT_TARGET=t2 novaboot /dev/null' +WVPASS test "$(cat t)" = Target2 +WVPASSSH 'NOVABOOT_TARGET=t2 novaboot --target t3 /dev/null' +WVPASS test "$(cat t)" = Target3 + # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t))) -- 2.39.2