-
Notifications
You must be signed in to change notification settings - Fork 8
/
flash.sh
executable file
·184 lines (147 loc) · 5.37 KB
/
flash.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
#!/bin/bash
trap "echo -e '\033[0;31m Script execution aborted. \033[0m'; exit 1" INT
echo -e "\033[0;33m
What do you want to do?
1. Flash Recovery
2. Flash VBMETA
3. Use adb Sideload
4. Use adb Sideload and Reboot to recovery
5. Check adb devices
6. Check fastboot devices
7. Reboot to System
8. Reboot to Recovery
9. Reboot to Bootloader
10. Reboot to Fastboot
11. Flash MIUI Stock ROM (Fastboot)
(Press Any key to Exit or input your choice.)
\033[0m";
read -p "Choice: " flasher
case $flasher in
"1")
echo -e "\033[0;33m Please ensure that 'recovery.img' file exist in root directory. Press enter to continue \033[0m";
read
files=("recovery.img" "./platform-tools/fastboot" "./platform-tools/adb")
for file in "${files[@]}"; do
if [ ! -f "$file" ]; then
echo -e "\033[0;31m > $file file is not found \033[0m";
fi
done
for file in "${files[@]}"; do
if [ ! -f "$file" ]; then
echo -e "\033[0;31m \033[3m Please ensure that all of these files exist and try again. Have a good day! \033[0m"
exit 1;
fi
done
echo -e "\033[0;32m Flashing Recovery \033[0m";
./platform-tools/fastboot flash recovery recovery.img
read -p "Do you want to flash 'vbmeta.img' file? Type 'y' to flash, any key to skip: " vbimg;
if [ "$vbimg" = "y" ] || [ "$vbimg" = "yes" ] || [ "$vbimg" = "Y" ] || [ "$vbimg" = "YES" ]; then
echo -e "\033[0;33m make sure 'vbmeta.img' file exist in the root directory. \033[0m";
echo -e "\033[0;32m Flashing vbmeta.img \033[0m";
./platform-tools/fastboot --disable-verity --disable-verification flash vbmeta vbmeta.img
else
echo -e "\033[0;32m Skipping Flashing vbmeta.img \033[0m";
fi
echo -e "\033[0;32m Rebooting to Recovery \033[0m";
./platform-tools/fastboot reboot recovery
if [ $? -eq 0 ]; then
echo -e "\033[0;32m Operation Succeed \033[0m";
fi
source ./flash.sh
;;
"2")
if [ ! -f "vbmeta.img" ]; then
echo -e "\033[0;31m \033[3m Please ensure that 'vbmeta.img' file exist in the root directory and try again. Have a good day! \033[0m"
exit 1;
fi
if [ ! -f "./platform-tools/fastboot" ]; then
echo -e "\033[0;31m \033[3m Please ensure that fastboot file exist in platform-tools and try again. Have a good day! \033[0m"
exit 1;
fi
echo -e "\033[0;32m Flashing vbmeta.img \033[0m";
./platform-tools/fastboot --disable-verity --disable-verification flash vbmeta vbmeta.img
echo -e "\033[0;32m Rebooting your device to system! Have a good day! \033[0m";
./platform-tools/fastboot reboot
if [ $? -eq 0 ]; then
echo -e "\033[0;32m Operation Succeed \033[0m";
fi
source ./flash.sh
;;
"3")
echo -e "\033[0;32m Please enter the file name of your custom rom. \033[0m";
read -p "Enter the zip file name: " romname
if [ ! -f "$romname" ]; then
echo -e "\033[0;31m > $romname file is not found \033[0m";
echo -e "\033[0;31m \033[3m Please ensure that '$romname' file exist and try again. Have a good day! \033[0m";
exit 1;
fi
if [ ! -f "./platform-tools/adb" ]; then
echo -e "\033[0;31m > adb file is not found \033[0m";
echo -e "\033[0;31m \033[3m Please ensure that 'adb' file exist and try again. Have a good day! \033[0m";
exit 1;
fi
./platform-tools/adb sideload $romname
if [ $? -eq 0 ]; then
echo -e "\033[0;32m sideload operation completed \033[0m";
fi
source ./flash.sh
;;
"4")
echo -e "\033[0;32m Please enter the file name of your custom rom. \033[0m";
read -p "Enter the zip file name: " romname
if [ ! -f "$romname" ]; then
echo -e "\033[0;31m > $romname file is not found \033[0m";
echo -e "\033[0;31m \033[3m Please ensure that '$romname' file exist and try again. Have a good day! \033[0m";
exit 1;
fi
if [ ! -f "./platform-tools/adb" ]; then
echo -e "\033[0;31m > adb file is not found \033[0m";
echo -e "\033[0;31m \033[3m Please ensure that 'adb' file exist and try again. Have a good day! \033[0m";
exit 1;
fi
./platform-tools/adb sideload $romname
if [ $? -eq 0 ]; then
echo -e "\033[0;32m Sideload operation completed. Rebooting to Recovery \033[0m";
./platform-tools/adb reboot recovery
fi
source ./flash.sh
;;
"5")
echo -e "\033[0;32m adb device list: \033[0m"
./platform-tools/adb devices
source ./flash.sh
;;
"6")
echo -e "\033[0;32m fastboot device list: \033[0m"
./platform-tools/fastboot devices
source ./flash.sh
;;
"7")
echo -e "\033[0;32m Rebooting your device to system! Have a good day! \033[0m";
./platform-tools/fastboot reboot
source ./flash.sh
;;
"8")
echo -e "\033[0;32m Rebooting your device to Recovery! \033[0m";
./platform-tools/fastboot reboot recovery
source ./flash.sh
;;
"9")
echo -e "\033[0;32m Rebooting your device to Bootloader! \033[0m";
./platform-tools/fastboot reboot bootloader
source ./flash.sh
;;
"10")
echo -e "\033[0;32m Rebooting your device to Fastboot! \033[0m";
./platform-tools/fastboot reboot fastboot
source ./flash.sh
;;
"11")
echo -e "\033[0;32m Great Choice! Heading up to Stock ROM Flash system! \033[0m";
source ./flash-stock-rom.sh;
;;
*)
echo -e '\033[0;31m Script execution aborted. \033[0m';
exit 1
;;
esac