]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/yaird-0.0.5/perl/Conf.pm
Initial revision
[bacula/rescue] / rescue / linux / cdrom / yaird-0.0.5 / perl / Conf.pm
1 #!perl -w
2 #
3 # Conf -- configured path names and such.
4 #   Copyright (C) 2005  Erik van Konijnenburg
5 #
6 #   This program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2 of the License, or
9 #   (at your option) any later version.
10 #
11 #   This program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program; if not, write to the Free Software
18 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 #
20 # You can get and set configuration items by name,
21 # with the following restrictions:
22 # - only get and set known keys
23 # - after first get, no further set is allowed.
24 #
25 # Defaults are packaged as subs, so that you can change
26 # one setting and have the change ripple through in other
27 # settings.
28 #
29 use strict;
30 use warnings;
31 use Base;
32 package Conf;
33
34 sub get($);
35
36 #
37 # Default values for configuration; if there is no default,
38 # it's not a known parameter, and you cannot modify it.
39 #
40 my $defaults = {
41         version         => sub { my $v = `uname -r`; chomp $v; $v; },
42         libModules      => sub { "/lib/modules"; },
43         kernConf        => sub { "/boot/config-"
44                                 . get('version'); },
45         modDep          => sub { get('libModules')
46                                 . '/' . get('version')
47                                 . '/modules.dep'; },
48         usbMap          => sub { get('libModules')
49                                 . '/' . get('version')
50                                 . '/modules.usbmap'; },
51         pciMap          => sub { get('libModules')
52                                 . '/' . get('version')
53                                 . '/modules.pcimap'; },
54         modDir          => sub { get('libModules')
55                                 . '/' . get('version')
56                                 . '/kernel'; },
57         sysFs           => sub { "/sys"; },
58         procFs          => sub { "/proc"; },
59         #delete next 2?
60         sysBlock        => sub { get ('sysFs') . "/block"; },
61         sysDevices      => sub { get ('sysFs') . "/devices"; },
62         dev             => sub { "/dev"; },
63         fstab           => sub { "/etc/fstab"; },
64         hotplug         => sub { "/etc/hotplug"; },
65         appVersion      => sub { "0.0.5"; },
66         auxDir          => sub { "/usr/local/lib/yaird/exec"; },
67 };
68
69
70 my $overrides = {};             # config values where default is overridden,
71                                 # presumably via command line.
72 my $used = {};                  # if a key exists, the config value has
73                                 # been used, and it no longer can be changed.
74
75 sub get ($) {
76         my ($key) = @_;
77         my $dflt = $defaults->{$key};
78         Base::assert (defined ($dflt));
79         $used->{$key}++;
80         my $ovr = $overrides->{$key};
81         if (defined ($ovr)) {
82                 return $ovr;
83         }
84         return &{$dflt}();
85 }
86
87 sub set ($$) {
88         my ($key, $value) = @_;
89         my $dflt = $defaults->{$key};
90         Base::assert (defined ($dflt));
91         Base::assert (! defined ($used->{$key}));
92         $overrides->{$key} = $value;
93 }
94
95 1;