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
                     }
216
                  }
129 rodolico 217
                );
218
 
219
our %binaries = (
144 rodolico 220
                  'dmidecode' => {
221
                     'debian' => {
222
                        'command' => 'apt-get -y install',
223
                        'parameter' => 'dmidecode'
224
                     },
225
                     'freebsd' => {
226
                        'command' => 'echo y | pkg install',
227
                        'parameter' => 'dmidecode'
228
                     },
229
                     'opnsense' => {
230
                        'command' => 'echo y | pkg install',
231
                        'parameter' => 'dmidecode'
232
                     }
233
                  }
129 rodolico 234
               );
144 rodolico 235
 
236
 
237
# if subroutine &postInstall exists, it is called with a reference to the %install hash
238
# postInstall may return, or may call some other script. it is the last thing called by
239
# the installer
240
sub postInstall {
241
   my $install = shift;
242
 
243
   # We need to open sysinfoconf so we can build the configuration file
244
   # using eval, since the installer is responsible for loading YAML::Tiny, so we may not
245
   # have it defined when we first start up.
246
   eval( 'use sysinfoconf qw/&writeConfig &makeConfig &showConf/;' );
247
 
248
   &logIt( 'Entering postInstall to build configuration' );
249
   # seed configuration, if needed
250
   if ( $$install{'build config'} ) {
251
      my $config;
252
      my @fileList;
253
 
254
      # the order is important here as, if multiple files exist, latter ones can
255
      # overwrite values in the previous. We do a push so the first value pushed
256
      # is processed last, ie has higher priority.
257
      push @fileList, $install->{'configuration'}->{'old configuration file'};
258
      push @fileList, $install->{'configuration'}->{'configuration file'};
259
 
260
      my $seedFile = $install->{'configuration'}->{'configuration seed file'};
261
      if ( -e $install->{'configuration seed file'} ) {
262
         push @fileList, $install->{'configuration seed file'};
263
      } # if preload seed file
264
 
161 rodolico 265
      &logIt( "Order of configuration files is\n\t" . join( "\n\t", @fileList ) . "\n" );
266
 
144 rodolico 267
      $config = &makeConfig( @fileList );
268
      # if ScriptDirs and moduleDirs not populated, do so from our configuration
269
      if ( ! $$config{'scriptDirs'} || ! scalar @{ $$config{'scriptDirs'} }  ) {
270
         $config->{'scriptDirs'} = [ $install->{'files'}->{'scripts'}->{'target'} ];
271
      }
272
      if ( ! $$config{'moduleDirs'} || ! @{ $$config{'moduleDirs'} }  ) {
273
         $config->{'moduleDirs'} = [ $install->{'files'}->{'modules'}->{'target'} ];
274
      }
275
      # We should have a nice combined configuration, so we'll write it to a temporary file
276
      my $filename = &writeConfig( '', &showConf( $config ) );
277
      my $confFileName = $install{'configuration'}{'configuration file'};
278
      # configure.pl is already designed to combine our temp file with our current config file and write it ou
279
      # so we'll just use that instead of reinventing the wheel
280
      exec( "$install{bindir}/configure.pl -f $filename -o $confFileName" );
281
   } # if we are building/merging configuration
282
}