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