Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # 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
- # NO WARRANTY AT ALL! THIS MAY WORK OR NOT! THIS MAY BREAK YOUR SYSTEM OR NOT!
- # - jniklast on android-hilfe.de
- echo "This script will automatically configure udev and go-mtpfs for use with Nexus 4 MTP"
- 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!"
- if [ -e "/media/Nexus4" ]
- then
- echo "Mountpoint /media/Nexus4 already exists!"
- 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!"
- exit 1
- fi
- echo "Please enter your login name:"
- read username
- echo "Adjusting fuse.conf..."
- sudo chmod a+r /etc/fuse.conf
- cat /etc/fuse.conf | sed 's/\#user_allow_other/user_allow_other/' > fuse.conf
- sudo mv fuse.conf /etc/fuse.conf
- echo "Installing dependencies..."
- sudo apt-get install libmtp-dev git golang
- echo "Getting go-mtpfs..."
- mkdir /tmp/go
- export GOPATH=/tmp/go
- go get github.com/hanwen/go-mtpfs
- echo "Installing go-mtpfs..."
- sudo mv /tmp/go/bin/go-mtpfs /usr/local/sbin/go-mtpfs
- sudo chmod a+x /usr/local/sbin/go-mtpfs
- echo "Creating mountpoint /media/Nexus4..."
- sudo mkdir /media/Nexus4
- sudo chmod 777 /media/Nexus4
- echo "Creating udev rules..."
- echo "# Google Nexus 4 16 Gb MTP mode (multimedia device)
- SUBSYSTEM==\"usb\", ATTR{idVendor}==\"18d1\", ATTR{idProduct}==\"4ee1\", MODE=\"0666\" # MTP media
- SUBSYSTEM==\"usb\", ATTR{idVendor}==\"18d1\", ATTR{idProduct}==\"4ee2\", MODE=\"0666\" # MTP media with USB debug on
- # Google Nexus 4 MTP mode : automatic mount when plugged
- 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\"
- 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\"
- # Google Nexus 4 MTP mode : automatic unmount when unplugged
- ENV{ID_MODEL}==\"Nexus_4\", ENV{ID_MODEL_ID}==\"4ee1\", ACTION==\"remove\", RUN+=\"/bin/umount /media/Nexus4\"
- ENV{ID_MODEL}==\"Nexus_4\", ENV{ID_MODEL_ID}==\"4ee2\", ACTION==\"remove\", RUN+=\"/bin/umount /media/Nexus4\" " > 99-Nexus4-rules.d
- sudo mv 99-Nexus4-rules.d /etc/udev/rules.d/99-Nexus4-rules.d
- echo "Restarting udev..."
- sudo service udev restart
- echo "Adding Nexus 4 to fstab..."
- cat /etc/fstab > fstab
- echo "# Nexus 4
- DeviceFs(Nexus\0404) /media/Nexus4 fuse.DeviceFs(Nexus\0404) allow_other,rw,user,noauto 0 0" >> fstab
- sudo mv fstab /etc/fstab
- echo "Finished!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement