]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
Add support for configuration directory
authorMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 21 Jul 2014 22:09:21 +0000 (00:09 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 21 Jul 2014 22:09:21 +0000 (00:09 +0200)
Makefile
etc.novaboot.txt [new file with mode: 0644]
novaboot
tests/novaboot.wv

index 1565579adbe384c822f7cf6727e86db2537baeb4..fb6319690ba8edcad006bd3083de164e3b932584 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,8 @@ install:
        pod2man novaboot $(DESTDIR)$(PREFIX)/share/man/man1/novaboot.1
        install -d $(DESTDIR)/etc/sudoers.d
        install -m 440 sudoers.novaboot $(DESTDIR)/etc/sudoers.d/novaboot
+       install -d $(DESTDIR)/etc/novaboot.d
+       install etc.novaboot.txt $(DESTDIR)/etc/novaboot.d/README.txt
 
 test:
        $(MAKE) -C tests
diff --git a/etc.novaboot.txt b/etc.novaboot.txt
new file mode 100644 (file)
index 0000000..aac91fb
--- /dev/null
@@ -0,0 +1,3 @@
+Files in this directory with names consisting solely from English
+letters, numbers, dashes '-' and underscores '_' (note that dot '.' is
+not included) are read by novaboot on startup in alphabetical order.
index 09612aa1fb3279f8ef040b7ba9c97c5d653c335c..11719c62d647dad9dcc1e99b40e50b226e05cb47 100755 (executable)
--- a/novaboot
+++ b/novaboot
@@ -88,11 +88,19 @@ my @cfgs;
        my @dirs = File::Spec->splitdir($dir);
        $dir = File::Spec->catdir(@dirs[0..$#dirs-1]);
     }
+    @cfgs = reverse @cfgs;
+    $dir = $ENV{'NOVABOOT_CONFIG_DIR'} || '/etc/novaboot.d';
+    if (opendir(my $dh, $dir)) {
+       my @etccfg = map { "$dir/$_" } grep { /^[-_a-zA-Z0-9]+$/ && -f "$dir/$_" } readdir($dh);
+       closedir $dh;
+       @etccfg = sort(@etccfg);
+       @cfgs = ( @etccfg, @cfgs );
+    }
 }
 my $cfg = $ENV{'NOVABOOT_CONFIG'};
 Getopt::Long::Configure(qw/no_ignore_case pass_through/);
 GetOptions ("config|c=s" => \$cfg);
-read_config($_) foreach $cfg or reverse @cfgs;
+read_config($_) foreach $cfg or @cfgs;
 
 ## Command line handling
 
@@ -1143,19 +1151,32 @@ follow.
 
 =head2 Configuration reading phase
 
-After starting, novaboot reads configuration files. By default, it
-searches for files named F<.novaboot> starting from the directory of
-the novaboot script (or working directory, see bellow) and continuing
-upwards up to the root directory. The configuration files are read in
-order from the root directory downwards with latter files overriding
-settings from the former ones.
+After starting, novaboot reads configuration files. Their content is
+described in L</"CONFIGURATION FILE">. By default, configuration is
+read from two locations. First from the configuration directory and
+second from F<.novaboot> files along the path to the current
+directory. The later read files override settings from the former
+ones.
+
+Configuration directory is determined by the content of
+NOVABOOT_CONFIG_DIR environment variable defaulting to
+F</etc/novaboot.d>. Files in this directory with names consisting
+solely from English letters, numbers, dashes '-' and underscores '_'
+(note that dot '.' is not included) are read in alphabetical order.
+
+Then novaboot searches for files named F<.novaboot> starting
+from the directory of the novaboot script (or working directory, see
+bellow) and continuing upwards up to the root directory. The found
+configuration files are then read in order from the root directory
+downwards.
 
 In certain cases, the location of the novaboot script cannot be
 determined in this early phase. This happens either when the script is
 read from the standard input or when novaboot is invoked explicitly
 and options precede the script name, as in the example L</"4."> above.
 In this case the current working directory is used as a starting point
-for configuration file search.
+for configuration file search instead of the novaboot script
+directory.
 
 =over 8
 
@@ -1694,13 +1715,13 @@ intermediate output.
 
 Novaboot can read its configuration from one or more files. By
 default, novaboot looks for files named F<.novaboot> as described in
-L</Configuration reading phase>. Alternatively, its location can be
-specified with the B<-c> switch or with the NOVABOOT_CONFIG
-environment variable. The configuration file has perl syntax and
-should set values of certain Perl variables. The current configuration
-can be dumped with the B<--dump-config> switch. Some configuration
-variables can be overridden by environment variables (see below) or by
-command line switches.
+L</Configuration reading phase>. Alternatively, configuration file
+location can be specified with the B<-c> switch or with the
+NOVABOOT_CONFIG environment variable. The configuration file has perl
+syntax and should set values of certain Perl variables. The current
+configuration can be dumped with the B<--dump-config> switch. Some
+configuration variables can be overridden by environment variables
+(see below) or by command line switches.
 
 Supported configuration variables include:
 
@@ -1718,10 +1739,11 @@ specified on command line with the B<--target> option.
 
 =item %targets
 
-Hash of shortcuts to be used with the B<--target> option. If the hash
-contains, for instance, the following pair of values
+Hash of target definitions to be used with the B<--target> option. The
+key is the identifier of the target, the value is the string with
+command line options. For instance, if the configuration file contains:
 
'mybox' => '--server=boot:/tftproot --serial=/dev/ttyUSB0 --grub',
$targets{'mybox'} = '--server=boot:/tftproot --serial=/dev/ttyUSB0 --grub',
 
 then the following two commands are equivalent:
 
@@ -1744,6 +1766,11 @@ override the environment variables.
 Name of the novaboot configuration file to use instead of the default
 one(s).
 
+=item NOVABOOT_CONFIG_DIR
+
+Name of the novaboot configuration directory. When not specified
+F</etc/novaboot.d> is used.
+
 =item NOVABOOT_BENDER
 
 Defining this variable has the same meaning as B<--bender> option.
index 9fc60569f50b1ab3b780bd71e007dccb584422b1..63c402bb972a4035589a3398146916f3a55f430e 100755 (executable)
@@ -46,6 +46,19 @@ EOF
 WVPASS ./script --gen-only
 WVPASS test -f build/file
 
+WVSTART Configuration directory
+mkdir -p dir
+echo '$test_a = 1;' > dir/a
+echo '$test_c = 2;' > dir/c
+echo '$test_c = 1;' > dir/b    # Overriden by the 'c' file
+echo '$test_ign=1;' > dir/b.txt        # Ignored
+WVPASS sh -c 'NOVABOOT_CONFIG_DIR=dir novaboot --dump-config > config'
+WVPASS sh -c 'grep \$test config > test'
+WVPASS diff -u - test <<'EOF'
+$test_a = 1;
+$test_c = 2;
+EOF
+
 WVSTART Fail with unknown target
 create_dummy
 WVFAIL sh -c "./script --gen-only -t non-existing-target"