From: Michal Sojka Date: Sun, 23 Nov 2014 23:18:34 +0000 (+0100) Subject: Implement user configuration file X-Git-Tag: 20141125~5 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/novaboot.git/commitdiff_plain/05829f7a16a534bf4061203179433303db5eeeb6 Implement user configuration file 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. --- diff --git a/README.md b/README.md index 08028ee..cc1f0e2 100644 --- 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: diff --git a/novaboot b/novaboot index 0c2faf1..4e30ace 100755 --- 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. 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 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. 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 and files -named F<.novaboot> as described in L. -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, file +F<~/.config/novaboot> and files named F<.novaboot> as described in +L. 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: