home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / GUSI 1.4.1 / GUSI / SafeInstall < prev   
Encoding:
Text File  |  1993-07-18  |  1.5 KB  |  75 lines  |  [TEXT/MPS ]

  1. Perl -Sx "{0}" {"Parameters"} > "{TempFolder}SafeInstall.tmp" && "{TempFolder}SafeInstall.tmp"
  2. Exit
  3.  
  4. #!perl
  5. #######################################################################
  6. #    File        :    SafeInstall        -    Install newer files in a folder
  7. #    Author    :    Matthias Neeracher
  8. #    Started    :    17Jul93                                Language    :    MPW Shell/Make
  9. #    Modified    :    17Jul93    MN    
  10. #    Last        :    17Jul93
  11. #######################################################################
  12.  
  13. $y = "-y";
  14.  
  15. while ($arg = shift(@ARGV)) {
  16.     if ($arg eq "-to") {
  17.         $tofolder = ®ularize(shift @ARGV);
  18.     } elsif ($arg eq "-from") {
  19.         $fromfolder = ®ularize(shift @ARGV);
  20.     } elsif ($arg eq "-c") {
  21.         $createfolders = 1;
  22.     } elsif ($arg eq "-y") {
  23.         $y = "";
  24.     } else {
  25.         push(@args, $arg);
  26.     }
  27. }
  28.  
  29. $tofolder || die "No destination folder specified.";
  30.  
  31. &mkdirs($tofolder) if $createfolders;
  32.  
  33. -d $tofolder || die "'$tofolder' is no folder.";
  34.  
  35. while ($arg = shift(@args)) {
  36.     $arg         =~ /([^:]+):?$/;
  37.     $toarg    =    "$tofolder$1";
  38.     $arg         = "$fromfolder$arg" unless ($arg =~ /:/);
  39.     
  40.     -e $arg || die "'$arg' does not exist.";
  41.     
  42.     if (!-e $toarg) {
  43.         print "Duplicate '$arg' '$toarg'\n";
  44.     } elsif ((stat $arg)[9] > (stat $toarg)[9]) {
  45.         print "Duplicate $y '$arg' '$toarg'\n";
  46.     }
  47. }
  48.  
  49. sub mkdirs 
  50. {
  51.     local($dir) = @_;
  52.     
  53.     if (!-d $dir) {
  54.         if ($dir =~ /(.*:)[^:]+:/) {
  55.             &mkdirs($1);
  56.         }
  57.         
  58.         mkdir($dir, 0777) || die "Couldn't create directory \"$dir\"";
  59.     }
  60. }
  61.  
  62. sub regularize
  63. {
  64.     local($dir) = @_;
  65.     
  66.     if ($dir !~ /:/) {
  67.         $dir = ":$dir:";
  68.     } elsif ($dir !~ /:$/) {
  69.         $dir = "$dir:";
  70.     }
  71.     
  72.     $dir;
  73. }
  74.  
  75.