Subversion Repositories camp_sysinfo_client_3

Rev

Rev 22 | Rev 24 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#!/usr/bin/env perl

use warnings;

$main::VERSION = '1.1.1';

# find our location and use it for searching for libraries
BEGIN {
   use FindBin;
   use File::Spec;
   use lib File::Spec->catdir($FindBin::Bin);
}

use sysinfoconf;

my $seedFile = 'sysinfo-client.seed';
my $sysinfo2 = '/etc/sysinfo/sysinfo.conf';


sub moveFiles {
   # an extremely basic installer for sysinfo-client

   # create all the directories we need, set permissions
   for $dir ( $binDir, $confDir, @moduleDirs, @scriptDirs ) {
      next if -d $dir;
      `mkdir -p $dir`;
      `chmod 0700 $dir`;
   }
   # copy the modules and scripts
   # all modules start with 0600, and scripts with 0700
   # modules will be "turned on" by setting their permissions to 0700
   # in the osinstall specialty scrips
   for $dir ( 'modules', 'scripts' ) {
      `cp -av $dir $binDir`;
      `rm -fR $binDir/$dir/.svn`;
      `chmod 0700 $binDir/$dir`;
      if ( $dir eq 'scripts' ) {
         `chmod -fR 0700 $binDir/$dir/*`;
      } else {
         `chmod -fR 0600 $binDir/$dir/*`;
      }
   }

   # copy the binary files and the documentation. Default all to
   # 0600
   for $file ( 'sysinfo-client','notes', 'sysinfo-client.conf.template','configure.pl', 'uninstall.pl', 'sysinfoconf.pm' ) {
      `cp $file $binDir`;
      `chmod 0600 $binDir/$file`;
   }

   # Set permissions for the executable files
   for my $file ( "$binDir/sysinfo-client", "$binDir/configure.pl", "$binDir/uninstall.pl" ) {
      `chmod 0700 $file`;
   }
   
   # Everything is owned by root
   foreach my $dir ( $binDir, $confDir ) {
      `chown -fR root:root $dir`;
   }

}

# simply attempts to detect the operating system so we can do OS
# specific actions at the end.   
sub getOperatingSystem {
   my @OSTypes = ( 'ipfire','debian' );
   my $OS = `uname -a`;
   foreach $osType ( @OSTypes ) {
      return $osType if $OS =~ m/$osType/i;
   }
   return '';
} # getOperatingSystem


sub convertSysinfo2 {
   my $client_name;
   my $iMailResults;
   my $mailTo;
   my $mailSubject;
   my $mailCC;
   my $mailBCC;
   my $mailServer;
   my $mailServerPort;
   my $mailFrom;
   my $SENDMAIL;
   my $clientName;
   my $serialNumber;
   my $hostname;
   my $transports = {}; # holds transportation mechanisms
   open SEED, "<$sysinfo2" or die "Could not open $sysinfo2: $!\n";
   my $temp = join( '', <SEED> );
   close SEED;
   eval( $temp );
   if ( $iMailResults ) {
      $temp = {};
      $$temp{'-name-'} = 'SendEmail';
      $$temp{'mailTo'} = $mailTo if $mailTo;
      $$temp{'$mailFrom'} = $mailFrom if $mailFrom;
      $$temp{'mailCC'} = $mailCC if $mailCC;
      $$temp{'mailServer'} = $mailServer if $mailServer;
      $$temp{'mailServer'} .= ":$mailServerPort" if $mailServerPort;
      $$transports{'1'} = $temp;
   }   
   $clientName = $client_name if ( $client_name );
   return ( $clientName,$hostname,$serialNumber,$transports );
}

# for installation, just go and see if we have anything we can grab
# to make a config. We'll do them in a particular order, with each
# subsequent stage overriding the previous one.
# first, look for any old sysinfo2 config, then, look for an existing
# sysinfo3 config, then look for a seed file
sub makeConfig {
   if ( -f $sysinfo2 && &yesno( 'Old sysinfo 2 config exists, load it for defaults' ) ) {
      print "Loading defaults from sysinfo2 config $sysinfo2\n";
      # NOTE: the return values are all placed into globals!!!!
      ( $clientName,$hostname,$serialNumber,$transports ) = &convertSysinfo2();
   }
   # if they have a current sysinfo3 config, see if we can load it
   if ( -f $sysinfo3 && &yesno( 'I found an existing sysinfo3 configuration, Load it? ' ) ) {
      print "Loading defaults from existing config $sysinfo3\n";
      my $client_name;
      open SEED, "<$sysinfo3" or die "Could not open $sysinfo3: $!\n";
      my $temp = join( '', <SEED> );
      close SEED;
      eval( $temp );
   }
   # seed files are expected to be in the correct format already
   # and expected to override everything.
   if ( -f $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
      print "Loading seed file $seedFile\n";
      open SEED, "<$seedFile" or die "Could not open $seedFile: $!\n";
      my $temp = join( '', <SEED> );
      close SEED;
      eval( $temp );
   }
}


&processParameters( @ARGV );

&moveFiles();

if ( &yesno( "Preseed the configuration file?" ) ) {
   &makeConfig();
   print "Writing Config file; run configure.pl to modify it\n";
   &writeConfig( $confDir, $confName, &showConf() );
   #print &showConf();
   #&yesno( "Press enter to continue" );
}

my $os = &getOperatingSystem();
if ( $os && &yesno( "This appears to be an $os system, may I automatically set up a few things" ) ) {
   require "$os.pm";
   &systemSpecificInstall();
}

exec( "$binDir/configure.pl" ) if &yesno( "Would you like to configure the package now? " );