-
Notifications
You must be signed in to change notification settings - Fork 5
/
initbuild.sh
executable file
·598 lines (576 loc) · 16 KB
/
initbuild.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
#!/bin/bash
#echo -e "\e[40;32;1m"
clear
username=`whoami`
thisDir=`pwd`
toolsDir=$thisDir/tools
logDir=$thisDir/logs
#Environment Tools
addRulesFunc(){
read mIdVendor mIdProduct
echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\""$mIdVendor"\", ATTR{idProduct}==\""$mIdProduct"\", MODE=\"0600\", OWNER=\"$username\"" | sudo tee -a /etc/udev/rules.d/51-android.rules
sudo /etc/init.d/udev restart
}
addRules(){
clear
lsusb
echo -e "\nOK 上面列出了所有USB列表,大致内容如下:\n"
echo -e "\033[40;37;7mBus 00x Device 00x: ID \033[40;34;7mxxxx\033[40;32;1m:\033[40;33;7mxxxx\033[40;30;0m \033[40;31;7mxxxxxxxxxxxxx\033[40;31;0m"
echo -e "\e[40;32;1m"
echo -e "如上,蓝色字符串为idVendor,黄色字符串为idProduct\n红色的是一些厂商信息(也可能没有)"
echo -e "找第三个里面有没有你的手机厂商的名字,如:HUAWEI,ZTE 什么的"
echo -e "当然没找到没关系,第三个什么都没有的就是了\n把idVendor和idProduct 打在下面,空格隔开,如:19d2 ffd0"
echo -ne "\n输入:"
addRulesFunc
echo -e "添加成功"
}
installadbini(){
echo -e "正在安装adb_usb.ini环境"
cd $thisDir
git clone https://github.com/GaHoKwan/adbusbini
if [ "$?" -ne "0" ];then
echo -e "下载环境配置文件错误,请检查错误!"
else
sudo rm -rf ~/.android
sudo mv $thisDir/adbusbini ~/.android
fi
}
installadb(){
echo -e "\n配置adb环境变量..."
sudo apt-get update
sudo apt-get install android-tools-adb android-tools-fastboot
installadbini
curl https://raw.githubusercontent.com/GaHoKwan/Android-udev-rules/master/51-android.rules > $toolsDir/51-android.rules
sudo cp $toolsDir/51-android.rules /etc/udev/rules.d/
sudo chmod a+rx /etc/udev/rules.d/51-android.rules
sudo /etc/init.d/udev restart
echo "export PATH=$PATH:~/bin/" | sudo tee -a /etc/profile
source /etc/profile
sudo adb kill-server
sudo adb devices
echo "\n配置环境完成"
}
installia32(){
if [ "$kind" == "1" ]; then
sudo apt-get install ia32-libs
elif [ "$kind" == "2" ]; then
#start
cd /etc/apt/sources.list.d #进入apt源列表
echo "deb http://old-releases.ubuntu.com/ubuntu/ raring main restricted universe multiverse" | sudo tee ia32-libs-raring.list
#添加ubuntu 13.04的源,因为13.10的后续版本废弃了ia32-libs
sudo apt-get update #更新一下源
if [ "$?" == "0" ]; then
echo -e "下载完成"
else
echo -e "下载失败,正在重新尝试"
sudo apt-get update
fi
sudo apt-get install ia32-libs #安装ia32-libs
if [ "$?" == "0" ]; then
echo -e "下载完成"
else
echo -e "下载失败,正在重新尝试"
sudo apt-get install ia32-libs
fi
sudo rm ia32-libs-raring.list #恢复源
sudo apt-get update #再次更新下源
#end
else
kind=$(whiptail --backtitle "开始安卓开发环境..." --title "请选择使用的系统版本" --menu "请选择" 15 60 5 \
"1" "ubuntu 12.04 及以下(此项不安装编译环境)" \
"2" "ubuntu 14.04 以上及deepin等基于ubuntu14.04的系统" \
"3" "Linux mint 17(此项不安装ia32因为Mint系统自带)" \
"0" "离开脚本" 3>&1 1>&2 2>&3)
case $kind in
1)
export kind=1
installia32
;;
2)
export kind=2
installia32
;;
*)
initSystemConfigure
;;
esac
fi
}
initSystemConfigure(){
clear
configurechoose=$(whiptail --title "请输入你想安装的环境" --menu "请选择" 18 60 9 \
"1" "ia32运行库" \
"2" "JavaSE(Oracle Java JDK)" \
"3" "aosp&cm&recovery编译环境" \
"4" "adb运行环境" \
"5" "AndroidSDK运行环境" \
"6" "安卓开发必备环境(上面1234)" \
"0" "离开" 3>&1 1>&2 2>&3)
case $configurechoose in
1)
installia32
read -p "按回车键继续..."
initSystemConfigure
;;
2)
installJavaSE
read -p "按回车键继续..."
initSystemConfigure
;;
3)
DevEnvSetup
read -p "按回车键继续..."
initSystemConfigure
;;
4)
installadb
read -p "按回车键继续..."
initSystemConfigure
;;
5)
installsdk
initSystemConfigure
;;
6)
kind=$(whiptail --backtitle "开始安卓开发环境..." --title "请选择使用的系统版本" --menu "请选择" 15 60 5 \
"1" "ubuntu 12.04 及以下(此项不安装编译环境)" \
"2" "ubuntu 14.04 以上及deepin等基于ubuntu14.04的系统" \
"3" "Linux mint 17(此项不安装ia32因为Mint系统自带)" \
"0" "离开脚本" 3>&1 1>&2 2>&3)
case $kind in
1)
installrepo
installia32
installJavaSE
installadb
initSystemConfigure
;;
2)
installrepo
installia32
installJavaSE
installadb
DevEnvSetup
initSystemConfigure
;;
3)
installrepo
installJavaSE
installadb
DevEnvSetup
initSystemConfigure
;;
*)
initSystemConfigure
;;
esac
;;
esac
}
installsdk(){
echo
echo "下载和配置 Android SDK!!"
echo "请确保 unzip 已经安装"
echo
sudo apt-get install unzip -y
if [ `getconf LONG_BIT` = "64" ];then
echo
echo "正在下载 Linux 64位 系统的Android SDK"
wget http://dl.google.com/android/adt/adt-bundle-linux-x86_64-20140702.zip
echo "下载完成!!"
echo "展开文件"
mkdir ~/adt-bundle
mv adt-bundle-linux-x86_64-20140702.zip ~/adt-bundle/adt_x64.zip
cd ~/adt-bundle
unzip adt_x64.zip
mv -f adt-bundle-linux-x86_64-20140702/* .
echo "正在配置"
echo -e '\n# Android tools\nexport PATH=${PATH}:~/adt-bundle/sdk/tools\nexport PATH=${PATH}:~/adt-bundle/sdk/platform-tools\nexport PATH=${PATH}:~/bin' >> ~/.bashrc
echo -e '\nPATH="$HOME/adt-bundle/sdk/tools:$HOME/adt-bundle/sdk/platform-tools:$PATH"' >> ~/.profile
echo "完成!!"
else
echo
echo "正在下载 Linux 32位 系统的Android SDK"
wget http://dl.google.com/android/adt/adt-bundle-linux-x86-20140702.zip
echo "下载完成!!"
echo "展开文件"
mkdir ~/adt-bundle
mv adt-bundle-linux-x86-20140702.zip ~/adt-bundle/adt_x86.zip
cd ~/adt-bundle
unzip adt_x86.zip
mv -f adt-bundle-linux-x86_64-20140702/* .
echo "正在配置"
echo -e '\n# Android tools\nexport PATH=${PATH}:~/adt-bundle/sdk/tools\nexport PATH=${PATH}:~/adt-bundle/sdk/platform-tools\nexport PATH=${PATH}:~/bin' >> ~/.bashrc
echo -e '\nPATH="$HOME/adt-bundle/sdk/tools:$HOME/adt-bundle/sdk/platform-tools:$PATH"' >> ~/.profile
echo "完成!!"
fi
rm -Rf ~/adt-bundle/adt-bundle-linux-x86_64-20140702
rm -Rf ~/adt-bundle/adt-bundle-linux-x86-20140702
rm -f ~/adt-bundle/adt_x64.zip
rm -f ~/adt-bundle/adt_x86.zip
read -p "按回车键继续..."
}
installkitchen(){
echo "安装安卓厨房"
sudo apt-get install git -y
cd ~/
git clone https://github.com/kuairom/Android_Kitchen_cn
if [ "$?" -ne "0" ];then
read -p "安装失败,请检查报错信息,按回车键继续"
main
fi
echo "安卓厨房已下载到主文件夹的Android_Kitchen_cn目录里!"
cd $thisDir
read -p "按回车键继续..."
}
installJavaSE(){
sudo apt-get update
echo -e "\n开始安装oracle java developement kit..."
sleep 1
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update && sudo apt-get install oracle-java6-installer
if [ "$?" == "0" ]; then
echo -e "下载完成"
else
echo -e "下载失败,正在重新尝试"
sudo apt-get install openjdk-7-jdk
fi
echo -e "\n安装openjdk7..."
sleep 1
sudo apt-get install openjdk-7-jdk
if [ "$?" == "0" ]; then
echo -e "下载完成"
else
echo -e "下载失败,正在重新尝试"
sudo apt-get install openjdk-7-jdk
fi
read -p "按回车键继续..."
echo 'alias jar-switch="sudo update-alternatives --config jar"' | sudo tee -a ~/.bashrc
echo -e "你可以使用jar-switch命令来切换jar版本"
echo 'alias java-switch="sudo update-alternatives --config java"' | sudo tee -a ~/.bashrc
echo 'alias javac-switch="sudo update-alternatives --config javac"' | sudo tee -a ~/.bashrc
echo 'alias javah-switch="sudo update-alternatives --config javah"' | sudo tee -a ~/.bashrc
echo 'alias javap-switch="sudo update-alternatives --config javap"' | sudo tee -a ~/.bashrc
source ~/.bashrc
echo -e "你可以使用java(c/h/p)-switch命令来切换java(c/h/p)版本"
}
DevEnvSetup(){
echo -e "\n开始安装ROM编译环境..."
sudo apt-get install bison ccache libc6 curl flex g++-multilib g++ gcc-multilib git-core gnupg gperf x11proto-core-dev tofrodos libx11-dev:i386 libgl1-mesa-dev libreadline6-dev:i386 lib32ncurses5-dev libncurses5-dev:i386 lib32readLine-gplv2-dev lib32z1-dev libesd0-dev libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev python-markdown libxml2 libxml2-utils lzop squashfs-tools xsltproc pngcrush schedtool zip zlib1g-dev:i386 zlib1g-dev
if [ "$?" == "0" ]; then
echo -e "下载完成"
else
echo -e "下载失败,正在重新尝试"
DevEnvSetup
fi
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
}
#Development tools
installrepo(){
mkdir -p ~/bin
curl https://raw.githubusercontent.com/FlymeOS/manifest/lollipop-5.0/repo > ~/bin/repo
chmod a+x ~/bin/repo
}
repoSource(){
if [ ! -f ~/bin/repo ]; then
installrepo
fi
clear
sDir=$(dialog --backtitle "方向键上下选择,单击空格选择,双击空格进入目录,退格键返回上一层,回车键确认路径" --title "输入存放源码的地址 " --dselect ~/ 7 40 3>&1 1>&2 2>&3)
cd ${sDir//\'//}
echo -e "请稍等..."
repo init -u https://github.com/FlymeOS/manifest.git -b lollipop-5.0
repo sync -j4
if [ "$?" == "0" ]; then
echo -e "同步完成"
else
echo -e "同步失败,正在重新尝试"
repo sync -j4
fi
cd $thisDir
read -p "按回车键继续..."
}
fastrepoSource(){
if [ ! -f ~/bin/repo ]; then
installrepo
fi
clear
sDir=$(dialog --backtitle "方向键上下选择,单击空格选择,双击空格进入目录,退格键返回上一层,回车键确认路径" --title "输入存放源码的地址 " --dselect ~/ 7 40 3>&1 1>&2 2>&3)
cd ${sDir//\'//}
echo -e "请稍等..."
cd ${sDir//\'//}
repo init --repo-url git://github.com/FlymeOS/repo.git -u https://github.com/FlymeOS/manifest.git -b lollipop-5.0 --no-repo-verify
repo sync -c --no-clone-bundle -j4
if [ "$?" == "0" ]; then
echo -e "同步完成"
else
echo -e "同步失败,正在重新尝试"
repo sync -c --no-clone-bundle -j4
fi
read -p "按回车键继续..."
cd $thisDir
}
logcat(){
source $toolsDir/logcat
}
screencap(){
shotcap=$(whiptail --title "截图工具" --menu "请选择" 20 60 10 \
"1" "截图" \
"2" "拉取截图" \
"3" "清理缓存" \
"0" "离开脚本" 3>&1 1>&2 2>&3)
case $shotcap in
1)
echo ">>> 正在获取截图..."
source $toolsDir/cs
adb shell mkdir -p /data/local/tmp/Screenshot
adb shell 'screencap -p "/data/local/tmp/Screenshot/`date`.png"'
if [ "$?" == "0" ]; then
whiptail --title "提示" --msgbox "截图文件已经输出到/data/local/tmp/Screenshot." 10 60
else
whiptail --title "提示" --msgbox "截图错误,请检查adb是否正常工作." 10 60
fi
screencap
;;
2)
mkdir $thisDir/Screenshot/
source $toolsDir/cs
adb pull "/data/local/tmp/Screenshot/" $thisDir/Screenshot/
if [ "$?" == "0" ]; then
whiptail --title "提示" --msgbox "截图文件已经输出到$thisDir/Screenshot." 10 60
else
whiptail --title "提示" --msgbox "输出错误,请检查adb是否正常工作." 10 60
fi
whiptail --title "提示" --msgbox "操作完成." 10 60
main
;;
3)
source $toolsDir/cs
adb shell rm -rf /data/local/tmp/Screenshot
whiptail --title "清理残留文件" --yes-button "确定" --no-button "取消" --yesno "是否清理残留文件?" 10 60
if [ "$?" == "0" ]; then
rm -rf $thisDir/Screenshot >/dev/null
for i in {1..100} ;do echo $i;done | dialog --title \
"清理残留文件" --gauge "正在清理..." 8 30
fi
whiptail --title "提示" --msgbox "操作完成." 10 60
main
;;
*)
main
;;
esac
}
zipcenop(){
whiptail --title "这是刷机包或者apk&jar伪加密工具" --yes-button "加密" --no-button "解密" --yesno "请选择模式." 10 80
if [ "$?" == "0" ]; then
export cenopmode=1
else
export cenopmode=2
fi
cenopfile=$(dialog --backtitle "方向键上下选择,单击空格选择,双击空格进入目录,退格键返回上一层,回车键确认路径" --title "请把需要加密的刷机包或者apk&jar拖进来 " --dselect / 7 40 3>&1 1>&2 2>&3)
case $cenopmode in
1)
java -jar $toolsDir/ZipCenOp.jar e ${cenopfile//\'//}
if [ "$?" == "0" ]; then
whiptail --title "提示" --msgbox "加密错误,请检查文件路径是否正确." 10 60
else
whiptail --title "提示" --msgbox "加密完成." 10 60
fi
;;
2)
java -jar $toolsDir/ZipCenOp.jar r ${cenopfile//\'//}
if [ "$?" == "0" ]; then
whiptail --title "提示" --msgbox "解密错误,请检查文件路径是否正确." 10 60
else
whiptail --title "提示" --msgbox "解密完成." 10 60
fi
;;
*)
main
;;
esac
}
clean(){
cd $toolsDir
rm -rf colored-adb-logcat.py 51-android.rules >/dev/null
cd $thisDir
for i in {1..100} ;do echo $i;done | dialog --title \
"清理环境文件" --gauge "正在清理..." 8 30
whiptail --title "清理残留文件" --yesno "是否清理残留文件?" 10 60
if [ "$?" == "0" ]; then
rm -rf logs Screenshot >/dev/null
for i in {1..100} ;do echo $i;done | dialog --title \
"清理残留文件" --gauge "正在清理..." 8 30
else
clear
fi
echo -e "\e[0m"
exit
}
adbtools(){
adbtool=$(whiptail --title "Android Debug Bridge Tools" --menu "请选择" 14 60 6 \
"1" "使用root权限启动adb" \
"2" "重启到系统" \
"3" "重启到Recovery" \
"4" "重启到Download" \
"5" "重启到Bootloader(Fastboot)" \
"0" "离开脚本" 3>&1 1>&2 2>&3)
case $adbtool in
1)
echo -e "请稍等..."
source $toolsDir/cs -s
read -p "按回车键继续..."
adbtools
;;
2)
echo -e "请稍等..."
source $toolsDir/cs -n
source $toolsDir/sys
read -p "按回车键继续..."
adbtools
;;
3)
echo -e "请稍等..."
source $toolsDir/cs -n
source $toolsDir/rec
read -p "按回车键继续..."
adbtools
;;
4)
echo -e "请稍等..."
source $toolsDir/cs -n
source $toolsDir/dl
read -p "按回车键继续..."
adbtools
;;
5)
echo -e "请稍等..."
source $toolsDir/cs -n
source $toolsDir/bl
read -p "按回车键继续..."
adbtools
;;
*)
main
;;
esac
}
devtools(){
tools=$(whiptail --title "Android开发工具" --menu "请选择" 12 60 4 \
"1" "伪加密工具" \
"2" "抓取log工具" \
"3" "手机截图" \
"0" "离开脚本" 3>&1 1>&2 2>&3)
case $tools in
1)
zipcenop
devtools
;;
2)
logcat
devtools
;;
3)
screencap
devtools
;;
*)
main
;;
esac
}
ubtools(){
ubtool=$(whiptail --title "Ubuntu软件安装工具" --menu "请选择" 12 60 4 \
"1" "搜狗拼音输入法" \
"2" "WineQQ国际版" \
"0" "离开脚本" 3>&1 1>&2 2>&3)
case $ubtool in
1)
source $toolsDir/sogou
ubtools
;;
2)
kind=$(whiptail --backtitle "WineQQ国际版" --title "请选择使用的系统版本" --menu "请选择" 10 60 2 \
"1" "Ubuntu及其他" \
"2" "Linux deepin" 3>&1 1>&2 2>&3)
case $kind in
1)
source $toolsDir/wineqq
;;
2)
sudo apt-get update
sudo apt-get install deepinwine-qqintl
;;
esac
ubtools
;;
*)
main
;;
esac
}
main(){
clear
inp=$(whiptail --backtitle "作者: 嘉豪仔_Kwan (QQ:625336209 微博:www.weibo.com/kwangaho)" --title "Android开发环境一键搭载脚本及开发工具-Flyme专版" --menu "请选择" 18 60 10 \
"1" "adb开发工具" \
"2" "Android开发工具" \
"3" "Ubuntu软件安装工具" \
"4" "设置环境变量" \
"5" "安装安卓厨房Android-Kitchen" \
"6" "依然无法识别手机?没关系,选这个" \
"7" "同步源码" \
"8" "快速同步源码(跳过谷歌认证)" \
"0" "离开脚本" 3>&1 1>&2 2>&3)
case $inp in
1)
adbtools
;;
2)
devtools
;;
3)
ubtools
;;
4)
initSystemConfigure
main
;;
5)
installkitchen
main
;;
6)
addRules
main
;;
7)
repoSource
main
;;
8)
fastrepoSource
main
;;
0)
clean
;;
*)
main
;;
esac
}
warning(){
whiptail --title "警告" --yesno "本脚本仅适用于Ubuntu及各大Ubuntu发行版使用,并且建议在14.04LTS以上版本使用." 10 80
if [ "$?" == "0" ]; then
yourpassword=$(whiptail --title "Root" --passwordbox "请输入你的root密码." 10 60 3>&1 1>&2 2>&3)
echo $yourpassword | sudo -S sudo echo -e "正在进入主界面..."
if [ "$?" -ne "0" ]; then
warning
fi
main
else
exit
fi
}
warning