Subversion Repositories camp_sysinfo_client_3

Rev

Rev 208 | Rev 218 | Go to most recent revision | Details | Compare with Previous | 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
129
#      apt-get -y install perl-modules
130
#      apt-get -y install libwww-perl
131
# instead of
132
#      apt-get -y install libwww-perl perl-modules
133
# flexibility vs efficiency in this case.
134
our %libraries = ( 
144 rodolico 135
                  'File::Basename' => {
136
                     'debian' => {
137
                        'command'   => 'apt-get -y install',
138
                        'parameter' => 'perl-modules'
139
                     }
140
                  },
141
                  'Exporter' => {
142
                     'debian' => {
143
                        'comand' => 'apt-get -y install',
144
                        'parameter' => 'perl-base'
145
                     },
146
                  },
129 rodolico 147
                  'LWP' => { 
144 rodolico 148
                     'debian' => {
149
                        'command'   => 'apt-get -y install',
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
                  },
129 rodolico 161
                  'YAML::Tiny' => {
144 rodolico 162
                     'debian' => {
163
                        'command'   => 'apt-get -y install',
164
                        'parameter' => 'libyaml-tiny-perl',
165
                     },
166
                     'freebsd' => {
167
                        'command' => 'echo y | pkg install',
168
                        'parameter' => 'p5-YAML-Tiny'
169
                     },
170
                     'opnsense' => {
171
                        'command' => 'cpan -i',
172
                        'parameter' => 'YAML::Tiny'
173
                     },
174
                     'ipfire' => {
175
                        'command' => 'cpan -i',
176
                        'parameter' => 'YAML::Tiny'
177
                     }
178
                  },
179
                  'Sys::Syslog' => {
180
                     'debian' => {
181
                        'command' => 'apt-get -y install',
182
                        'parameter' => 'libsys-syslog-perl',
183
                     },
184
                     'freebsd' => {
185
                        'command' => 'echo y | pkg install',
186
                        'parameter' => 'p5-Unix-Syslog',
153 rodolico 187
                     },
188
                     'opnsense' => {
189
                        'command' => 'cpan -i',
190
                        'parameter' => 'Unix::Syslog'
144 rodolico 191
                     }
174 rodolico 192
                  },
193
                  'JSON' => {
194
                     'debian' => {
195
                        'command' => 'apt-get -y install',
196
                        'parameter' => 'libjson-perl'
179 rodolico 197
                     },
198
                     'freebsd' => {
199
                        'command' => 'echo y | pkg install',
200
                        'parameter' => 'p5-JSON'
201
                     },
202
                    'opnsense' => {
203
                        'command' => 'cpan -i',
204
                        'parameter' => 'JSON'
205
                     },
144 rodolico 206
                  }
129 rodolico 207
                );
208
 
209
our %binaries = (
144 rodolico 210
                  'dmidecode' => {
211
                     'debian' => {
212
                        'command' => 'apt-get -y install',
213
                        'parameter' => 'dmidecode'
214
                     },
215
                     'freebsd' => {
216
                        'command' => 'echo y | pkg install',
217
                        'parameter' => 'dmidecode'
218
                     },
219
                     'opnsense' => {
220
                        'command' => 'echo y | pkg install',
221
                        'parameter' => 'dmidecode'
222
                     }
223
                  }
129 rodolico 224
               );
144 rodolico 225
 
226
 
227
# if subroutine &postInstall exists, it is called with a reference to the %install hash
228
# postInstall may return, or may call some other script. it is the last thing called by
229
# the installer
230
sub postInstall {
231
   my $install = shift;
206 rodolico 232
   my $quiet = shift;
144 rodolico 233
 
234
   # We need to open sysinfoconf so we can build the configuration file
235
   # using eval, since the installer is responsible for loading YAML::Tiny, so we may not
236
   # have it defined when we first start up.
237
   eval( 'use sysinfoconf qw/&writeConfig &makeConfig &showConf/;' );
238
 
239
   &logIt( 'Entering postInstall to build configuration' );
240
   # seed configuration, if needed
241
   if ( $$install{'build config'} ) {
242
      my $config;
243
      my @fileList;
244
 
245
      # the order is important here as, if multiple files exist, latter ones can
246
      # overwrite values in the previous. We do a push so the first value pushed
247
      # is processed last, ie has higher priority.
248
      push @fileList, $install->{'configuration'}->{'old configuration file'};
249
      push @fileList, $install->{'configuration'}->{'configuration file'};
250
 
251
      my $seedFile = $install->{'configuration'}->{'configuration seed file'};
252
      if ( -e $install->{'configuration seed file'} ) {
253
         push @fileList, $install->{'configuration seed file'};
254
      } # if preload seed file
255
 
161 rodolico 256
      &logIt( "Order of configuration files is\n\t" . join( "\n\t", @fileList ) . "\n" );
257
 
144 rodolico 258
      $config = &makeConfig( @fileList );
259
      # if ScriptDirs and moduleDirs not populated, do so from our configuration
260
      if ( ! $$config{'scriptDirs'} || ! scalar @{ $$config{'scriptDirs'} }  ) {
261
         $config->{'scriptDirs'} = [ $install->{'files'}->{'scripts'}->{'target'} ];
262
      }
263
      if ( ! $$config{'moduleDirs'} || ! @{ $$config{'moduleDirs'} }  ) {
264
         $config->{'moduleDirs'} = [ $install->{'files'}->{'modules'}->{'target'} ];
265
      }
266
      # We should have a nice combined configuration, so we'll write it to a temporary file
267
      my $filename = &writeConfig( '', &showConf( $config ) );
268
      my $confFileName = $install{'configuration'}{'configuration file'};
269
      # configure.pl is already designed to combine our temp file with our current config file and write it ou
270
      # so we'll just use that instead of reinventing the wheel
211 rodolico 271
      # just return the command to be used
272
      return "$install{bindir}/configure.pl -t -q -f $filename -o $confFileName";
144 rodolico 273
   } # if we are building/merging configuration
274
}
211 rodolico 275
 
276
1;