Skip to content

Commit 4f92227

Browse files
committed
Consolidate to one file.
- Functionalizes the program - Cleanup code. - Add nice messages
1 parent 0460a82 commit 4f92227

File tree

4 files changed

+172
-108
lines changed

4 files changed

+172
-108
lines changed

README

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11

2-
This script is for creating the nessecery usb rules for ubuntu 10.10
2+
This script is for creating the nessecery usb rules for udev
33
to allow most Android powerered devices to connect
4+
(Though all i've seen do anyway)
45

5-
To run the script fallow the fallowing directions
6+
To run the script follow the following directions
67

78
1) Allow files to execute, run commands in the terminal
8-
$ chmod u+rx rules.sh
9-
$ chmod create_android_rules.sh
9+
$ chmod u+rx create-rules.sh
1010

11-
2) Execute files, run commands in the terminal
12-
$ . create_android_rules.sh
13-
14-
3) You will be promted for your password
11+
2) Execute files, run commands in the terminal with root priveleges
12+
$ sudo ./create-rules.sh
1513

1614
4) Congratulations you have all the Google presribed manufatures device permisions
1715

create-rules.sh

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#!/bin/bash
2+
3+
USBVendorIDs=(0502 0b05 413c 0489 04c5 04c5 091e 18d1 109b 0bb4 12d1 24e3 2116 0482 17ef 1004 22b8
4+
0409 2080 0955 2257 10a9 1d4d 0471 04da 05c6 1f53 04e8 04dd 054c 0fce 2340 0930 19d2)
5+
6+
Vendors=(Acer ASUS Dell Foxconn Fujitsu Fujitsu-Toshiba Garmin-Asus Google Hisense HTC Huawei K-Touch KT-Tech Kyocera Lenovo LG Motorola NEC Nook Nvidia OTGV Pantech Pegatron Philips PMC-Sierra Qualcomm SK-Telesys Samsung Sharp Sony Sony-Ericsson Teleepoch Toshiba ZTE)
7+
8+
9+
DIR=/etc/udev/rules.d
10+
FILE=51-android.rules
11+
CONONICAL=$DIR/$FILE
12+
ADB=''
13+
14+
welcomeMessage(){
15+
16+
17+
18+
echo "##########################################################"
19+
echo "# #"
20+
echo "# Add device permisions to the udev rules by LinuxMotion #"
21+
echo "# #"
22+
echo "# Updated: November 7 2012 #"
23+
echo "# #"
24+
echo "# #"
25+
echo "##########################################################"
26+
}
27+
28+
29+
30+
exists()
31+
{
32+
if command -v $1 &>/dev/null
33+
then
34+
# echo " Yes, command :$1: was found."
35+
return 0
36+
else
37+
# echo " No, command :$1: was NOT found."
38+
return 1
39+
fi
40+
}
41+
42+
killadbserver(){
43+
44+
45+
echo "# Adb found, killing the adb server #"
46+
echo "# #"
47+
$ADB kill-server
48+
echo "# #"
49+
echo "# Please unplug and replug any currently connected devices #"
50+
echo "# Press enter to continue #"
51+
read pause
52+
echo "# #"
53+
$ADB devices
54+
echo "# #"
55+
echo "############################################################"
56+
57+
$ADB devices
58+
59+
60+
}
61+
62+
createRules(){
63+
64+
echo "# #"
65+
echo "# #"
66+
echo "# Creating the 51-android.rules file in the #"
67+
echo "# $DIR directory #"
68+
echo "# #"
69+
echo "# This file containes the permisions for udev #"
70+
echo "# #"
71+
echo "# #"
72+
73+
74+
touch $CONONICAL
75+
welcomeMessage > $CONONICAL
76+
counter=0
77+
for i in "${USBVendorIDs[@]}"
78+
do
79+
CREATE=`echo "SUBSYSTEM==\"usb\", SYSFS{idVendor}==\"$i\", MODE=\"0666\" #${Vendors[counter]}" >> $CONONICAL`
80+
counter=$[$counter+1]
81+
$CREATE 2> /dev/null
82+
done
83+
84+
sudo chmod +x $CONONICAL
85+
86+
}
87+
88+
89+
90+
rootTest(){
91+
if [ "$(whoami)" != "root" ]; then
92+
echo "Sorry, you are not root."
93+
echo "Please run again with sudo."
94+
exit 1
95+
fi
96+
97+
echo "# Root privleges found #"
98+
echo "# #"
99+
100+
}
101+
102+
restartServices(){
103+
104+
if [ -f $CONONICAL ]
105+
then
106+
echo "# #"
107+
echo "# The file was created succesfully #"
108+
echo "# Restarting udev to read the new rules #"
109+
echo "# #"
110+
echo "# #"
111+
sudo service udev restart >> /dev/null
112+
else
113+
echo "# #"
114+
echo "# #"
115+
echo "# Your files was not created, please run again #"
116+
echo "# #"
117+
echo "# #"
118+
echo "##########################################################"
119+
exit -1
120+
121+
fi
122+
123+
adbexists=`command -v adb`
124+
125+
if [ -n "$adbexists" ]
126+
then
127+
ADB=`$adbexists`
128+
killadbserver
129+
130+
else
131+
echo "# #"
132+
echo "# #"
133+
echo "# ADB is not in your path or the shell could not find #"
134+
echo "# it but the script was created. If adb is in your #"
135+
echo "# PATH you will need to manually restart adb using #"
136+
echo "# adb kill-server #"
137+
echo "# #"
138+
echo "##########################################################"
139+
fi
140+
141+
}
142+
143+
144+
main(){
145+
146+
147+
welcomeMessage
148+
echo "# Press any key to continue #"
149+
read
150+
echo "# #"
151+
echo "# #"
152+
echo "# Requesting for Root privleges #"
153+
echo "# #"
154+
echo "# #"
155+
rootTest
156+
157+
createRules
158+
159+
restartServices
160+
161+
162+
}
163+
164+
165+
main
166+

create_android_rules.sh

Lines changed: 0 additions & 68 deletions
This file was deleted.

rules.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)