]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
Implement user configuration file
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 23 Nov 2014 23:18:34 +0000 (00:18 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 23 Nov 2014 23:18:34 +0000 (00:18 +0100)
Previously, it was recommended to use ~/.novaboot as user configuration
file, but this didn't work when working other directory, such as in
/tmp. Therefore a new configuration file ~/.config/novaboot is
introduced, which is read always when it exists.

Thanks to Michal Vokac for figuring out this problem.

README.md
novaboot

index 08028ee6e6abf34e04a4081be673a60261c603ff..cc1f0e270ea4c0113eab9e20fefcb58a86a0751d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -78,24 +78,33 @@ corresponding options follows.
 
 After starting, novaboot reads configuration files. Their content is
 described in section ["CONFIGURATION FILE"](#configuration-file). By default,
-configuration is read from two locations. First from the configuration
-directory and second from `.novaboot` files along the path to the
-current directory. The latter read files override settings from the
-former ones.
-
-Configuration directory is determined by the content of
+configuration is read from multiple locations. First from the system
+configuration directory, second from the user configuration file and
+third from `.novaboot` files along the path to the current directory.
+Alternatively, a single configuration file specified with the **-c**
+switch or with the `NOVABOOT_CONFIG` environment variable. The latter
+read files override settings from the former ones.
+
+The system configuration directory is determined by the content of
 NOVABOOT\_CONFIG\_DIR environment variable and defaults to
 `/etc/novaboot.d`. Files in this directory with names consisting
 solely of English letters, numbers, dashes '-' and underscores '\_'
 (note that dot '.' is not included) are read in alphabetical order.
 
-Then novaboot searches for files named `.novaboot` starting from the
+Then, the user configuration file is read from
+`$XDG_CONFIG_HOME/novaboot`. If `$XDG_CONFIG_HOME` environemnt
+variable is not set `~/.config/novaboot` is read instead.
+
+Finally, novaboot searches for files named `.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 the opposite order (i.e. from the
-root directory downwards). This allows to have, for example, user
-specific configuration in `~/.novaboot` and project specific one in
-`~/project/.novaboot`.
+root directory downwards). This allows to have, for example, a project
+specific configuration in `~/project/.novaboot`.
+
+Note the difference between `~/.config/novaboot` and `~/.novaboot`.
+The former one is read always, whereas the latter only when novaboot
+script or working directory is under the `$HOME` directory.
 
 In certain cases, the location of the novaboot script cannot be
 determined in this early phase. This happens either when the script is
@@ -673,15 +682,16 @@ The following variables are interpreted in the novaboot script:
 # CONFIGURATION FILE
 
 Novaboot can read its configuration from one or more files. By
-default, novaboot looks for files in `/etc/novaboot.d` and files
-named `.novaboot` as described in ["Configuration reading phase"](#configuration-reading-phase).
-Alternatively, configuration file location can be specified with the
-**-c** switch or with the NOVABOOT\_CONFIG environment variable. The
-configuration file has Perl syntax (i.e. it is better to put `1;` as
-a last line) and should set values of certain Perl variables. The
-current configuration can be dumped with the **--dump-config** switch.
-Some configuration variables can be overridden by environment
-variables (see below) or by command line switches.
+default, novaboot looks for files in `/etc/novaboot.d`, file
+`~/.config/novaboot` and files named `.novaboot` as described in
+["Configuration reading phase"](#configuration-reading-phase). Alternatively, configuration file
+location can be specified with the **-c** switch or with the
+NOVABOOT\_CONFIG environment variable. The configuration file has Perl
+syntax (i.e. it is better to put `1;` as the last line) and should set
+values of certain Perl variables. The current configuration can be
+dumped with the **--dump-config** switch. Some configuration variables
+can be overridden by environment variables (see below) or by command
+line switches.
 
 Supported configuration variables include:
 
index 0c2faf157d9ea78df2ddde74d874da234da7b0a8..4e30ace09d79bbdb676b86210cc2b1d2f4f5c267 100755 (executable)
--- a/novaboot
+++ b/novaboot
@@ -90,6 +90,10 @@ my @cfgs;
        $dir = File::Spec->catdir(@dirs[0..$#dirs-1]);
     }
     @cfgs = reverse @cfgs;
+
+    my $xdg_config_home = $ENV{'XDG_CONFIG_HOME'} || $ENV{'HOME'}.'/.config';
+    unshift(@cfgs, "$xdg_config_home/novaboot") if -r "$xdg_config_home/novaboot";
+
     $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);
@@ -1219,24 +1223,33 @@ corresponding options follows.
 
 After starting, novaboot reads configuration files. Their content is
 described in section 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 latter read files override settings from the
-former ones.
-
-Configuration directory is determined by the content of
+configuration is read from multiple locations. First from the system
+configuration directory, second from the user configuration file and
+third from F<.novaboot> files along the path to the current directory.
+Alternatively, a single configuration file specified with the B<-c>
+switch or with the C<NOVABOOT_CONFIG> environment variable. The latter
+read files override settings from the former ones.
+
+The system configuration directory is determined by the content of
 NOVABOOT_CONFIG_DIR environment variable and defaults to
 F</etc/novaboot.d>. Files in this directory with names consisting
 solely of 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
+Then, the user configuration file is read from
+F<$XDG_CONFIG_HOME/novaboot>. If C<$XDG_CONFIG_HOME> environemnt
+variable is not set F<~/.config/novaboot> is read instead.
+
+Finally, 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 the opposite order (i.e. from the
-root directory downwards). This allows to have, for example, user
-specific configuration in F<~/.novaboot> and project specific one in
-F<~/project/.novaboot>.
+root directory downwards). This allows to have, for example, a project
+specific configuration in F<~/project/.novaboot>.
+
+Note the difference between F<~/.config/novaboot> and F<~/.novaboot>.
+The former one is read always, whereas the latter only when novaboot
+script or working directory is under the C<$HOME> directory.
 
 In certain cases, the location of the novaboot script cannot be
 determined in this early phase. This happens either when the script is
@@ -1855,15 +1868,16 @@ intermediate output.
 =head1 CONFIGURATION FILE
 
 Novaboot can read its configuration from one or more files. By
-default, novaboot looks for files in F</etc/novaboot.d> and files
-named F<.novaboot> as described in 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 (i.e. it is better to put C<1;> as
-a last line) 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.
+default, novaboot looks for files in F</etc/novaboot.d>, file
+F<~/.config/novaboot> and files named F<.novaboot> as described in
+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 (i.e. it is better to put C<1;> as the last line) 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: