Skip to content

Commit 9acdafe

Browse files
committed
Update exists function
1 parent 4f92227 commit 9acdafe

File tree

2 files changed

+173
-7
lines changed

2 files changed

+173
-7
lines changed

create-rules.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ echo "##########################################################"
2828

2929

3030
exists()
31-
{
31+
{
3232
if command -v $1 &>/dev/null
3333
then
3434
# echo " Yes, command :$1: was found."
35-
return 0
35+
return 1
3636
else
3737
# echo " No, command :$1: was NOT found."
38-
return 1
38+
return 0
3939
fi
4040
}
4141

@@ -77,8 +77,9 @@ counter=0
7777
for i in "${USBVendorIDs[@]}"
7878
do
7979
CREATE=`echo "SUBSYSTEM==\"usb\", SYSFS{idVendor}==\"$i\", MODE=\"0666\" #${Vendors[counter]}" >> $CONONICAL`
80+
$CREATE &2> /dev/null
8081
counter=$[$counter+1]
81-
$CREATE 2> /dev/null
82+
8283
done
8384

8485
sudo chmod +x $CONONICAL
@@ -120,9 +121,8 @@ exit -1
120121

121122
fi
122123

123-
adbexists=`command -v adb`
124-
125-
if [ -n "$adbexists" ]
124+
adbexists=&(exists adb)
125+
if [ "$adbexists" == 1 ]
126126
then
127127
ADB=`$adbexists`
128128
killadbserver

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 1
36+
else
37+
# echo " No, command :$1: was NOT found."
38+
return 0
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+
$CREATE &2> /dev/null
81+
counter=$[$counter+1]
82+
83+
done
84+
85+
sudo chmod +x $CONONICAL
86+
87+
}
88+
89+
90+
91+
rootTest(){
92+
if [ "$(whoami)" != "root" ]; then
93+
echo "Sorry, you are not root."
94+
echo "Please run again with sudo."
95+
exit 1
96+
fi
97+
98+
echo "# Root privleges found #"
99+
echo "# #"
100+
101+
}
102+
103+
restartServices(){
104+
105+
if [ -f $CONONICAL ]
106+
then
107+
echo "# #"
108+
echo "# The file was created succesfully #"
109+
echo "# Restarting udev to read the new rules #"
110+
echo "# #"
111+
echo "# #"
112+
sudo service udev restart >> /dev/null
113+
else
114+
echo "# #"
115+
echo "# #"
116+
echo "# Your files was not created, please run again #"
117+
echo "# #"
118+
echo "# #"
119+
echo "##########################################################"
120+
exit -1
121+
122+
fi
123+
124+
adbexists=&(exists adb)
125+
if [ "$adbexists" == 1 ]
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+

0 commit comments

Comments
 (0)