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