Subversion Repositories camp_sysinfo_client_3

Rev

Blame | Last modification | View Log | RSS feed

#!/usr/bin/env perl

use warnings;

my $thisDir = `pwd`;
chomp $thisDir;

my $targetDir = '/opt/camp/sysinfo-client';
my $modulesDir = $targetDir . '/modules';
my $scriptsDir = $targetDir . '/scripts';
my $confDir = '/etc/camp/sysinfo-client';

# an extremely basic installer for sysinfo-client


# prompt the user for a response, then allow them to enter it
# the first response is considered the default and is printed
# in all caps if more than one exists
# first answer is used if they simply press the Enter
# key. The response is returned all lower case if more than one
# exists.
# it is assumed 
sub getAnswer {
   my ( $prompt, @answers ) = @_;
   my $default = $answers[0];
   my $onlyOneAnswer = scalar( @answers ) == 1;
   print $prompt . '[ ';
   $answers[0] = uc $answers[0] unless $onlyOneAnswer;
   print join( ' | ', @answers ) . ' ]: ';
   $thisAnswer = <>;
   chomp $thisAnswer;
   $thisAnswer = $default unless $thisAnswer;
   return $thisAnswer;
}

sub yesno {
   my $prompt = shift;
   my $answer = &getAnswer( $prompt, ('yes','no' ) );
   return lc( substr( $answer, 0, 1 ) ) eq 'y';
}

if ( &yesno( "I am getting ready to remove sysinfo-client from the system\nOk?" ) ) {
   my $removeConfig = &yesno( "Do you want me to remove the configuration also?" );
   print "Uninstalling ";
   print "and removing config" if $removeConfig;
   `rm -fRv $targetDir`;
   `rm -fRv $confDir` if $removeConfig;
   `rm /etc/fcron.daily/sysinfo.cron` if -e '/etc/fcron.daily/sysinfo.cron';
   `rm /etc/cron.daily/sysinfo` if -e '/etc/cron.daily/sysinfo';
   `rm /usr/local/bin/sysinfo-client` if -e '/usr/local/bin/sysinfo-client';
   print "Standard sysinfo-client removed\n";
} else {
   print "Uninstalled aborted\n"
}

exit 1;