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 = (
81
                  'debian' => {
82
                     'regex'  => '(debian|mx|devuan)',
83
                     'bindir' => '/opt/camp/sysinfo-client',
84
                     'confdir' => '/etc/camp/sysinfo-client',
132 rodolico 85
                     'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/cron.daily/sysinfo-client',
129 rodolico 86
                     'modules' => '((linux)|(dpkg)|(unix)|(all))',
87
                  },
88
                  'ipfire' => {
89
                     'regex'  => 'ipfire',
90
                     'bindir' => '/opt/camp/sysinfo-client',
91
                     'confdir' => '/etc/camp/sysinfo-client',
139 rodolico 92
                     'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/fcron.daily/sysinfo-client.fcron',
129 rodolico 93
                     'modules' => '((ipfire)|(unix)|(all))',
94
                  },
95
                  'freebsd' => {
96
                     'regex' => 'freebsd',
97
                     'bindir' => '/usr/local/opt/camp/sysinfo-client',
98
                     'confdir' => '/usr/local/etc/camp/sysinfo-client',
139 rodolico 99
                     'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
129 rodolico 100
                     'modules' => '((bsd)|(unix)|(all))',
101
                    'default group' => 'wheel',
102
                    'default owner' => 'root',
103
                  },
104
                  'opnsense' => {
105
                     'fileexists' => '/conf/config.xml',
106
                     'bindir' => '/usr/local/opt/camp/sysinfo-client',
107
                     'confdir' => '/usr/local/etc/camp/sysinfo-client',
108
                     'modules' => '((bsd)|(unix)|(all))',
109
                    'default group' => 'wheel',
110
                    'default owner' => 'root',
111
                    'files' => {
112
                              'actions_sysinfo.conf' => {
113
                                    'type' => 'file',
114
                                    'permission' => '755',
115
                                    'owner' => '<default owner>:<default group>',
116
                                    'target' => '/usr/local/opnsense/service/conf/actions.d',
117
                                    'post action' => 'service configd restart',
118
                                    'message' => 'No automatic run can be done. Please log in through the webui and enable the sysinfo cron job'
119
                                 },
120
                              },
121
                 },
122
 
123
                );
124
 
125
# list of libraries used by the system. We will offer to install them if
126
# we know how. NOTE: I have chosen to put the full installation command
127
# for each library. This allows us to use the package selector OR a different
128
# piece of code on a per-library basis, but results in something like
223 rodolico 129
#      apt -y install perl-modules
130
#      apt -y install libwww-perl
129 rodolico 131
# instead of
223 rodolico 132
#      apt -y install libwww-perl perl-modules
129 rodolico 133
# flexibility vs efficiency in this case.
134
our %libraries = ( 
144 rodolico 135
                  'File::Basename' => {
136
                     'debian' => {
223 rodolico 137
                        'command'   => 'apt -y install',
144 rodolico 138
                        'parameter' => 'perl-modules'
139
                     }
140
                  },
141
                  'Exporter' => {
142
                     'debian' => {
223 rodolico 143
                        'comand' => 'apt -y install',
144 rodolico 144
                        'parameter' => 'perl-base'
145
                     },
146
                  },
129 rodolico 147
                  'LWP' => { 
144 rodolico 148
                     'debian' => {
223 rodolico 149
                        'command'   => 'apt -y install',
144 rodolico 150
                        'parameter' => 'libwww-perl'
151
                     },
152
                     'freebsd' => {
153
                        'command'   => 'echo y | pkg install',
154
                        'parameter' => 'p5-libwww'
153 rodolico 155
                     },
156
                     'opnsense' => {
157
                        'command'   => 'cpan -i',
158
                        'parameter' => 'LWP'
144 rodolico 159
                     }
160
                  },
218 rodolico 161
                  'Hash::Merge' => {
162
                     'debian' => {
223 rodolico 163
                        'command'   => 'apt -y install',
218 rodolico 164
                        'parameter' => 'libhash-merge-perl',
165
                     },
166
                     'freebsd' => {
167
                        'command' => 'cpan -i',
168
                        'parameter' => 'Hash::Merge'
169
                     },
170
                     'opnsense' => {
171
                        'command' => 'cpan -i',
172
                        'parameter' => 'Hash::Merge'
173
                     },
174
                     'ipfire' => {
175
                        'command' => 'cpan -i',
176
                        'parameter' => 'Hash::Merge'
177
                     }
178
                  },
129 rodolico 179
                  'YAML::Tiny' => {
144 rodolico 180
                     'debian' => {
223 rodolico 181
                        'command'   => 'apt -y install',
144 rodolico 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' => {
223 rodolico 199
                        'command' => 'apt -y install',
144 rodolico 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' => {
223 rodolico 213
                        'command' => 'apt -y install',
174 rodolico 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' => {
223 rodolico 230
                        'command' => 'apt -y install',
144 rodolico 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
211 rodolico 289
      # just return the command to be used
290
      return "$install{bindir}/configure.pl -t -q -f $filename -o $confFileName";
144 rodolico 291
   } # if we are building/merging configuration
292
}
211 rodolico 293
 
294
1;