Subversion Repositories camp_sysinfo_client_3

Rev

Rev 20 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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