Advertisement
xShub

usb_otg.sh

Feb 16th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.10 KB | None | 0 0
  1. #!/system/bin/sh
  2.  
  3. mountdir=/mnt/Usb_otg
  4.  
  5. # checks number of dirs in media_rw
  6. n=`ls -ld /mnt/media_rw/* | wc -l`
  7.  
  8. # if more than one quits
  9. if [ $n -gt 1 ] ; then echo error: more then one mount point in /mnt/media_rw - exiting && exit 1; fi
  10. if [ $n -lt 1 ] ; then echo error: no mount point in /mnt/media_rw - exiting && exit 1; fi
  11.  
  12. # gets the mount point of the USB OTG pendrive
  13. mountpoint=`ls -d /mnt/media_rw/*`
  14.  
  15. # finds the device name of the pendrive
  16. if [ -d $mountpoint ] ; then device=`mount | grep $mountpoint | cut -d' ' -f1`; fi
  17.  
  18. # check if usb_otg dir exists, if not creates it
  19. if [ ! -d $mountdir ] ; then
  20.     mkdir $mountdir
  21.     chmod 777 $mountdir
  22. fi
  23.  
  24. # unmount mount point
  25. umount $mountpoint
  26.  
  27. if [ $? -ne 0 ] ; then
  28.     echo error: unmouting failed - exiting
  29.     exit 1
  30. fi
  31.  
  32. # checks exit code and re-mounts device on new mount point.
  33. # At last, removes the now empty old mount point
  34. if [ $? -eq 0 ] ; then
  35.         mount $device $mountdir
  36.         if [ $? -ne 0 ] ; then
  37.                 echo error: mouting failed - exiting
  38.                 exit 1
  39.         fi
  40.         rmdir $mountpoint
  41. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement