Subversion Repositories camp_sysinfo_client_3

Rev

Details | Last modification | View Log | RSS feed

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