| 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
 | 
        
           | 249 | rodolico | 8 | #
 | 
        
           |  |  | 9 | # 20241224 RWR
 | 
        
           |  |  | 10 | # added wget as a binary to check for, since not installed by default on freebsd
 | 
        
           | 203 | rodolico | 11 | our %install = (  
 | 
        
           |  |  | 12 |                   'bindir' => '/opt/camp/sysinfo-client',
 | 
        
           |  |  | 13 |                   'confdir' => '/etc/camp/sysinfo-client',
 | 
        
           |  |  | 14 |                   'application name' => 'sysinfo client',
 | 
        
           |  |  | 15 |                   'default group' => 'root',
 | 
        
           |  |  | 16 |                   'default owner' => 'root',
 | 
        
           |  |  | 17 |                   'default permission' => '0700',
 | 
        
           |  |  | 18 |                   'configuration seed file' => '<installdir>/sysinfo-client.seed.yaml',
 | 
        
           |  |  | 19 |                   'configuration' => {
 | 
        
           | 129 | rodolico | 20 |                           'configurator' => '<bindir>/configure.pl',
 | 
        
           |  |  | 21 |                           'configuration file' => '<confdir>/sysinfo-client.yaml',
 | 
        
           |  |  | 22 |                           'old configuration file' => '<confdir>/sysinfo-client.conf',
 | 
        
           |  |  | 23 |                           'permission' => '700',
 | 
        
           |  |  | 24 |                           'owner'      => '<default owner>',
 | 
        
           |  |  | 25 |                           'target'     => '<confdir>'
 | 
        
           |  |  | 26 |                             },
 | 
        
           |  |  | 27 |                  'files' => {
 | 
        
           |  |  | 28 |                            'configure.pl' => { 
 | 
        
           |  |  | 29 |                                  'type' => 'file',
 | 
        
           |  |  | 30 |                                  'permission' => '700', 
 | 
        
           |  |  | 31 |                                  'owner' => '<default owner>:<default group>', 
 | 
        
           |  |  | 32 |                                  'target' =>  '<bindir>'
 | 
        
           |  |  | 33 |                               },
 | 
        
           |  |  | 34 |                            'sysinfo-client' => { 
 | 
        
           |  |  | 35 |                                  'type' => 'file',
 | 
        
           |  |  | 36 |                                  'permission' => '700',
 | 
        
           |  |  | 37 |                                  'owner' => '<default owner>:<default group>',
 | 
        
           |  |  | 38 |                                  'target' =>  '<bindir>'
 | 
        
           |  |  | 39 |                               },
 | 
        
           |  |  | 40 |                            'sysinfoconf.pm' => {
 | 
        
           |  |  | 41 |                                  'type' => 'file',
 | 
        
           |  |  | 42 |                                  'permission' => '600',
 | 
        
           |  |  | 43 |                                  'owner' => '<default owner>:<default group>',
 | 
        
           |  |  | 44 |                                  'target' =>  '<bindir>'
 | 
        
           |  |  | 45 |                               },
 | 
        
           | 208 | rodolico | 46 |                            'installer' => {
 | 
        
           |  |  | 47 |                                  'type' => 'directory',
 | 
        
           | 129 | rodolico | 48 |                                  'permission' => '700', 
 | 
        
           |  |  | 49 |                                  'owner' => '<default owner>:<default group>', 
 | 
        
           |  |  | 50 |                                  'target' =>  '<bindir>' 
 | 
        
           |  |  | 51 |                               },
 | 
        
           |  |  | 52 |                            'VERSION' => { 
 | 
        
           |  |  | 53 |                                  'type' => 'file',
 | 
        
           |  |  | 54 |                                  'permission' => '600', 
 | 
        
           |  |  | 55 |                                  'owner' => '<default owner>:<default group>', 
 | 
        
           |  |  | 56 |                                  'target' =>  '<bindir>' 
 | 
        
           |  |  | 57 |                               },
 | 
        
           | 160 | rodolico | 58 |                            'SYSTEM_VERSION' => { 
 | 
        
           |  |  | 59 |                                  'type' => 'file',
 | 
        
           |  |  | 60 |                                  'permission' => '755', 
 | 
        
           | 129 | rodolico | 61 |                                  'owner' => '<default owner>:<default group>', 
 | 
        
           | 160 | rodolico | 62 |                                  'target' =>  '<bindir>' 
 | 
        
           |  |  | 63 |                            },
 | 
        
           |  |  | 64 |                            'modules' => {
 | 
        
           |  |  | 65 |                               'type' => 'directory',
 | 
        
           |  |  | 66 |                               'permission' => '700', 
 | 
        
           |  |  | 67 |                               'owner' => '<default owner>:<default group>', 
 | 
        
           |  |  | 68 |                               'target' =>  '<bindir>',
 | 
        
           |  |  | 69 |                               'action' => 'chmod 700 *'
 | 
        
           |  |  | 70 |                            },
 | 
        
           |  |  | 71 |                            'scripts' => {
 | 
        
           |  |  | 72 |                               'type' => 'directory',
 | 
        
           |  |  | 73 |                               'permission' => '700', 
 | 
        
           |  |  | 74 |                               'owner' => '<default owner>:<default group>', 
 | 
        
           |  |  | 75 |                               'target' =>  '<bindir>',
 | 
        
           |  |  | 76 |                               'action' => 'chmod 700 *'
 | 
        
           |  |  | 77 |                            },
 | 
        
           | 129 | rodolico | 78 |                      }
 | 
        
           |  |  | 79 |                   );
 | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 | # hash to set up os specific rules. these override values in %install when a particular operating
 | 
        
           |  |  | 82 | # system is detected.
 | 
        
           |  |  | 83 | our %operatingSystems = (
 | 
        
           | 224 | rodolico | 84 |                   'configuration file' => '<confdir>/sysinfo-client.yaml',
 | 
        
           | 129 | rodolico | 85 |                   'debian' => {
 | 
        
           |  |  | 86 |                      'regex'  => '(debian|mx|devuan)',
 | 
        
           |  |  | 87 |                      'bindir' => '/opt/camp/sysinfo-client',
 | 
        
           |  |  | 88 |                      'confdir' => '/etc/camp/sysinfo-client',
 | 
        
           | 132 | rodolico | 89 |                      'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/cron.daily/sysinfo-client',
 | 
        
           | 129 | rodolico | 90 |                      'modules' => '((linux)|(dpkg)|(unix)|(all))',
 | 
        
           |  |  | 91 |                   },
 | 
        
           |  |  | 92 |                   'ipfire' => {
 | 
        
           |  |  | 93 |                      'regex'  => 'ipfire',
 | 
        
           |  |  | 94 |                      'bindir' => '/opt/camp/sysinfo-client',
 | 
        
           |  |  | 95 |                      'confdir' => '/etc/camp/sysinfo-client',
 | 
        
           | 139 | rodolico | 96 |                      'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/fcron.daily/sysinfo-client.fcron',
 | 
        
           | 129 | rodolico | 97 |                      'modules' => '((ipfire)|(unix)|(all))',
 | 
        
           |  |  | 98 |                   },
 | 
        
           |  |  | 99 |                   'freebsd' => {
 | 
        
           |  |  | 100 |                      'regex' => 'freebsd',
 | 
        
           |  |  | 101 |                      'bindir' => '/usr/local/opt/camp/sysinfo-client',
 | 
        
           |  |  | 102 |                      'confdir' => '/usr/local/etc/camp/sysinfo-client',
 | 
        
           | 139 | rodolico | 103 |                      'crontab' => 'ln -fs <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
 | 
        
           | 129 | rodolico | 104 |                      'modules' => '((bsd)|(unix)|(all))',
 | 
        
           | 224 | rodolico | 105 |                      'default group' => 'wheel',
 | 
        
           |  |  | 106 |                      'default owner' => 'root',
 | 
        
           | 129 | rodolico | 107 |                   },
 | 
        
           |  |  | 108 |                   'opnsense' => {
 | 
        
           |  |  | 109 |                      'fileexists' => '/conf/config.xml',
 | 
        
           |  |  | 110 |                      'bindir' => '/usr/local/opt/camp/sysinfo-client',
 | 
        
           |  |  | 111 |                      'confdir' => '/usr/local/etc/camp/sysinfo-client',
 | 
        
           |  |  | 112 |                      'modules' => '((bsd)|(unix)|(all))',
 | 
        
           | 224 | rodolico | 113 |                      'default group' => 'wheel',
 | 
        
           |  |  | 114 |                      'default owner' => 'root',
 | 
        
           | 225 | rodolico | 115 |                      'crontab' => 'chown wheel:root <scriptdir>/actions_sysinfo.conf && ' . 
 | 
        
           |  |  | 116 |                                   'chmod 755 <scriptdir>/actions_sysinfo.conf && ' . 
 | 
        
           | 226 | rodolico | 117 |                                   'cp -a <scriptdir>/actions_sysinfo.conf /usr/local/opnsense/service/conf/actions.d/ && ' .
 | 
        
           | 225 | rodolico | 118 |                                   'service configd restart',
 | 
        
           |  |  | 119 |                      'message' => 'No automatic run can be done. Please log in through the webui and enable the sysinfo cron job'
 | 
        
           | 129 | rodolico | 120 |                  },
 | 
        
           |  |  | 121 |   | 
        
           |  |  | 122 |                 );
 | 
        
           |  |  | 123 |   | 
        
           |  |  | 124 | # list of libraries used by the system. We will offer to install them if
 | 
        
           |  |  | 125 | # we know how. NOTE: I have chosen to put the full installation command
 | 
        
           |  |  | 126 | # for each library. This allows us to use the package selector OR a different
 | 
        
           |  |  | 127 | # piece of code on a per-library basis, but results in something like
 | 
        
           | 223 | rodolico | 128 | #      apt -y install perl-modules
 | 
        
           |  |  | 129 | #      apt -y install libwww-perl
 | 
        
           | 129 | rodolico | 130 | # instead of
 | 
        
           | 223 | rodolico | 131 | #      apt -y install libwww-perl perl-modules
 | 
        
           | 129 | rodolico | 132 | # flexibility vs efficiency in this case.
 | 
        
           |  |  | 133 | our %libraries = ( 
 | 
        
           | 144 | rodolico | 134 |                   'File::Basename' => {
 | 
        
           |  |  | 135 |                      'debian' => {
 | 
        
           | 223 | rodolico | 136 |                         'command'   => 'apt -y install',
 | 
        
           | 144 | rodolico | 137 |                         'parameter' => 'perl-modules'
 | 
        
           |  |  | 138 |                      }
 | 
        
           |  |  | 139 |                   },
 | 
        
           |  |  | 140 |                   'Exporter' => {
 | 
        
           |  |  | 141 |                      'debian' => {
 | 
        
           | 223 | rodolico | 142 |                         'comand' => 'apt -y install',
 | 
        
           | 144 | rodolico | 143 |                         'parameter' => 'perl-base'
 | 
        
           |  |  | 144 |                      },
 | 
        
           |  |  | 145 |                   },
 | 
        
           | 129 | rodolico | 146 |                   'LWP' => { 
 | 
        
           | 144 | rodolico | 147 |                      'debian' => {
 | 
        
           | 223 | rodolico | 148 |                         'command'   => 'apt -y install',
 | 
        
           | 144 | rodolico | 149 |                         'parameter' => 'libwww-perl'
 | 
        
           |  |  | 150 |                      },
 | 
        
           |  |  | 151 |                      'freebsd' => {
 | 
        
           |  |  | 152 |                         'command'   => 'echo y | pkg install',
 | 
        
           |  |  | 153 |                         'parameter' => 'p5-libwww'
 | 
        
           | 153 | rodolico | 154 |                      },
 | 
        
           |  |  | 155 |                      'opnsense' => {
 | 
        
           |  |  | 156 |                         'command'   => 'cpan -i',
 | 
        
           |  |  | 157 |                         'parameter' => 'LWP'
 | 
        
           | 144 | rodolico | 158 |                      }
 | 
        
           |  |  | 159 |                   },
 | 
        
           | 218 | rodolico | 160 |                   'Hash::Merge' => {
 | 
        
           |  |  | 161 |                      'debian' => {
 | 
        
           | 223 | rodolico | 162 |                         'command'   => 'apt -y install',
 | 
        
           | 218 | rodolico | 163 |                         'parameter' => 'libhash-merge-perl',
 | 
        
           |  |  | 164 |                      },
 | 
        
           |  |  | 165 |                      'freebsd' => {
 | 
        
           |  |  | 166 |                         'command' => 'cpan -i',
 | 
        
           |  |  | 167 |                         'parameter' => 'Hash::Merge'
 | 
        
           |  |  | 168 |                      },
 | 
        
           |  |  | 169 |                      'opnsense' => {
 | 
        
           |  |  | 170 |                         'command' => 'cpan -i',
 | 
        
           |  |  | 171 |                         'parameter' => 'Hash::Merge'
 | 
        
           |  |  | 172 |                      },
 | 
        
           |  |  | 173 |                      'ipfire' => {
 | 
        
           |  |  | 174 |                         'command' => 'cpan -i',
 | 
        
           |  |  | 175 |                         'parameter' => 'Hash::Merge'
 | 
        
           |  |  | 176 |                      }
 | 
        
           |  |  | 177 |                   },
 | 
        
           | 129 | rodolico | 178 |                   'YAML::Tiny' => {
 | 
        
           | 144 | rodolico | 179 |                      'debian' => {
 | 
        
           | 223 | rodolico | 180 |                         'command'   => 'apt -y install',
 | 
        
           | 144 | rodolico | 181 |                         'parameter' => 'libyaml-tiny-perl',
 | 
        
           |  |  | 182 |                      },
 | 
        
           |  |  | 183 |                      'freebsd' => {
 | 
        
           |  |  | 184 |                         'command' => 'echo y | pkg install',
 | 
        
           |  |  | 185 |                         'parameter' => 'p5-YAML-Tiny'
 | 
        
           |  |  | 186 |                      },
 | 
        
           |  |  | 187 |                      'opnsense' => {
 | 
        
           |  |  | 188 |                         'command' => 'cpan -i',
 | 
        
           |  |  | 189 |                         'parameter' => 'YAML::Tiny'
 | 
        
           |  |  | 190 |                      },
 | 
        
           |  |  | 191 |                      'ipfire' => {
 | 
        
           |  |  | 192 |                         'command' => 'cpan -i',
 | 
        
           |  |  | 193 |                         'parameter' => 'YAML::Tiny'
 | 
        
           |  |  | 194 |                      }
 | 
        
           |  |  | 195 |                   },
 | 
        
           |  |  | 196 |                   'Sys::Syslog' => {
 | 
        
           |  |  | 197 |                      'debian' => {
 | 
        
           | 223 | rodolico | 198 |                         'command' => 'apt -y install',
 | 
        
           | 144 | rodolico | 199 |                         'parameter' => 'libsys-syslog-perl',
 | 
        
           |  |  | 200 |                      },
 | 
        
           |  |  | 201 |                      'freebsd' => {
 | 
        
           |  |  | 202 |                         'command' => 'echo y | pkg install',
 | 
        
           |  |  | 203 |                         'parameter' => 'p5-Unix-Syslog',
 | 
        
           | 153 | rodolico | 204 |                      },
 | 
        
           |  |  | 205 |                      'opnsense' => {
 | 
        
           |  |  | 206 |                         'command' => 'cpan -i',
 | 
        
           |  |  | 207 |                         'parameter' => 'Unix::Syslog'
 | 
        
           | 144 | rodolico | 208 |                      }
 | 
        
           | 174 | rodolico | 209 |                   },
 | 
        
           |  |  | 210 |                   'JSON' => {
 | 
        
           |  |  | 211 |                      'debian' => {
 | 
        
           | 223 | rodolico | 212 |                         'command' => 'apt -y install',
 | 
        
           | 174 | rodolico | 213 |                         'parameter' => 'libjson-perl'
 | 
        
           | 179 | rodolico | 214 |                      },
 | 
        
           |  |  | 215 |                      'freebsd' => {
 | 
        
           |  |  | 216 |                         'command' => 'echo y | pkg install',
 | 
        
           |  |  | 217 |                         'parameter' => 'p5-JSON'
 | 
        
           |  |  | 218 |                      },
 | 
        
           |  |  | 219 |                     'opnsense' => {
 | 
        
           |  |  | 220 |                         'command' => 'cpan -i',
 | 
        
           |  |  | 221 |                         'parameter' => 'JSON'
 | 
        
           |  |  | 222 |                      },
 | 
        
           | 144 | rodolico | 223 |                   }
 | 
        
           | 129 | rodolico | 224 |                 );
 | 
        
           |  |  | 225 |   | 
        
           |  |  | 226 | our %binaries = (
 | 
        
           | 144 | rodolico | 227 |                   'dmidecode' => {
 | 
        
           |  |  | 228 |                      'debian' => {
 | 
        
           | 223 | rodolico | 229 |                         'command' => 'apt -y install',
 | 
        
           | 144 | rodolico | 230 |                         'parameter' => 'dmidecode'
 | 
        
           |  |  | 231 |                      },
 | 
        
           |  |  | 232 |                      'freebsd' => {
 | 
        
           |  |  | 233 |                         'command' => 'echo y | pkg install',
 | 
        
           |  |  | 234 |                         'parameter' => 'dmidecode'
 | 
        
           |  |  | 235 |                      },
 | 
        
           |  |  | 236 |                      'opnsense' => {
 | 
        
           |  |  | 237 |                         'command' => 'echo y | pkg install',
 | 
        
           |  |  | 238 |                         'parameter' => 'dmidecode'
 | 
        
           |  |  | 239 |                      }
 | 
        
           | 249 | rodolico | 240 |                   },
 | 
        
           |  |  | 241 |                   'wget' => {
 | 
        
           |  |  | 242 |                      'debian' => {
 | 
        
           |  |  | 243 |                         'command' => 'apt -y install',
 | 
        
           |  |  | 244 |                         'parameter' => 'wget',
 | 
        
           |  |  | 245 |                      },
 | 
        
           |  |  | 246 |                      'freebsd' => { 
 | 
        
           |  |  | 247 |                         'command' => 'echo y | pkg install',
 | 
        
           |  |  | 248 |                         'parameter' => 'wget',
 | 
        
           |  |  | 249 |                      },
 | 
        
           |  |  | 250 |                      'opnsense' => { 
 | 
        
           |  |  | 251 |                         'command' => 'echo y | pkg install',
 | 
        
           |  |  | 252 |                         'parameter' => 'wget',
 | 
        
           |  |  | 253 |                      },
 | 
        
           |  |  | 254 |                   },
 | 
        
           | 129 | rodolico | 255 |                );
 | 
        
           | 144 | rodolico | 256 |   | 
        
           |  |  | 257 |   | 
        
           |  |  | 258 | # if subroutine &postInstall exists, it is called with a reference to the %install hash
 | 
        
           |  |  | 259 | # postInstall may return, or may call some other script. it is the last thing called by
 | 
        
           |  |  | 260 | # the installer
 | 
        
           |  |  | 261 | sub postInstall {
 | 
        
           |  |  | 262 |    my $install = shift;
 | 
        
           | 206 | rodolico | 263 |    my $quiet = shift;
 | 
        
           | 144 | rodolico | 264 |   | 
        
           |  |  | 265 |    # We need to open sysinfoconf so we can build the configuration file
 | 
        
           |  |  | 266 |    # using eval, since the installer is responsible for loading YAML::Tiny, so we may not
 | 
        
           |  |  | 267 |    # have it defined when we first start up.
 | 
        
           |  |  | 268 |    eval( 'use sysinfoconf qw/&writeConfig &makeConfig &showConf/;' );
 | 
        
           |  |  | 269 |   | 
        
           |  |  | 270 |    &logIt( 'Entering postInstall to build configuration' );
 | 
        
           |  |  | 271 |    # seed configuration, if needed
 | 
        
           |  |  | 272 |    if ( $$install{'build config'} ) {
 | 
        
           |  |  | 273 |       my $config;
 | 
        
           |  |  | 274 |       my @fileList;
 | 
        
           |  |  | 275 |   | 
        
           |  |  | 276 |       # the order is important here as, if multiple files exist, latter ones can
 | 
        
           |  |  | 277 |       # overwrite values in the previous. We do a push so the first value pushed
 | 
        
           |  |  | 278 |       # is processed last, ie has higher priority.
 | 
        
           |  |  | 279 |       push @fileList, $install->{'configuration'}->{'old configuration file'};
 | 
        
           |  |  | 280 |       push @fileList, $install->{'configuration'}->{'configuration file'};
 | 
        
           |  |  | 281 |   | 
        
           |  |  | 282 |       my $seedFile = $install->{'configuration'}->{'configuration seed file'};
 | 
        
           |  |  | 283 |       if ( -e $install->{'configuration seed file'} ) {
 | 
        
           |  |  | 284 |          push @fileList, $install->{'configuration seed file'};
 | 
        
           |  |  | 285 |       } # if preload seed file
 | 
        
           |  |  | 286 |   | 
        
           | 161 | rodolico | 287 |       &logIt( "Order of configuration files is\n\t" . join( "\n\t", @fileList ) . "\n" );
 | 
        
           |  |  | 288 |   | 
        
           | 144 | rodolico | 289 |       $config = &makeConfig( @fileList );
 | 
        
           |  |  | 290 |       # if ScriptDirs and moduleDirs not populated, do so from our configuration
 | 
        
           |  |  | 291 |       if ( ! $$config{'scriptDirs'} || ! scalar @{ $$config{'scriptDirs'} }  ) {
 | 
        
           |  |  | 292 |          $config->{'scriptDirs'} = [ $install->{'files'}->{'scripts'}->{'target'} ];
 | 
        
           |  |  | 293 |       }
 | 
        
           |  |  | 294 |       if ( ! $$config{'moduleDirs'} || ! @{ $$config{'moduleDirs'} }  ) {
 | 
        
           |  |  | 295 |          $config->{'moduleDirs'} = [ $install->{'files'}->{'modules'}->{'target'} ];
 | 
        
           |  |  | 296 |       }
 | 
        
           |  |  | 297 |       # We should have a nice combined configuration, so we'll write it to a temporary file
 | 
        
           |  |  | 298 |       my $filename = &writeConfig( '', &showConf( $config ) );
 | 
        
           |  |  | 299 |       my $confFileName = $install{'configuration'}{'configuration file'};
 | 
        
           |  |  | 300 |       # configure.pl is already designed to combine our temp file with our current config file and write it ou
 | 
        
           |  |  | 301 |       # so we'll just use that instead of reinventing the wheel
 | 
        
           | 211 | rodolico | 302 |       # just return the command to be used
 | 
        
           |  |  | 303 |       return "$install{bindir}/configure.pl -t -q -f $filename -o $confFileName";
 | 
        
           | 144 | rodolico | 304 |    } # if we are building/merging configuration
 | 
        
           |  |  | 305 | }
 | 
        
           | 211 | rodolico | 306 |   | 
        
           |  |  | 307 | 1;
 |