Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 rodolico 1
#!/usr/bin/env perl
8 rodolico 2
 
16 rodolico 3
use warnings;
26 rodolico 4
use strict;  
16 rodolico 5
 
26 rodolico 6
our $VERSION = '1.1.2';
20 rodolico 7
 
21 rodolico 8
# find our location and use it for searching for libraries
9
BEGIN {
10
   use FindBin;
11
   use File::Spec;
12
   use lib File::Spec->catdir($FindBin::Bin);
13
}
20 rodolico 14
 
21 rodolico 15
use sysinfoconf;
13 rodolico 16
 
21 rodolico 17
my $seedFile = 'sysinfo-client.seed';
18
my $sysinfo2 = '/etc/sysinfo/sysinfo.conf';
13 rodolico 19
 
20 rodolico 20
 
21 rodolico 21
sub moveFiles {
22
   # an extremely basic installer for sysinfo-client
23
 
24
   # create all the directories we need, set permissions
25
   for $dir ( $binDir, $confDir, @moduleDirs, @scriptDirs ) {
26
      next if -d $dir;
27
      `mkdir -p $dir`;
28
      `chmod 0700 $dir`;
29
   }
30
   # copy the modules and scripts
31
   # all modules start with 0600, and scripts with 0700
32
   # modules will be "turned on" by setting their permissions to 0700
33
   # in the osinstall specialty scrips
34
   for $dir ( 'modules', 'scripts' ) {
35
      `cp -av $dir $binDir`;
36
      `rm -fR $binDir/$dir/.svn`;
37
      `chmod 0700 $binDir/$dir`;
38
      if ( $dir eq 'scripts' ) {
39
         `chmod -fR 0700 $binDir/$dir/*`;
40
      } else {
41
         `chmod -fR 0600 $binDir/$dir/*`;
42
      }
43
   }
44
 
45
   # copy the binary files and the documentation. Default all to
46
   # 0600
22 rodolico 47
   for $file ( 'sysinfo-client','notes', 'sysinfo-client.conf.template','configure.pl', 'uninstall.pl', 'sysinfoconf.pm' ) {
21 rodolico 48
      `cp $file $binDir`;
49
      `chmod 0600 $binDir/$file`;
50
   }
51
 
52
   # Set permissions for the executable files
53
   for my $file ( "$binDir/sysinfo-client", "$binDir/configure.pl", "$binDir/uninstall.pl" ) {
54
      `chmod 0700 $file`;
55
   }
20 rodolico 56
 
21 rodolico 57
   # Everything is owned by root
58
   foreach my $dir ( $binDir, $confDir ) {
23 rodolico 59
      `chown -fR root:root $dir`;
21 rodolico 60
   }
20 rodolico 61
 
10 rodolico 62
}
8 rodolico 63
 
21 rodolico 64
# simply attempts to detect the operating system so we can do OS
65
# specific actions at the end.   
66
sub getOperatingSystem {
67
   my @OSTypes = ( 'ipfire','debian' );
68
   my $OS = `uname -a`;
69
   foreach $osType ( @OSTypes ) {
70
      return $osType if $OS =~ m/$osType/i;
18 rodolico 71
   }
21 rodolico 72
   return '';
73
} # getOperatingSystem
74
 
75
 
76
sub convertSysinfo2 {
77
   my $client_name;
78
   my $iMailResults;
79
   my $mailTo;
80
   my $mailSubject;
81
   my $mailCC;
82
   my $mailBCC;
83
   my $mailServer;
84
   my $mailServerPort;
85
   my $mailFrom;
86
   my $SENDMAIL;
87
   my $clientName;
88
   my $serialNumber;
89
   my $hostname;
90
   my $transports = {}; # holds transportation mechanisms
91
   open SEED, "<$sysinfo2" or die "Could not open $sysinfo2: $!\n";
92
   my $temp = join( '', <SEED> );
93
   close SEED;
94
   eval( $temp );
95
   if ( $iMailResults ) {
96
      $temp = {};
97
      $$temp{'-name-'} = 'SendEmail';
98
      $$temp{'mailTo'} = $mailTo if $mailTo;
99
      $$temp{'$mailFrom'} = $mailFrom if $mailFrom;
100
      $$temp{'mailCC'} = $mailCC if $mailCC;
101
      $$temp{'mailServer'} = $mailServer if $mailServer;
102
      $$temp{'mailServer'} .= ":$mailServerPort" if $mailServerPort;
103
      $$transports{'1'} = $temp;
104
   }   
105
   $clientName = $client_name if ( $client_name );
106
   return ( $clientName,$hostname,$serialNumber,$transports );
10 rodolico 107
}
108
 
21 rodolico 109
# for installation, just go and see if we have anything we can grab
110
# to make a config. We'll do them in a particular order, with each
111
# subsequent stage overriding the previous one.
112
# first, look for any old sysinfo2 config, then, look for an existing
113
# sysinfo3 config, then look for a seed file
114
sub makeConfig {
115
   if ( -f $sysinfo2 && &yesno( 'Old sysinfo 2 config exists, load it for defaults' ) ) {
116
      print "Loading defaults from sysinfo2 config $sysinfo2\n";
117
      # NOTE: the return values are all placed into globals!!!!
118
      ( $clientName,$hostname,$serialNumber,$transports ) = &convertSysinfo2();
119
   }
120
   # if they have a current sysinfo3 config, see if we can load it
121
   if ( -f $sysinfo3 && &yesno( 'I found an existing sysinfo3 configuration, Load it? ' ) ) {
122
      print "Loading defaults from existing config $sysinfo3\n";
123
      my $client_name;
124
      open SEED, "<$sysinfo3" or die "Could not open $sysinfo3: $!\n";
125
      my $temp = join( '', <SEED> );
126
      close SEED;
127
      eval( $temp );
128
   }
129
   # seed files are expected to be in the correct format already
130
   # and expected to override everything.
131
   if ( -f $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
132
      print "Loading seed file $seedFile\n";
133
      open SEED, "<$seedFile" or die "Could not open $seedFile: $!\n";
134
      my $temp = join( '', <SEED> );
135
      close SEED;
136
      eval( $temp );
137
   }
8 rodolico 138
}
139
 
21 rodolico 140
 
141
&processParameters( @ARGV );
142
 
143
&moveFiles();
144
 
145
if ( &yesno( "Preseed the configuration file?" ) ) {
146
   &makeConfig();
147
   print "Writing Config file; run configure.pl to modify it\n";
148
   &writeConfig( $confDir, $confName, &showConf() );
149
   #print &showConf();
150
   #&yesno( "Press enter to continue" );
20 rodolico 151
}
8 rodolico 152
 
21 rodolico 153
my $os = &getOperatingSystem();
154
if ( $os && &yesno( "This appears to be an $os system, may I automatically set up a few things" ) ) {
155
   require "$os.pm";
156
   &systemSpecificInstall();
20 rodolico 157
}
158
 
24 rodolico 159
exec( "perl $binDir/configure.pl" ) if &yesno( "Would you like to configure the package now? " );
8 rodolico 160