#!/opt/casp/tools/bin/linux2/perl5/bin/perl -I/opt/casp/tools/bin/linux2/perl5/lib -I/opt/casp use INSTALL::common; use INSTALL::query; use INSTALL::odbc; use INSTALL::internaldb; use INSTALL::webserver; use INSTALL::ini; use INSTALL::component; use INSTALL::global; use INSTALL::parameter; use INSTALL::user; use INSTALL::os; use strict; #============================================================================== #------------------------ Make sure that the user is a root #============================================================================== if ($> != 0) { print STDOUT "You will need to be root to execute this script.\n"; exit 1; } #============================================================================== #------------------------ Default global values #============================================================================== my $pOS = \%INSTALL::os::Details; my $pGlobals = \%INSTALL::global::variables; my $pParameters = \%INSTALL::parameter::variables; $pParameters->{asphome} = "/opt/casp"; $pParameters->{com_layer} = "chilicom"; INSTALL::common::set_standard_globals; #============================================================================== #------------------------ The bulk of the uninstall #============================================================================== sub list_components { return(INSTALL::component::list("/opt/casp")); } sub uninstall_component { ($#_ == 0) || die "Invalid number of arguments."; my ($component) = @_; my @component_list = list_components; if (not grep { $_ eq $component } @component_list) { return(undef); } else { my $pComponent = INSTALL::component::open($component,"/opt/casp"); if ($pComponent) { my $result = 1; if ($pComponent->{uninstaller}) { $result = (not system($pComponent->{uninstaller})); } if ($result) { my $result = INSTALL::component::unregister($component,"/opt/casp"); } return($result); } else { return(undef); } } } sub uninstall_components { my @components = @_; my $result = 1; foreach(@components) { if (not uninstall_component($_)) { $result = undef; } } return($result); } sub uninstall { my @components; if (boolean_value($pParameters->{force}) || boolean_value($pParameters->{rpm})) { @components = list_components; $pParameters->{non_interactive} = "true"; my @webserver_list = INSTALL::webserver::load_used_servers; if ($#webserver_list >= 0) { INSTALL::webserver::uninstall(map {$_->{engine_dir}} @webserver_list); } if ($#components >= 0) { unless (uninstall_components(@components)) { note("One or more components returned failure upon uninstall ..."); } } } else { # Interactive REQUERY_UNINSTALL_TYPE: my $uninstall_type = INSTALL::query::user_menu ("Chili!Soft ASP - Uninstall options", "There are two options for the uninstall. You can remove the entire product ". "and all related resources, or you can perform a stage-based uninstall ". "(option 2, below), which allows you to remove some components and retain ". "others. Given the systematic nature and flexibility of the stage-based ". "uninstall, we recommend that you choose this option.", "Choose the uninstall method that you would prefer", "Uninstall the entire product.", "Perform a stage-based uninstall.", "default=Cancel the uninstall." ); if ($uninstall_type == 1) { report("Warning: ", "You have chosen to uninstall this installation of Sun Chili!Soft", "ASP. All associations currently in place between Web servers and ", "ASP Servers will be lost, thereby disabling ASP content ", "for those Web servers. All files currently contained under the ", "installation directory will be deleted. The directory is:", " $pGlobals->{asphome}", ""); if (INSTALL::query::user("Are you sure that you want to proceed", "terminal_mark=?","default=n","y") eq "n") { goto REQUERY_UNINSTALL_TYPE; } if (not fork) { exit(system("$0 force=yes")); } else { print STDERR "Uninstalling all components ... "; INSTALL::common::spinner_wait; print STDERR "\n\n"; exit($?); } } elsif ($uninstall_type == 3) { report("Uninstall canceled."); exit(1); } RETRY_UNINSTALL_COMPONENT: @components = list_components; while($#components >= 0) { my $max_index = $#components + 1; my $component = INSTALL::query::user_menu ("Sun Chili!Soft ASP - Component Uninstall", "Following is a list of installed components. These components must be removed ". "to proceed to the next stage. Components may be removed in any order, and ". "canceling the uninstall at this point will leave remaining portions of the ". "product in their current configurations.", "Component to remove", (map { "$_." } @components), "All components.", "default=Cancel."); if ($component == ($max_index + 1)) { report("Warning: You are about to uninstall all of the components."); my $answer = INSTALL::query::user ("Do you want to continue","terminal_mark=?","y","default=n"); if ($answer eq "n") { goto RETRY_UNINSTALL_COMPONENT; } if (not uninstall_components(@components)) { note("One or more components returned failure during uninstall ..."); print STDERR "Press enter to continue ..."; ; } } elsif ($component == ($max_index + 2)) { note("Uninstall canceled."); return(1); } else { report("Warning: You are about to uninstall the $components[$component - 1]."); my $answer = INSTALL::query::user ("Do you want to continue","terminal_mark=?","y","default=n"); if ($answer eq "n") { goto RETRY_UNINSTALL_COMPONENT; } if (not uninstall_component($components[$component - 1])) { note("The components uninstall script returned failure ..."); print STDERR "Press enter to continue ..."; ; } } @components = list_components; } } while(INSTALL::webserver::list_used_servers) { unless (INSTALL::webserver::uninstall) { note("Uninstall canceled."); return(1); } } INSTALL::odbc::uninstall; INSTALL::internaldb::uninstall; if (not boolean_value($pParameters->{rpm})) { if (not boolean_value($pParameters->{force})) { # Interactive note("The ASP Server directory /opt/casp will now be removed. Be sure", "to remove any data you have stored in this directory structure", "prior to uninstall. You can now cancel the uninstall to", "make backups as desired. After that task has been done,", "it will be safe to re-run the uninstall script."); my $answer = INSTALL::query::user ("Would you like to stop the uninstall","terminal_mark=?","default=y","n"); if ($answer ne "n") { note("Uninstall canceled."); return(1); } } chdir("/opt/casp/.."); recursive_rmdir("/opt/casp"); } ########## Delete the chili_ini entry for this engine. my $pIni = INSTALL::ini::open($pGlobals->{chili_ini}); if ($pIni) { my $pSection = INSTALL::ini::deleteSection($pIni,$pGlobals->{asphome}); if ($pSection) { INSTALL::ini::save($pIni,$pGlobals->{chili_ini}); # note("/opt/casp chili.ini entree successfully removed."); } else { note("/opt/casp successfully removed. However, an error occurred removing", "the /opt/casp section from the $pGlobals->{chili_ini} file"); } } ########## Remove the Sun Chili!Soft ASP user. # if (INSTALL::user::exists("chiliasp")) { # INSTALL::user::del("chiliasp"); #} report("\nSun Chili!Soft ASP: Uninstall successful."); return(1); } #============================================================================== #------------------------ main() #============================================================================== if ($#ARGV >= 0) { my @valid_options = ("force","rpm"); my $invalid_option; foreach(keys %{$pParameters}) { if (not grep { /$_/ } @valid_options) { $invalid_option = 1; last; } } if ($invalid_option) { print("usage: uninstall\n"); print("internal usage: uninstall [force=(yes|no)] [rpm=(yes|no)]\n"); exit(1); } } exit(not uninstall);