Subversion Repositories camp_sysinfo_client_3

Rev

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