CentOS6.5上MTP讀取Android手機

參考文章:http://www.zavedil.com/software-mtp-support-rhel-6/

要達到讀取安卓手機內容的目的,我們需要安裝go-mtpfs,在這之前,需要先裝上一些基本的配件:

1.yum install bison gcc mercurial libusb-devel

2.如果你的電腦沒有libusb-1.0的話,在安裝過程中會出錯,下面是安裝的鏈接:

http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.9/libusb-1.0.9.tar.bz2

下載到一個/tmp之類的文件夾中,解壓 tar xjvf libu**  ,然後進入該文件夾,依次執行 ./configure ;make;make install(當然這需要在root的身份下)

安裝完之後,還需要配置環境:

export PKG_CONFIG_PATH=/usr/lib/pkgconfig:$PKG_CONFIG_PATH   其中的/usr/lib/不一定是存在pkgconfig的,具體要寫pkgconfig存在的位置

3.安裝go語言包,詳見我的博客“CentOS6.5下安裝golang

4.下載go-mtpfs

    mkdir /tmp/go 
    export GOPATH=/tmp/go
    go get github.com/hanwen/go-mtpfs
    cp /tmp/go/bin/go-mtpfs /usr/bin
    chmod 4755 /usr/bin/go-mtpfs
5.配置掛載:

         chmod 4755 /bin/fusermount

         mkdir  /mnt/phone

         chmod 777 /mnt/phone

       然後在/usr/bin 中新建兩個文件phone-mount.sh 和 phone-unmount.sh 並修改它們的權限爲 777.

       編輯兩個文件的內容:

phone-mount.sh:

#/bin/bash
# Export a suitable path - it is requred by the module, 
# but will not be supplied by the udev:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# Run the mounter as the user who will access the phone - 
# replace USER with your username
su USER -c "/usr/bin/go-mtpfs /mnt/phone &"
# Exiting is important, else udev may hang here forever
exit

phone-unmount.sh:

#/bin/bash
# Export a suitable path
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# Run the FUSE unmounter
/bin/fusermount -u /mnt/phone

       保存後再修改權限爲755。

       最後到/etc/udev/rules.d 文件夾中,新建一個rules文件,當然,如果你之前已經創建或者文件夾裏存在諸如51-android.rules這樣子的文件,那就不用新建了:

進入新建的文件夾,編輯:

SUBSYSTEM=="usb", ATTRS{idVendor}=="AAAA", ATTRS{idProduct}=="BBBB", ACTION=="add", RUN+="/usr/bin/phone-mount.sh"
ENV{ID_VENDOR_ID}=="AAAA", ENV{ID_MODEL_ID}=="BBBB", ACTION=="remove", RUN+="/usr/bin/phone-unmount.sh"

其中 AAAA是你手機的供應商識別嗎,而BBBB是你的手機產品識別碼。你可以用lsusb的指令查看手機的具體ID。


6.寫在後面,至此,重啓後理論上應該就可以即插即用了,不過我出了點小差錯,沒反應。

暈,,,,,所以我只能直接用指令羅,

su USER -c "/usr/bin/go-mtpfs /mnt/phone &"
其中USER記得替換爲你自己的名字,在/mnt/phone裏面終於出現我想要的東西。好吧,至少目的達到,不能即插即用的原因有待排查。

發佈了20 篇原創文章 · 獲贊 12 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章