Subversion Repositories camp_sysinfo_client_3

Rev

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;
4
 
24 rodolico 5
$main::VERSION = '1.1.2';
20 rodolico 6
 
21 rodolico 7
# find our location and use it for searching for libraries
8
BEGIN {
9
   use FindBin;
10
   use File::Spec;
11
   use lib File::Spec->catdir($FindBin::Bin);
12
}
20 rodolico 13
 
21 rodolico 14
use sysinfoconf;
13 rodolico 15
 
21 rodolico 16
my $seedFile = 'sysinfo-client.seed';
17
my $sysinfo2 = '/etc/sysinfo/sysinfo.conf';
13 rodolico 18
 
20 rodolico 19
 
21 rodolico 20
sub moveFiles {
21
   # an extremely basic installer for sysinfo-client
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
33
   for $dir ( 'modules', 'scripts' ) {
34
      `cp -av $dir $binDir`;
35
      `rm -fR $binDir/$dir/.svn`;
36
      `chmod 0700 $binDir/$dir`;
37
      if ( $dir eq 'scripts' ) {
38
         `chmod -fR 0700 $binDir/$dir/*`;
39
      } else {
40
         `chmod -fR 0600 $binDir/$dir/*`;
41
      }
42
   }
43
 
44
   # copy the binary files and the documentation. Default all to
45
   # 0600
22 rodolico 46
   for $file ( 'sysinfo-client','notes', 'sysinfo-client.conf.template','configure.pl', 'uninstall.pl', 'sysinfoconf.pm' ) {
21 rodolico 47
      `cp $file $binDir`;
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
   }
20 rodolico 55
 
21 rodolico 56
   # Everything is owned by root
57
   foreach my $dir ( $binDir, $confDir ) {
23 rodolico 58
      `chown -fR root:root $dir`;
21 rodolico 59
   }
20 rodolico 60
 
10 rodolico 61
}
8 rodolico 62
 
21 rodolico 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;
18 rodolico 70
   }
21 rodolico 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
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 );
10 rodolico 106
}
107
 
21 rodolico 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.
130
   if ( -f $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
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
   }
8 rodolico 137
}
138
 
21 rodolico 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" );
20 rodolico 150
}
8 rodolico 151
 
21 rodolico 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();
20 rodolico 156
}
157
 
24 rodolico 158
exec( "perl $binDir/configure.pl" ) if &yesno( "Would you like to configure the package now? " );
8 rodolico 159