129 |
rodolico |
1 |
#! /usr/bin/env perl
|
|
|
2 |
|
|
|
3 |
# This file will contain information for a specific installer
|
|
|
4 |
# this allows the installer to be used on different programs.
|
|
|
5 |
|
|
|
6 |
# defines a basic install. Values are overridden depending on operating
|
|
|
7 |
# system as defined by %operatingSystems
|
203 |
rodolico |
8 |
our %install = (
|
|
|
9 |
'bindir' => '/opt/camp/sysinfo-client',
|
|
|
10 |
'confdir' => '/etc/camp/sysinfo-client',
|
|
|
11 |
'application name' => 'sysinfo client',
|
|
|
12 |
'default group' => 'root',
|
|
|
13 |
'default owner' => 'root',
|
|
|
14 |
'default permission' => '0700',
|
|
|
15 |
'configuration seed file' => '<installdir>/sysinfo-client.seed.yaml',
|
|
|
16 |
'configuration' => {
|
129 |
rodolico |
17 |
'configurator' => '<bindir>/configure.pl',
|
|
|
18 |
'configuration file' => '<confdir>/sysinfo-client.yaml',
|
|
|
19 |
'old configuration file' => '<confdir>/sysinfo-client.conf',
|
|
|
20 |
'permission' => '700',
|
|
|
21 |
'owner' => '<default owner>',
|
|
|
22 |
'target' => '<confdir>'
|
|
|
23 |
},
|
|
|
24 |
'files' => {
|
|
|
25 |
'configure.pl' => {
|
|
|
26 |
'type' => 'file',
|
|
|
27 |
'permission' => '700',
|
|
|
28 |
'owner' => '<default owner>:<default group>',
|
|
|
29 |
'target' => '<bindir>'
|
|
|
30 |
},
|
|
|
31 |
'sysinfo-client' => {
|
|
|
32 |
'type' => 'file',
|
|
|
33 |
'permission' => '700',
|
|
|
34 |
'owner' => '<default owner>:<default group>',
|
|
|
35 |
'target' => '<bindir>'
|
|
|
36 |
},
|
|
|
37 |
'sysinfoconf.pm' => {
|
|
|
38 |
'type' => 'file',
|
|
|
39 |
'permission' => '600',
|
|
|
40 |
'owner' => '<default owner>:<default group>',
|
|
|
41 |
'target' => '<bindir>'
|
|
|
42 |
},
|
|
|
43 |
'notes' => {
|
|
|
44 |
'type' => 'file',
|
|
|
45 |
'permission' => '600',
|
|
|
46 |
'owner' => '<default owner>:<default group>',
|
|
|
47 |
'target' => '<bindir>'
|
|
|
48 |
},
|
|
|
49 |
'sysinfo-client.conf.template.yaml' => {
|
|
|
50 |
'type' => 'file',
|
|
|
51 |
'permission' => '600',
|
|
|
52 |
'owner' => '<default owner>:<default group>',
|
|
|
53 |
'target' => '<bindir>'
|
|
|
54 |
},
|
|
|
55 |
'getSendEmail.pl' => {
|
|
|
56 |
'type' => 'file',
|
|
|
57 |
'permission' => '700',
|
|
|
58 |
'owner' => '<default owner>:<default group>',
|
|
|
59 |
'target' => '<bindir>'
|
|
|
60 |
},
|
139 |
rodolico |
61 |
'install' => {
|
129 |
rodolico |
62 |
'type' => 'file',
|
|
|
63 |
'permission' => '700',
|
|
|
64 |
'owner' => '<default owner>:<default group>',
|
|
|
65 |
'target' => '<bindir>'
|
|
|
66 |
},
|
|
|
67 |
'sysinfo-client.seed.example.yaml' => {
|
|
|
68 |
'type' => 'file',
|
|
|
69 |
'permission' => '600',
|
|
|
70 |
'owner' => '<default owner>:<default group>',
|
|
|
71 |
'target' => '<bindir>'
|
|
|
72 |
},
|
|
|
73 |
'VERSION' => {
|
|
|
74 |
'type' => 'file',
|
|
|
75 |
'permission' => '600',
|
|
|
76 |
'owner' => '<default owner>:<default group>',
|
|
|
77 |
'target' => '<bindir>'
|
|
|
78 |
},
|
160 |
rodolico |
79 |
'SYSTEM_VERSION' => {
|
|
|
80 |
'type' => 'file',
|
|
|
81 |
'permission' => '755',
|
129 |
rodolico |
82 |
'owner' => '<default owner>:<default group>',
|
160 |
rodolico |
83 |
'target' => '<bindir>'
|
|
|
84 |
},
|
|
|
85 |
'modules' => {
|
|
|
86 |
'type' => 'directory',
|
|
|
87 |
'permission' => '700',
|
|
|
88 |
'owner' => '<default owner>:<default group>',
|
|
|
89 |
'target' => '<bindir>',
|
|
|
90 |
'action' => 'chmod 700 *'
|
|
|
91 |
},
|
|
|
92 |
'scripts' => {
|
|
|
93 |
'type' => 'directory',
|
|
|
94 |
'permission' => '700',
|
|
|
95 |
'owner' => '<default owner>:<default group>',
|
|
|
96 |
'target' => '<bindir>',
|
|
|
97 |
'action' => 'chmod 700 *'
|
|
|
98 |
},
|
129 |
rodolico |
99 |
}
|
|
|
100 |
);
|
|
|
101 |
|
|
|
102 |
# hash to set up os specific rules. these override values in %install when a particular operating
|
|
|
103 |
# system is detected.
|
|
|
104 |
our %operatingSystems = (
|
|
|
105 |
'debian' => {
|
|
|
106 |
'regex' => '(debian|mx|devuan)',
|
|
|
107 |
'bindir' => '/opt/camp/sysinfo-client',
|
|
|
108 |
'confdir' => '/etc/camp/sysinfo-client',
|
132 |
rodolico |
109 |
'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/cron.daily/sysinfo-client',
|
129 |
rodolico |
110 |
'modules' => '((linux)|(dpkg)|(unix)|(all))',
|
|
|
111 |
},
|
|
|
112 |
'ipfire' => {
|
|
|
113 |
'regex' => 'ipfire',
|
|
|
114 |
'bindir' => '/opt/camp/sysinfo-client',
|
|
|
115 |
'confdir' => '/etc/camp/sysinfo-client',
|
139 |
rodolico |
116 |
'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/fcron.daily/sysinfo-client.fcron',
|
129 |
rodolico |
117 |
'modules' => '((ipfire)|(unix)|(all))',
|
|
|
118 |
},
|
|
|
119 |
'freebsd' => {
|
|
|
120 |
'regex' => 'freebsd',
|
|
|
121 |
'bindir' => '/usr/local/opt/camp/sysinfo-client',
|
|
|
122 |
'confdir' => '/usr/local/etc/camp/sysinfo-client',
|
139 |
rodolico |
123 |
'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
|
129 |
rodolico |
124 |
'modules' => '((bsd)|(unix)|(all))',
|
|
|
125 |
'default group' => 'wheel',
|
|
|
126 |
'default owner' => 'root',
|
|
|
127 |
},
|
|
|
128 |
'opnsense' => {
|
|
|
129 |
'fileexists' => '/conf/config.xml',
|
|
|
130 |
'bindir' => '/usr/local/opt/camp/sysinfo-client',
|
|
|
131 |
'confdir' => '/usr/local/etc/camp/sysinfo-client',
|
144 |
rodolico |
132 |
#'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
|
129 |
rodolico |
133 |
'modules' => '((bsd)|(unix)|(all))',
|
|
|
134 |
'default group' => 'wheel',
|
|
|
135 |
'default owner' => 'root',
|
|
|
136 |
'files' => {
|
|
|
137 |
'actions_sysinfo.conf' => {
|
|
|
138 |
'type' => 'file',
|
|
|
139 |
'permission' => '755',
|
|
|
140 |
'owner' => '<default owner>:<default group>',
|
|
|
141 |
'target' => '/usr/local/opnsense/service/conf/actions.d',
|
|
|
142 |
'post action' => 'service configd restart',
|
|
|
143 |
'message' => 'No automatic run can be done. Please log in through the webui and enable the sysinfo cron job'
|
|
|
144 |
},
|
|
|
145 |
},
|
|
|
146 |
},
|
|
|
147 |
|
|
|
148 |
);
|
|
|
149 |
|
|
|
150 |
# list of libraries used by the system. We will offer to install them if
|
|
|
151 |
# we know how. NOTE: I have chosen to put the full installation command
|
|
|
152 |
# for each library. This allows us to use the package selector OR a different
|
|
|
153 |
# piece of code on a per-library basis, but results in something like
|
|
|
154 |
# apt-get -y install perl-modules
|
|
|
155 |
# apt-get -y install libwww-perl
|
|
|
156 |
# instead of
|
|
|
157 |
# apt-get -y install libwww-perl perl-modules
|
|
|
158 |
# flexibility vs efficiency in this case.
|
|
|
159 |
our %libraries = (
|
144 |
rodolico |
160 |
'File::Basename' => {
|
|
|
161 |
'debian' => {
|
|
|
162 |
'command' => 'apt-get -y install',
|
|
|
163 |
'parameter' => 'perl-modules'
|
|
|
164 |
}
|
|
|
165 |
},
|
|
|
166 |
'Exporter' => {
|
|
|
167 |
'debian' => {
|
|
|
168 |
'comand' => 'apt-get -y install',
|
|
|
169 |
'parameter' => 'perl-base'
|
|
|
170 |
},
|
|
|
171 |
},
|
129 |
rodolico |
172 |
'LWP' => {
|
144 |
rodolico |
173 |
'debian' => {
|
|
|
174 |
'command' => 'apt-get -y install',
|
|
|
175 |
'parameter' => 'libwww-perl'
|
|
|
176 |
},
|
|
|
177 |
'freebsd' => {
|
|
|
178 |
'command' => 'echo y | pkg install',
|
|
|
179 |
'parameter' => 'p5-libwww'
|
153 |
rodolico |
180 |
},
|
|
|
181 |
'opnsense' => {
|
|
|
182 |
'command' => 'cpan -i',
|
|
|
183 |
'parameter' => 'LWP'
|
144 |
rodolico |
184 |
}
|
|
|
185 |
},
|
129 |
rodolico |
186 |
'YAML::Tiny' => {
|
144 |
rodolico |
187 |
'debian' => {
|
|
|
188 |
'command' => 'apt-get -y install',
|
|
|
189 |
'parameter' => 'libyaml-tiny-perl',
|
|
|
190 |
},
|
|
|
191 |
'freebsd' => {
|
|
|
192 |
'command' => 'echo y | pkg install',
|
|
|
193 |
'parameter' => 'p5-YAML-Tiny'
|
|
|
194 |
},
|
|
|
195 |
'opnsense' => {
|
|
|
196 |
'command' => 'cpan -i',
|
|
|
197 |
'parameter' => 'YAML::Tiny'
|
|
|
198 |
},
|
|
|
199 |
'ipfire' => {
|
|
|
200 |
'command' => 'cpan -i',
|
|
|
201 |
'parameter' => 'YAML::Tiny'
|
|
|
202 |
}
|
|
|
203 |
},
|
|
|
204 |
'Sys::Syslog' => {
|
|
|
205 |
'debian' => {
|
|
|
206 |
'command' => 'apt-get -y install',
|
|
|
207 |
'parameter' => 'libsys-syslog-perl',
|
|
|
208 |
},
|
|
|
209 |
'freebsd' => {
|
|
|
210 |
'command' => 'echo y | pkg install',
|
|
|
211 |
'parameter' => 'p5-Unix-Syslog',
|
153 |
rodolico |
212 |
},
|
|
|
213 |
'opnsense' => {
|
|
|
214 |
'command' => 'cpan -i',
|
|
|
215 |
'parameter' => 'Unix::Syslog'
|
144 |
rodolico |
216 |
}
|
174 |
rodolico |
217 |
},
|
|
|
218 |
'JSON' => {
|
|
|
219 |
'debian' => {
|
|
|
220 |
'command' => 'apt-get -y install',
|
|
|
221 |
'parameter' => 'libjson-perl'
|
179 |
rodolico |
222 |
},
|
|
|
223 |
'freebsd' => {
|
|
|
224 |
'command' => 'echo y | pkg install',
|
|
|
225 |
'parameter' => 'p5-JSON'
|
|
|
226 |
},
|
|
|
227 |
'opnsense' => {
|
|
|
228 |
'command' => 'cpan -i',
|
|
|
229 |
'parameter' => 'JSON'
|
|
|
230 |
},
|
144 |
rodolico |
231 |
}
|
129 |
rodolico |
232 |
);
|
|
|
233 |
|
|
|
234 |
our %binaries = (
|
144 |
rodolico |
235 |
'dmidecode' => {
|
|
|
236 |
'debian' => {
|
|
|
237 |
'command' => 'apt-get -y install',
|
|
|
238 |
'parameter' => 'dmidecode'
|
|
|
239 |
},
|
|
|
240 |
'freebsd' => {
|
|
|
241 |
'command' => 'echo y | pkg install',
|
|
|
242 |
'parameter' => 'dmidecode'
|
|
|
243 |
},
|
|
|
244 |
'opnsense' => {
|
|
|
245 |
'command' => 'echo y | pkg install',
|
|
|
246 |
'parameter' => 'dmidecode'
|
|
|
247 |
}
|
|
|
248 |
}
|
129 |
rodolico |
249 |
);
|
144 |
rodolico |
250 |
|
|
|
251 |
|
|
|
252 |
# if subroutine &postInstall exists, it is called with a reference to the %install hash
|
|
|
253 |
# postInstall may return, or may call some other script. it is the last thing called by
|
|
|
254 |
# the installer
|
|
|
255 |
sub postInstall {
|
|
|
256 |
my $install = shift;
|
206 |
rodolico |
257 |
my $quiet = shift;
|
144 |
rodolico |
258 |
|
|
|
259 |
# We need to open sysinfoconf so we can build the configuration file
|
|
|
260 |
# using eval, since the installer is responsible for loading YAML::Tiny, so we may not
|
|
|
261 |
# have it defined when we first start up.
|
|
|
262 |
eval( 'use sysinfoconf qw/&writeConfig &makeConfig &showConf/;' );
|
|
|
263 |
|
|
|
264 |
&logIt( 'Entering postInstall to build configuration' );
|
|
|
265 |
# seed configuration, if needed
|
|
|
266 |
if ( $$install{'build config'} ) {
|
|
|
267 |
my $config;
|
|
|
268 |
my @fileList;
|
|
|
269 |
|
|
|
270 |
# the order is important here as, if multiple files exist, latter ones can
|
|
|
271 |
# overwrite values in the previous. We do a push so the first value pushed
|
|
|
272 |
# is processed last, ie has higher priority.
|
|
|
273 |
push @fileList, $install->{'configuration'}->{'old configuration file'};
|
|
|
274 |
push @fileList, $install->{'configuration'}->{'configuration file'};
|
|
|
275 |
|
|
|
276 |
my $seedFile = $install->{'configuration'}->{'configuration seed file'};
|
|
|
277 |
if ( -e $install->{'configuration seed file'} ) {
|
|
|
278 |
push @fileList, $install->{'configuration seed file'};
|
|
|
279 |
} # if preload seed file
|
|
|
280 |
|
161 |
rodolico |
281 |
&logIt( "Order of configuration files is\n\t" . join( "\n\t", @fileList ) . "\n" );
|
|
|
282 |
|
144 |
rodolico |
283 |
$config = &makeConfig( @fileList );
|
|
|
284 |
# if ScriptDirs and moduleDirs not populated, do so from our configuration
|
|
|
285 |
if ( ! $$config{'scriptDirs'} || ! scalar @{ $$config{'scriptDirs'} } ) {
|
|
|
286 |
$config->{'scriptDirs'} = [ $install->{'files'}->{'scripts'}->{'target'} ];
|
|
|
287 |
}
|
|
|
288 |
if ( ! $$config{'moduleDirs'} || ! @{ $$config{'moduleDirs'} } ) {
|
|
|
289 |
$config->{'moduleDirs'} = [ $install->{'files'}->{'modules'}->{'target'} ];
|
|
|
290 |
}
|
|
|
291 |
# We should have a nice combined configuration, so we'll write it to a temporary file
|
|
|
292 |
my $filename = &writeConfig( '', &showConf( $config ) );
|
|
|
293 |
my $confFileName = $install{'configuration'}{'configuration file'};
|
|
|
294 |
# configure.pl is already designed to combine our temp file with our current config file and write it ou
|
|
|
295 |
# so we'll just use that instead of reinventing the wheel
|
206 |
rodolico |
296 |
if ( $quiet ) {
|
|
|
297 |
print "Verify configuration by executing \n$install{bindir}/configure.pl -f $filename -o $confFileName\n"
|
|
|
298 |
} else {
|
|
|
299 |
exec( "$install{bindir}/configure.pl -f $filename -o $confFileName" );
|
|
|
300 |
}
|
144 |
rodolico |
301 |
} # if we are building/merging configuration
|
|
|
302 |
}
|