Subversion Repositories camp_sysinfo_client_3

Rev

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