Subversion Repositories camp_sysinfo_client_3

Rev

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