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
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
                              },
78
                              'modules' => {
79
                                 'type' => 'directory',
80
                                 'permission' => '700', 
81
                                 'owner' => '<default owner>:<default group>', 
82
                                 'target' =>  '<bindir>',
83
                                 'action' => 'chmod 700 *'
84
                              },
85
                              'scripts' => {
86
                                 'type' => 'directory',
87
                                 'permission' => '700', 
88
                                 'owner' => '<default owner>:<default group>', 
89
                                 'target' =>  '<bindir>',
90
                                 'action' => 'chmod 700 *'
91
                              },
92
                     }
93
                  );
94
 
95
# hash to set up os specific rules. these override values in %install when a particular operating
96
# system is detected.
97
our %operatingSystems = (
98
                  'debian' => {
99
                     'regex'  => '(debian|mx|devuan)',
100
                     'bindir' => '/opt/camp/sysinfo-client',
101
                     'confdir' => '/etc/camp/sysinfo-client',
132 rodolico 102
                     'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/cron.daily/sysinfo-client',
129 rodolico 103
                     'modules' => '((linux)|(dpkg)|(unix)|(all))',
104
                  },
105
                  'ipfire' => {
106
                     'regex'  => 'ipfire',
107
                     'bindir' => '/opt/camp/sysinfo-client',
108
                     'confdir' => '/etc/camp/sysinfo-client',
139 rodolico 109
                     'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/fcron.daily/sysinfo-client.fcron',
129 rodolico 110
                     'modules' => '((ipfire)|(unix)|(all))',
111
                  },
112
                  'freebsd' => {
113
                     'regex' => 'freebsd',
114
                     'bindir' => '/usr/local/opt/camp/sysinfo-client',
115
                     'confdir' => '/usr/local/etc/camp/sysinfo-client',
139 rodolico 116
                     'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
129 rodolico 117
                     'modules' => '((bsd)|(unix)|(all))',
118
                    'default group' => 'wheel',
119
                    'default owner' => 'root',
120
                  },
121
                  'opnsense' => {
122
                     'fileexists' => '/conf/config.xml',
123
                     'bindir' => '/usr/local/opt/camp/sysinfo-client',
124
                     'confdir' => '/usr/local/etc/camp/sysinfo-client',
144 rodolico 125
                     #'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
129 rodolico 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'
173
                     }
174
                  },
129 rodolico 175
                  'YAML::Tiny' => {
144 rodolico 176
                     'debian' => {
177
                        'command'   => 'apt-get -y install',
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' => {
195
                        'command' => 'apt-get -y install',
196
                        'parameter' => 'libsys-syslog-perl',
197
                     },
198
                     'freebsd' => {
199
                        'command' => 'echo y | pkg install',
200
                        'parameter' => 'p5-Unix-Syslog',
201
                     }
202
                  }
129 rodolico 203
                );
204
 
205
our %binaries = (
144 rodolico 206
                  'dmidecode' => {
207
                     'debian' => {
208
                        'command' => 'apt-get -y install',
209
                        'parameter' => 'dmidecode'
210
                     },
211
                     'freebsd' => {
212
                        'command' => 'echo y | pkg install',
213
                        'parameter' => 'dmidecode'
214
                     },
215
                     'opnsense' => {
216
                        'command' => 'echo y | pkg install',
217
                        'parameter' => 'dmidecode'
218
                     }
219
                  }
129 rodolico 220
               );
144 rodolico 221
 
222
 
223
# if subroutine &postInstall exists, it is called with a reference to the %install hash
224
# postInstall may return, or may call some other script. it is the last thing called by
225
# the installer
226
sub postInstall {
227
   my $install = shift;
228
 
229
   # We need to open sysinfoconf so we can build the configuration file
230
   # using eval, since the installer is responsible for loading YAML::Tiny, so we may not
231
   # have it defined when we first start up.
232
   eval( 'use sysinfoconf qw/&writeConfig &makeConfig &showConf/;' );
233
 
234
   &logIt( 'Entering postInstall to build configuration' );
235
   # seed configuration, if needed
236
   if ( $$install{'build config'} ) {
237
      my $config;
238
      my @fileList;
239
 
240
      # the order is important here as, if multiple files exist, latter ones can
241
      # overwrite values in the previous. We do a push so the first value pushed
242
      # is processed last, ie has higher priority.
243
      push @fileList, $install->{'configuration'}->{'old configuration file'};
244
      push @fileList, $install->{'configuration'}->{'configuration file'};
245
 
246
      my $seedFile = $install->{'configuration'}->{'configuration seed file'};
247
      if ( -e $install->{'configuration seed file'} ) {
248
         push @fileList, $install->{'configuration seed file'};
249
      } # if preload seed file
250
 
251
      $config = &makeConfig( @fileList );
252
      # if ScriptDirs and moduleDirs not populated, do so from our configuration
253
      if ( ! $$config{'scriptDirs'} || ! scalar @{ $$config{'scriptDirs'} }  ) {
254
         $config->{'scriptDirs'} = [ $install->{'files'}->{'scripts'}->{'target'} ];
255
      }
256
      if ( ! $$config{'moduleDirs'} || ! @{ $$config{'moduleDirs'} }  ) {
257
         $config->{'moduleDirs'} = [ $install->{'files'}->{'modules'}->{'target'} ];
258
      }
259
      # We should have a nice combined configuration, so we'll write it to a temporary file
260
      my $filename = &writeConfig( '', &showConf( $config ) );
261
      my $confFileName = $install{'configuration'}{'configuration file'};
262
      # configure.pl is already designed to combine our temp file with our current config file and write it ou
263
      # so we'll just use that instead of reinventing the wheel
264
      exec( "$install{bindir}/configure.pl -f $filename -o $confFileName" );
265
   } # if we are building/merging configuration
266
}