Skip to content

Instantly share code, notes, and snippets.

@kamawanu
Last active October 2, 2015 03:34
Show Gist options
  • Save kamawanu/5cde69f40ea3a1e8c085 to your computer and use it in GitHub Desktop.
Save kamawanu/5cde69f40ea3a1e8c085 to your computer and use it in GitHub Desktop.
#!/bin/bash -x
TMP=/tmp/$$
mkdir $TMP
trap "/bin/rm -rf $TMP" 0 3 6 9 15
lsusb | (
if [ $# -gt 0 ]
then
fgrep $1
else
cat
fi
) | cut -d: -f2- > $TMP/ids
awk '{print $2}' $TMP/ids > $TMP/devid
FOUND=$( wc -l < $TMP/devid )
#echo $?
if [ $FOUND -gt 1 ]
then
echo many device found
exit
fi
##exit
MAJ=$( cat $TMP/devid | cut -d: -f1 )
MIN=$( cat $TMP/devid | cut -d: -f2 )
cut -c15- $TMP/ids > $TMP/hw
HWNAME=$( cat $TMP/hw )
#HWPATH=$( cut -d/ -f1 < $TMP/hw | sed -e 's/([^)])//g' | tr " " "_" )
HWPATH=$MAJ-$MIN
ls /etc/udev/rules.d/
(
#echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\"18d1\", ATTR{idProduct}==\"$MAJ\", MODE=\"0666\" # $HW "
#echo "ENV{ID_MODEL}==\"$HWNAME\", ENV{ID_MODEL_ID}==\"$MAJ\", ACTION==\"add\", RUN+=\"/usr/bin/mtpfs -o allow_other /media/$HWPATH\""
#echo "ENV{ID_MODEL}==\"$HWNAME\", ENV{ID_MODEL_ID}==\"$MAJ\", ACTION==\"remove\", RUN+=\"/bin/umount /media/$HWPATH\""
#http://stackoverflow.com/questions/15055304/unable-to-mount-samsung-android-in-ubuntu
echo "ATTR{idVendor}==\"$MAJ\", ATTR{idProduct}==\"$MIN\", SYMLINK+=\"libmtp-%k\", MODE=\"660\", GROUP=\"audio\", ENV{ID_MTP_DEVICE}=\"1\", ENV{ID_MEDIA_PLAYER}=\"1\""
) > $TMP/udev
#mkdir -p /media/$HWPATH
#chmod 0 /media/$HWPATH
UNIQ=$( md5sum $TMP/udev | awk '{print $1}' )
sudo rm -fv /etc/udev/rules/51-android-$MAJ-$MIN-*
sudo cp $TMP/udev /etc/udev/rules.d/51-android-$MAJ-$MIN-$UNIQ.rules
echo "mtpfs /media/$MAJ-$MIN fuse.mtpfs allow_other,rw,user,noauto 0 0" #>> /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment