Advertisement
Guest User

Untitled

a guest
Dec 21st, 2012
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.82 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script enables proper MTP suppoert for the Nexus 4 on Ubuntu. Credit to http://bernaerts.dyndns.org/linux/247-ubuntu-automount-nexus7-mtp for the actual guide
  4. # NO WARRANTY AT ALL! THIS MAY WORK OR NOT! THIS MAY BREAK YOUR SYSTEM OR NOT!
  5. # - jniklast on android-hilfe.de
  6.  
  7. echo "This script will automatically configure udev and go-mtpfs for use with Nexus 4 MTP"
  8. read -p "Although this script should, at worst, overwrite any existing 99-Nexus4-rules.d file, THERE IS ABSOLUTELY NO WARRANTY! THIS MAY NOT WORK OR EVEN BREAK YOUR SYSTEM! PLEASE PRESS Ctrl+C IF YOU DON'T KNOW WHAT YOU ARE DOING!"
  9.  
  10. if [ -e "/media/Nexus4" ]
  11. then
  12. echo "Mountpoint /media/Nexus4 already exists!"
  13. echo "It seems you have already run this script! If you haven't and you know what you are doing, please rmdir /media/Nexus4 and run this script again!"
  14. exit 1
  15. fi
  16.  
  17.  
  18. echo "Please enter your login name:"
  19. read username
  20. echo "Adjusting fuse.conf..."
  21. sudo chmod a+r /etc/fuse.conf
  22. cat /etc/fuse.conf | sed 's/\#user_allow_other/user_allow_other/' > fuse.conf
  23. sudo mv fuse.conf /etc/fuse.conf
  24.  
  25. echo "Installing dependencies..."
  26. sudo apt-get install libmtp-dev git golang
  27.  
  28. echo "Getting go-mtpfs..."
  29. mkdir /tmp/go
  30. export GOPATH=/tmp/go
  31. go get github.com/hanwen/go-mtpfs
  32.  
  33. echo "Installing go-mtpfs..."
  34. sudo mv /tmp/go/bin/go-mtpfs /usr/local/sbin/go-mtpfs
  35. sudo chmod a+x /usr/local/sbin/go-mtpfs
  36.  
  37. echo "Creating mountpoint /media/Nexus4..."
  38. sudo mkdir /media/Nexus4
  39. sudo chmod 777 /media/Nexus4
  40.  
  41. echo "Creating udev rules..."
  42. echo "# Google Nexus 4 16 Gb MTP mode (multimedia device)
  43. SUBSYSTEM==\"usb\", ATTR{idVendor}==\"18d1\", ATTR{idProduct}==\"4ee1\", MODE=\"0666\" # MTP media
  44. SUBSYSTEM==\"usb\", ATTR{idVendor}==\"18d1\", ATTR{idProduct}==\"4ee2\", MODE=\"0666\" # MTP media with USB debug on
  45.  
  46. # Google Nexus 4 MTP mode : automatic mount when plugged
  47. ENV{ID_MODEL}==\"Nexus_4\", ENV{ID_MODEL_ID}==\"4ee1\", ACTION==\"add\", RUN+=\"/usr/bin/sudo -u $username /usr/local/sbin/go-mtpfs -allow-other=true /media/Nexus4\"
  48. ENV{ID_MODEL}==\"Nexus_4\", ENV{ID_MODEL_ID}==\"4ee2\", ACTION==\"add\", RUN+=\"/usr/bin/sudo -u $username /usr/local/sbin/go-mtpfs -allow-other=true /media/Nexus4\"
  49.  
  50. # Google Nexus 4 MTP mode : automatic unmount when unplugged
  51. ENV{ID_MODEL}==\"Nexus_4\", ENV{ID_MODEL_ID}==\"4ee1\", ACTION==\"remove\", RUN+=\"/bin/umount /media/Nexus4\"
  52. ENV{ID_MODEL}==\"Nexus_4\", ENV{ID_MODEL_ID}==\"4ee2\", ACTION==\"remove\", RUN+=\"/bin/umount /media/Nexus4\" " > 99-Nexus4-rules.d
  53. sudo mv 99-Nexus4-rules.d /etc/udev/rules.d/99-Nexus4-rules.d
  54.  
  55. echo "Restarting udev..."
  56. sudo service udev restart
  57.  
  58. echo "Adding Nexus 4 to fstab..."
  59. cat /etc/fstab > fstab
  60. echo "# Nexus 4
  61. DeviceFs(Nexus\0404)    /media/Nexus4   fuse.DeviceFs(Nexus\0404)   allow_other,rw,user,noauto  0   0" >> fstab
  62. sudo mv fstab /etc/fstab
  63.  
  64. echo "Finished!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement