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',
112
                     'files' => {
129 rodolico 113
                              'actions_sysinfo.conf' => {
114
                                    'type' => 'file',
115
                                    'permission' => '755',
116
                                    'owner' => '<default owner>:<default group>',
117
                                    'target' => '/usr/local/opnsense/service/conf/actions.d',
118
                                    'post action' => 'service configd restart',
119
                                    'message' => 'No automatic run can be done. Please log in through the webui and enable the sysinfo cron job'
120
                                 },
121
                              },
122
                 },
123
 
124
                );
125
 
126
# list of libraries used by the system. We will offer to install them if
127
# we know how. NOTE: I have chosen to put the full installation command
128
# for each library. This allows us to use the package selector OR a different
129
# piece of code on a per-library basis, but results in something like
223 rodolico 130
#      apt -y install perl-modules
131
#      apt -y install libwww-perl
129 rodolico 132
# instead of
223 rodolico 133
#      apt -y install libwww-perl perl-modules
129 rodolico 134
# flexibility vs efficiency in this case.
135
our %libraries = ( 
144 rodolico 136
                  'File::Basename' => {
137
                     'debian' => {
223 rodolico 138
                        'command'   => 'apt -y install',
144 rodolico 139
                        'parameter' => 'perl-modules'
140
                     }
141
                  },
142
                  'Exporter' => {
143
                     'debian' => {
223 rodolico 144
                        'comand' => 'apt -y install',
144 rodolico 145
                        'parameter' => 'perl-base'
146
                     },
147
                  },
129 rodolico 148
                  'LWP' => { 
144 rodolico 149
                     'debian' => {
223 rodolico 150
                        'command'   => 'apt -y install',
144 rodolico 151
                        'parameter' => 'libwww-perl'
152
                     },
153
                     'freebsd' => {
154
                        'command'   => 'echo y | pkg install',
155
                        'parameter' => 'p5-libwww'
153 rodolico 156
                     },
157
                     'opnsense' => {
158
                        'command'   => 'cpan -i',
159
                        'parameter' => 'LWP'
144 rodolico 160
                     }
161
                  },
218 rodolico 162
                  'Hash::Merge' => {
163
                     'debian' => {
223 rodolico 164
                        'command'   => 'apt -y install',
218 rodolico 165
                        'parameter' => 'libhash-merge-perl',
166
                     },
167
                     'freebsd' => {
168
                        'command' => 'cpan -i',
169
                        'parameter' => 'Hash::Merge'
170
                     },
171
                     'opnsense' => {
172
                        'command' => 'cpan -i',
173
                        'parameter' => 'Hash::Merge'
174
                     },
175
                     'ipfire' => {
176
                        'command' => 'cpan -i',
177
                        'parameter' => 'Hash::Merge'
178
                     }
179
                  },
129 rodolico 180
                  'YAML::Tiny' => {
144 rodolico 181
                     'debian' => {
223 rodolico 182
                        'command'   => 'apt -y install',
144 rodolico 183
                        'parameter' => 'libyaml-tiny-perl',
184
                     },
185
                     'freebsd' => {
186
                        'command' => 'echo y | pkg install',
187
                        'parameter' => 'p5-YAML-Tiny'
188
                     },
189
                     'opnsense' => {
190
                        'command' => 'cpan -i',
191
                        'parameter' => 'YAML::Tiny'
192
                     },
193
                     'ipfire' => {
194
                        'command' => 'cpan -i',
195
                        'parameter' => 'YAML::Tiny'
196
                     }
197
                  },
198
                  'Sys::Syslog' => {
199
                     'debian' => {
223 rodolico 200
                        'command' => 'apt -y install',
144 rodolico 201
                        'parameter' => 'libsys-syslog-perl',
202
                     },
203
                     'freebsd' => {
204
                        'command' => 'echo y | pkg install',
205
                        'parameter' => 'p5-Unix-Syslog',
153 rodolico 206
                     },
207
                     'opnsense' => {
208
                        'command' => 'cpan -i',
209
                        'parameter' => 'Unix::Syslog'
144 rodolico 210
                     }
174 rodolico 211
                  },
212
                  'JSON' => {
213
                     'debian' => {
223 rodolico 214
                        'command' => 'apt -y install',
174 rodolico 215
                        'parameter' => 'libjson-perl'
179 rodolico 216
                     },
217
                     'freebsd' => {
218
                        'command' => 'echo y | pkg install',
219
                        'parameter' => 'p5-JSON'
220
                     },
221
                    'opnsense' => {
222
                        'command' => 'cpan -i',
223
                        'parameter' => 'JSON'
224
                     },
144 rodolico 225
                  }
129 rodolico 226
                );
227
 
228
our %binaries = (
144 rodolico 229
                  'dmidecode' => {
230
                     'debian' => {
223 rodolico 231
                        'command' => 'apt -y install',
144 rodolico 232
                        'parameter' => 'dmidecode'
233
                     },
234
                     'freebsd' => {
235
                        'command' => 'echo y | pkg install',
236
                        'parameter' => 'dmidecode'
237
                     },
238
                     'opnsense' => {
239
                        'command' => 'echo y | pkg install',
240
                        'parameter' => 'dmidecode'
241
                     }
242
                  }
129 rodolico 243
               );
144 rodolico 244
 
245
 
246
# if subroutine &postInstall exists, it is called with a reference to the %install hash
247
# postInstall may return, or may call some other script. it is the last thing called by
248
# the installer
249
sub postInstall {
250
   my $install = shift;
206 rodolico 251
   my $quiet = shift;
144 rodolico 252
 
253
   # We need to open sysinfoconf so we can build the configuration file
254
   # using eval, since the installer is responsible for loading YAML::Tiny, so we may not
255
   # have it defined when we first start up.
256
   eval( 'use sysinfoconf qw/&writeConfig &makeConfig &showConf/;' );
257
 
258
   &logIt( 'Entering postInstall to build configuration' );
259
   # seed configuration, if needed
260
   if ( $$install{'build config'} ) {
261
      my $config;
262
      my @fileList;
263
 
264
      # the order is important here as, if multiple files exist, latter ones can
265
      # overwrite values in the previous. We do a push so the first value pushed
266
      # is processed last, ie has higher priority.
267
      push @fileList, $install->{'configuration'}->{'old configuration file'};
268
      push @fileList, $install->{'configuration'}->{'configuration file'};
269
 
270
      my $seedFile = $install->{'configuration'}->{'configuration seed file'};
271
      if ( -e $install->{'configuration seed file'} ) {
272
         push @fileList, $install->{'configuration seed file'};
273
      } # if preload seed file
274
 
161 rodolico 275
      &logIt( "Order of configuration files is\n\t" . join( "\n\t", @fileList ) . "\n" );
276
 
144 rodolico 277
      $config = &makeConfig( @fileList );
278
      # if ScriptDirs and moduleDirs not populated, do so from our configuration
279
      if ( ! $$config{'scriptDirs'} || ! scalar @{ $$config{'scriptDirs'} }  ) {
280
         $config->{'scriptDirs'} = [ $install->{'files'}->{'scripts'}->{'target'} ];
281
      }
282
      if ( ! $$config{'moduleDirs'} || ! @{ $$config{'moduleDirs'} }  ) {
283
         $config->{'moduleDirs'} = [ $install->{'files'}->{'modules'}->{'target'} ];
284
      }
285
      # We should have a nice combined configuration, so we'll write it to a temporary file
286
      my $filename = &writeConfig( '', &showConf( $config ) );
287
      my $confFileName = $install{'configuration'}{'configuration file'};
288
      # configure.pl is already designed to combine our temp file with our current config file and write it ou
289
      # so we'll just use that instead of reinventing the wheel
211 rodolico 290
      # just return the command to be used
291
      return "$install{bindir}/configure.pl -t -q -f $filename -o $confFileName";
144 rodolico 292
   } # if we are building/merging configuration
293
}
211 rodolico 294
 
295
1;