home *** CD-ROM | disk | FTP | other *** search
/ ftp.sberbank.sumy.ua / 2014.11.ftp.sberbank.sumy.ua.tar / ftp.sberbank.sumy.ua / incoming / sxtech / check_sw_fw.pl < prev    next >
Perl Script  |  2014-08-29  |  2KB  |  127 lines

  1. #!/usr/bin/perl -w
  2. #
  3. # $Revision: #1 $
  4. #
  5. # upgrade_swfw - perform upgrade of switch firmware
  6. #
  7.  
  8. use    Carp;
  9. use    IO::Handle;
  10. use    File::Basename;
  11.  
  12. require "stat.pl";
  13. require "getopts.pl";
  14.  
  15. $opt_G          = 0;            # GUI mode
  16. $outputfile     = "/var/log/eq_upgrade.log";
  17.  
  18.  
  19. sub get_answer {
  20.     my $ans = "x";
  21.     chop($ans = <STDIN>);
  22.     return($ans);
  23. }
  24.  
  25. #
  26. # cark - cark it
  27. #
  28.  
  29. sub cark {
  30.     my $arg = shift;
  31.     print "**** Fatal error.\n";
  32.     print "**** Please contact CoyotePoint customer support.\n";
  33.     die "$arg";
  34. }
  35.  
  36. #
  37. # sis - perform `system' function and croak if non-zero result.
  38. #
  39.  
  40. sub sis {
  41.     my $arg = shift or &cark("");
  42.  
  43.     #
  44.     # This is perl-ass-backwards, if you can imagine what that is.
  45.     #
  46.     system $arg and sleep 1 and &cark("\n");
  47. }
  48.  
  49. #
  50. # switch_firmware
  51. #    
  52.     sub switch_firmware {
  53.     my $lfirm = "";
  54.         my $cfirm = "";
  55.     my $fw_ok = 0;
  56.     my @latest = (0, 0);
  57.         my @current = (0, 0);
  58.  
  59.         open SW, "/usr/l7up/swconfig -d 2>&1 |" or &cark("$!\n");
  60.  
  61.         while (<SW>) {
  62.             if (/(Latest)/) {
  63.                $lfirm = $_;
  64.            @latest = split(/\t/, $lfirm);
  65.             }
  66.             if (/(Current)/) {
  67.                $cfirm = $_;
  68.                @current = split(/\t/, $cfirm);
  69.             }
  70.         }
  71.         close SW;
  72.     
  73.         if ($current[1] < $latest[1]) {
  74.             print "\nWARNING: This upgrade contains firmware which\n";
  75.         print "requires an immediate reboot after installation.\n";
  76.             print "If you proceed, a system reboot will be automatically\n";
  77.         print "performed when the upgrade is complete.\n"; 
  78.         $fw_ok = 1;
  79.         }   
  80.     else {
  81.         $fw_ok = 0;
  82.     }    
  83.     flush STDOUT;
  84.     flush STDERR;
  85.     sleep 1;
  86.     return $fw_ok;
  87.     }    
  88.     
  89.   
  90. #    
  91. # main
  92. #    
  93.     sub main {
  94.         my $gx = 0;    # Indicates GX platform
  95.     my $fw_ok = 0;    
  96.         &Getopts('G');
  97.             
  98.     if ($opt_G) {
  99.         open(STDOUT, '>>'.$outputfile ) or die $!;
  100.         open(STDERR, '>>'.$outputfile ) or die $!;
  101.     }                        
  102.         select(STDOUT); $| = 1; 
  103.         select(STDERR); $| = 1;
  104.         
  105.     #
  106.     # See if this is a gx platform
  107.     #
  108.     open IN, "/usr/local/sbin/lm -h -U 2>&1 |" or &cark("$!\n");
  109.  
  110.         while (<IN>) {
  111.             if (/^(e[2346]50)gx-?/) {
  112.                 $gx = 1;
  113.             }
  114.         }
  115.     
  116.     #
  117.     # Check switch firmware level 
  118.     #
  119.     if ($gx) {
  120.         $fw_ok = &switch_firmware;
  121.     }    
  122.     
  123.     exit $fw_ok;
  124.     }
  125.  
  126.     &main;
  127.