home *** CD-ROM | disk | FTP | other *** search
/ Chip: Windows 2000 Professional Resource Kit / W2KPRK.iso / apps / perl / ActivePerl.exe / data.z / uninstall.pl < prev    next >
Encoding:
Text File  |  1999-10-14  |  6.0 KB  |  219 lines

  1. #
  2. # Uninstall.pl
  3. #
  4. # Author: Michael Smith (mikes@ActiveState.com)
  5. #
  6. # Copyright ⌐ 1998 ActiveState Tool Corp., all rights reserved.
  7. #
  8. ###########################################################
  9.  
  10. use Win32::Registry;
  11. use File::Find;
  12. use MetabaseConfig;
  13.  
  14. my $data_file = $ARGV[0];
  15. my $ENVIRONMENT_KEY = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
  16.  
  17. ReadData();
  18. UninstallDependents();
  19. Warn();
  20. CleanPath();
  21. RemoveIISVirtDirs();
  22. RemoveIISScriptMaps();
  23. RemoveLinesFromFiles();
  24. RemoveDirectories();
  25. RemoveFiles();
  26. CallInstallShield();
  27. print <<"EOF";
  28. \007
  29. \007
  30. Note: If you intend to re-install ActivePerl, you *must* reboot your system
  31. before doing so.
  32.  
  33. Press any key to exit...
  34. EOF
  35. exit(0);
  36.  
  37. sub ReadData {
  38.     print "Reading uninstall data...\n";
  39.     my $data = '';
  40.     $rv = open(DATA, "<$data_file");
  41.     if($rv) {
  42.         map($data .= $_, <DATA>);
  43.         close(DATA);
  44.         eval($data);
  45.     }else{
  46.         die "Error reading uninstallation data file. Aborting!!";
  47.     }
  48. }
  49.  
  50. sub Warn {
  51.     print "This will uninstall $app_name. Do you wish to continue?\n";
  52.     print "[y|N] ==>";
  53.     my $response = '';
  54.     while(($response = <STDIN>) !~ /^[\nyn]/i){};
  55.     if($response !~ /^y/i) {
  56.         print "Aborting $app_name uninstallation!\n";
  57.         exit(0);
  58.     }
  59. }
  60.  
  61. sub UninstallDependents {
  62.     my $RegObj = 0;
  63.     my $UninstallString = '';
  64.     my $type = 0;
  65.     my $rv = 0;
  66.     
  67.     foreach $dependent (@$dependents) {
  68.         print "$dependent is dependent on $app_name\n" .
  69.                 "and will not function correctly without it.\n" .
  70.                 "Would you like to uninstall $dependent?\n" .
  71.                 "[y|n] ==>";
  72.         while(($response = <STDIN>) !~ /[yn]/i){};
  73.         
  74.         if($response =~ /y/i) {
  75.             $rv = $HKEY_LOCAL_MACHINE->Open("software\\microsoft\\windows\\currentversion\\uninstall\\$dependent", $RegObj);
  76.             if($rv) {
  77.                 $rv = $RegObj->QueryValueEx("UninstallString", $type, $UninstallString);
  78.                 if($rv) {
  79.                     $RegObj->Close();
  80.                     print $UninstallString;
  81.                     print "Uninstalling $dependent...\n";
  82.                     $rv = (system($UninstallString) ? 0 : 1);
  83.                 }
  84.             }
  85.             
  86.             if(!$rv) {
  87.                 print "Error uninstalling $dependent!\n\n";
  88.             }
  89.         }
  90.     }
  91. }
  92.  
  93. sub CleanPath {
  94.     if(@$path_info) {
  95.         print "Cleaning PATH...\n";
  96.         my $path = '';
  97.         if(Win32::IsWinNT) {
  98.             my $Environment = 0;
  99.             if($HKEY_LOCAL_MACHINE->Open($ENVIRONMENT_KEY, $Environment)) {
  100.                 if($Environment->QueryValueEx("PATH", $type, $path)) {
  101.                     for $dir (@$path_info) {
  102.                         $dir =~ s/\\/\\\\/g;
  103.                         $path =~ s/$dir;?//ig;
  104.                     }
  105.                     $Environment->SetValueEx("PATH", -1, $type, $path);
  106.                 }
  107.             }
  108.         } else {
  109.             my $file = "$ENV{'SystemDrive'}/autoexec.bat";
  110.             if(open(FILE, "<$file")) {
  111.                 my @statements = <FILE>;
  112.                 close(FILE);
  113.                 my $path = '';
  114.                 for $statement (@statements) {
  115.                     if($statement =~ /\s+path\s?=/i) {
  116.                         $path = $statement;
  117.                         for $dir (@$path_info) {
  118.                             $dir =~ s/\\/\\\\/g;
  119.                             $path =~ s/$dir;?//ig;
  120.                         }
  121.                     }
  122.                 }
  123.                 if(open(FILE, ">$file")) {
  124.                     print FILE @statements;
  125.                     close(FILE);
  126.                 }
  127.             }
  128.         }
  129.     }
  130. }
  131.  
  132. sub RemoveIISVirtDirs {
  133.     if(@$iis_virt_dir) {
  134.         print "Removing IIS4 virtual directories...\n";
  135.         for $virt_dir (@$iis_virt_dir) {
  136.             $rv = MetabaseConfig::DeleteVirDir(1, $virt_dir);
  137.             if($rv =~ /^Error/i){
  138.                 print "$rv\n";
  139.                 system('pause');
  140.             }
  141.         }
  142.     }
  143. }
  144.  
  145. sub RemoveIISScriptMaps {
  146.     if(keys %$iis_script_map) {
  147.         print "Removing IIS4 script maps...\n";
  148.         my $virt_dir = '';
  149.         for $key (keys %$iis_script_map) {
  150.             print "Virtual Directory ==> $key\n";
  151.             for $script_map (@{$iis_script_map->{$key}}) {
  152.                 print "\t$key ==> $script_map\n";
  153.                 $virt_dir = $key;
  154.                 $virt_dir = ($virt_dir eq '.' ? '' : $virt_dir);
  155.                 $rv = MetabaseConfig::RemoveFileExtMapping(1, $virt_dir, $script_map);
  156.                 if($rv =~ /^Error/i){
  157.                     print "$rv\n";
  158.                     system('pause');
  159.                 }
  160.             }
  161.         }
  162.     }
  163. }
  164.  
  165. sub RemoveLinesFromFiles {
  166.     my $file;
  167.  
  168.     foreach $file (keys %$lines_in_file) {
  169.         open(FILE, "<$file") or next;
  170.         my @lines = <FILE>;
  171.         close(FILE);
  172.         open(FILE, ">$file") or next;
  173. LINE:   foreach $line (@lines) {
  174.             chomp $line;
  175.             for ($offset = 0; $offset <= $#{$$lines_in_file{$file}}; $offset++) {
  176.                 if ($line eq $$lines_in_file{$file}[$offset]) {
  177.                     splice(@{$$lines_in_file{$file}}, $offset, 1);
  178.                     next LINE;
  179.                 }
  180.             }
  181.             print FILE "$line\n";
  182.         }
  183.         close(FILE);
  184.     }
  185. }
  186.  
  187. sub RemoveDirectories {
  188.     if(@$directory) {
  189.         print "Removing directories...\n";
  190.         for $dir (@$directory) {
  191.             finddepth(\&DeleteFiles, $dir);
  192.             rmdir($dir);
  193.         }
  194.     }
  195. }
  196.  
  197. sub RemoveFiles {
  198.     if(@$file) {
  199.         print "Removing files...\n";
  200.         for $file (@$file) {
  201.             unlink($file);
  202.         }
  203.     }
  204. }
  205.  
  206. sub CallInstallShield {
  207.     print "Calling InstallShield...\n";
  208.     system("start $is_uninstall_string");
  209. }
  210.  
  211. sub DeleteFiles {
  212.     if(-d $File::Find::name) {
  213.         rmdir("$File::Find::name");
  214.     } else {
  215.         unlink("$File::Find::name");
  216.     }
  217. }
  218.  
  219.