home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / patchSG0001239.idb / usr / lib / SoftWindows2 / bin / scripts / updisk.pl.z / updisk.pl
Encoding:
Perl Script  |  1996-05-07  |  3.0 KB  |  119 lines

  1. #!/usr/sbin/perl
  2.  
  3. $K=1024;        #1-K
  4. $Meg=$K*$K;        #1-Meg
  5. $XCONFIRM='/usr/bin/X11/xconfirm';
  6.  
  7. $NEW_DISK_SPACE_REQUIRED=90*$K;        #size in Kilobytes needed
  8.  
  9. #return codes
  10. $CREATE_NEW_HD=0;                # 0 - ok create new hard disk
  11. $UPGRADE_FAILED=1;                # 1 - $MV or $CP of old HD failed - reason unknown
  12. $BOOT_OFF_NEW=2;                # 2 - the new is ready to be booted off of
  13. $CONTINUE=3;                    # 3 - Continue back in SWIN
  14. $E_NOSPACE=4;                    # 4 - we are exiting for not enough space -
  15.                                 #      SWIN will give user a 2nd chance here
  16.  
  17. $MV="/sbin/mv";
  18. $CP="/sbin/cp";
  19.  
  20.  
  21. #$name=getpwuid($<);
  22. #$home=(getpwuid($<))[7];
  23. $name=$ENV{"USER"};
  24. $home=$ENV{"HOME"};
  25.  
  26. $OLD_DISK="$home/WIN31-$name.hdf";
  27. $NEW_DISK="$home/WIN311-$name.hdf";
  28.  
  29. Retry:
  30.  
  31. #sanity check
  32. if (-e $NEW_DISK) { exit $BOOT_OFF_NEW; }
  33.  
  34.  
  35. #get free disk space on home device
  36. $_=`/usr/sbin/df -k $home|/bin/tail -1`;
  37. ($free_space)=/.{27}\s*\S+\s+\d+\s+\d+\s+(\d+).*/;
  38.  
  39.  
  40. #find size of old hard disk in K
  41.  
  42. $old_size=((($old_exists=-R $OLD_DISK)?-s $OLD_DISK:0)+$K-1)/$K;
  43.  
  44. if (!$old_exists) {
  45.     #nothing to copy -- do we have enough space to create a new HD?
  46.     if ($NEW_DISK_SPACE_REQUIRED < $free_space) { exit $CREATE_NEW_HD;}
  47.     else {
  48.         exit $E_NOSPACE;
  49.     }
  50. }
  51.  
  52. #old exists, enough space to copy the old?
  53.  
  54. if ($old_size<$free_space) {
  55.     if (system("$CP -p $OLD_DISK $NEW_DISK")) {
  56.         system("rm $NEW_DISK");        #remove any turds
  57.         if ($NEW_DISK_SPACE_REQUIRED < $free_space) { exit $CREATE_NEW_HD; }
  58.         else {
  59.             exit $E_NOSPACE;
  60.         }
  61.     }
  62.     #getting here means $CP succeeded...
  63.     exit $BOOT_OFF_NEW;
  64. }
  65.  
  66. #Ok, we got here...what to do.
  67. #first -- we *could* rename the old
  68. #second, we *might* be able to create a new HD
  69. #third, we offer to exit for them!
  70. if ($NEW_DISK_SPACE_REQUIRED < $free_space) {
  71.     #3 choice popup!
  72.     $prog="$XCONFIRM".' -c -b "Continue" -b "Create" -B "Upgrade" -b "Retry" '.
  73.         '-header "Insufficient Space" '.
  74.         '-t "There is not enough space to make" '.
  75.         '-t "a backup of your current hard disk." '.
  76.         '-t "You can IRREVERSIBLY <Upgrade> your" '.
  77.         '-t "current hard disk, <Create> a new hard" '.
  78.         '-t "disk, or <Continue>." '.
  79.         '-icon question -geometry "360x190"';
  80. } else {
  81.     #2 choice popup
  82.     $prog="$XCONFIRM".' -c -b "Continue" -B " Upgrade" -b "Retry" '.
  83.         '-header "Insufficient Space" '.
  84.         '-t "There is not enough space to make" '.
  85.         '-t "a backup of your current hard disk" '.
  86.         '-t "or to create a new hard disk." '.
  87.         '-t "You can IRREVERSIBLY <Upgrade> your" '.
  88.         '-t "current hard disk, or <Continue> with" '.
  89.         '-t "more options." '.
  90.         '-icon question -geometry "360x190"';
  91. }
  92.  
  93. $_=`$prog`;
  94.  
  95. if (/Upgrade/) {
  96.     if (system("$MV $OLD_DISK $NEW_DISK")) {
  97.         # yuck this failed.  Not much to do
  98.         $prog="$XCONFIRM".' -c -B "Continue" -b "Retry" '.
  99.             '-header "Cannot Rename"" '.
  100.             '-t "Your old hard disk could not be " '.
  101.             '-t "renamed.  This might be a permission" '.
  102.             '-t "problem.  " '.
  103.             '-icon question -geometry "360x190"';
  104.         $_=`$prog`;
  105.  
  106.         if (/Retry/) {
  107.             goto Retry;
  108.         }
  109.         exit $CONTINUE;
  110.     }
  111.     exit $BOOT_OFF_NEW;
  112. } elsif (/Continue/) {
  113.     exit $CONTINUE;
  114. } elsif (/Retry/) {
  115.     goto Retry;
  116. } else {
  117.     exit $CREATE_NEW_HD;
  118. }
  119.