#!/usr/bin/php -q
<?
 # Description:
 # Mount a USB Flash device
 #
 # Author:	Aaron J. Swank
 #
 # Date:  	2005-07-29 
 #
 # Notes:
 #	Returns mountpoint on success, FAILED if Not Successful
 # Modification Log:
 # 08022005	Dave Bim-Merle	Changed to return -1 for failure, 
 #				0 for /mnt/lgrflash0, 1 for /mnt/lgrflash1

 # CONSTANTS
 # -----------
   # Script Return Values
   #  $failure = 'FAILED';
     $failure   = 0;
     $flash0ret = 1;
     $flash1ret = 2;
   # Errors returned from mount
     $_err_is_mounted = 'already mounted on /mnt/lgrflash';

   # Flash Mount Points
     $flash0 = '/mnt/lgrflash0';
     $flash1 = '/mnt/lgrflash1';

 # MOUNT DRIVE
 # --------------

 # Attempt to Mount the flash drive under /dev/sda1, lgrflash0
   $command = "/bin/mount $flash0  2>&1";
   $result = exec($command, $out, $err);


   if ( $err )  // there was an error
    {
      # If the drive is already mounted on sda1, return success   
      if (strpos($result, $_err_is_mounted) )
      {
       echo $flash0ret;
       exit;
      }

    }
    else
    {
     # Drive was mounted, and there were no errors
       echo $flash0ret;
       exit;
    }

  # If we made it here, then 
  # there were errors and drive was not already mounted

  # Attempt to mount under /dev/sdb1, lgrflash1
   $command = "/bin/mount $flash1  2>&1";
   $result = exec($command, $out, $err);

   if ( $err )  // there was an error
    {
      # If the drive is already mounted on sdb1, return success   
      if (strpos($result, $_err_is_mounted) )
      {
       echo $flash1ret;
       exit;
      }

    }
    else
    {
     # Drive was mounted, and there were no errors
       echo $flash1ret;
       exit;
    }

#  If we make it this far, we FAILED
   echo $failure;
   exit;

?>
