]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
Allow specifying target in NOVABOOT_TARGET environment variable
authorMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 15 Dec 2014 14:16:07 +0000 (15:16 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 15 Dec 2014 14:16:46 +0000 (15:16 +0100)
README.md
novaboot
tests/novaboot.wv

index fb1f402249f7f07b296b07298940647ed295e99e..7029f4f77bd386beb1eb0638c5b3089d40bad5c7 100644 (file)
--- 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.
index 263fdeef3c0597171357920d789e5229e7d8c2c4..3a1eda7d2b55f6a371acb266026ccd27b6ccb346 100755 (executable)
--- 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<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 C<%targets> configuration variable under key I<target>. See
-also L</"CONFIGURATION FILE">.
+options. The effect of this option is the same as specifying the
+options stored in the C<%targets> configuration variable under key
+I<target>. See also L</"CONFIGURATION FILE">.
+
+When this option is not given, novaboot tries to determine the target
+to use from either B<NOVABOOT_TARGET> 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<NOVABOOT_TARGET> environment variable.
 
 =item %targets
 
@@ -1983,6 +1988,12 @@ one(s).
 Name of the novaboot configuration directory. When not specified
 F</etc/novaboot.d> 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.
index e76a4c80f0eea8d23a961459bfb2a439df2d7f2e..da97b45debe5f2723baaa21aa07a5d6e843ca222 100755 (executable)
@@ -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)))