-
Notifications
You must be signed in to change notification settings - Fork 8
/
flash-stock-rom.sh
executable file
·136 lines (101 loc) · 4.84 KB
/
flash-stock-rom.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
#!/bin/bash
trap "echo -e '\033[0;31m Script execution aborted. \033[0m'; exit 1" INT
file1="./stock-rom/flash_all.sh"
file2="./stock-rom/flash_all_lock.sh"
file3="./stock-rom/flash_all_except_*.sh"
sudo chmod +x $file1 $file2 $file3
sudo -k
echo -e "\033[0;32m Succeed! CHMOD EXECUTED!
\033[0m"
look="fastboot"
replace="./stock-rom/fastboot"
# Perform search and replace using awk
if [ ! -f $file1 ]; then
echo -e "\033[0;31m $file1 file is not found \033[0m";
exit 1;
fi
if [ ! -f $file2 ]; then
echo -e "\033[0;31m $file2 file is not found \033[0m";
exit 1;
fi
if ! grep -q "$replace" "$file1"; then
awk '{ gsub(/'"$look"'/, "'"$replace"'"); print }' "$file1" > flash_all.txt && mv flash_all.txt "$file1"
awk -v search="/images/" -v replace="/stock-rom/images/" '{ gsub(search, replace); print }' "$file1" > flash_all.txt && mv flash_all.txt "$file1"
fi
if ! grep -q "$replace" "$file2"; then
awk '{ gsub(/'"$look"'/, "'"$replace"'"); print }' "$file2" > flash_all_lock.txt && mv flash_all_lock.txt "$file2"
awk -v search="/images/" -v replace="/stock-rom/images/" '{ gsub(search, replace); print }' "$file2" > flash_all.txt && mv flash_all.txt "$file2"
fi
# Use a loop to handle multiple files that match the pattern
for file in ./stock-rom/flash_all_except_*.sh; do
if [[ -f "$file" ]]; then
echo "Processing file: $file"
if ! grep -q "$replace" "$file"; then
# Replace 'look' with 'replace' in the file
awk '{ gsub(/'"$look"'/, "'"$replace"'"); print }' "$file" > flash_all.txt && mv flash_all.txt "$file"
# Replace '/images/' with '/stock-rom/images/' in the file
awk -v search="/images/" -v replace="/stock-rom/images/" '{ gsub(search, replace); print }' "$file" > flash_all.txt && mv flash_all.txt "$file"
fi
else
echo "No files found matching the pattern."
fi
done
if [ $? -eq 0 ]; then
echo -e "\033[0;32m Modifying Flash file Succeed!
\033[0m"
fi
cp -R "./platform-tools"/* "./stock-rom/"
echo -e "\033[0;32m Copying files completed
\033[0m"
echo -e "\033[0;33m What do you want to do?
1. Flash without lock bootloader
2. Flash and lock bootloader
3. Flash except data storage
4. Restore all modified files which are required to execute flash script.
(Press Any key to Exit or input your choice.)
\033[0m";
read -p "Choice: " flasher
case $flasher in
"1")
source $file1
;;
"2")
source $file2
;;
"3")
source $file3
;;
"4")
if grep -q "$replace" "$file1"; then
awk -v search="$replace" -v replace="$look" '{ gsub(search, replace); print }' "$file1" > flash_all.txt && mv flash_all.txt "$file1"
awk -v search="/stock-rom/images/" -v replace="/images/" '{ gsub(search, replace); print }' "$file1" > flash_all.txt && mv flash_all.txt "$file1"
fi
if grep -q "$replace" "$file2"; then
awk -v search="$replace" -v replace="$look" '{ gsub(search, replace); print }' "$file2" > flash_all.txt && mv flash_all.txt "$file2"
awk -v search="/stock-rom/images/" -v replace="/images/" '{ gsub(search, replace); print }' "$file2" > flash_all.txt && mv flash_all.txt "$file2"
fi
if grep -q "$replace" "$file3"; then
awk -v search="$replace" -v replace="$look" '{ gsub(search, replace); print }' "$file3" > flash_all.txt && mv flash_all.txt "$file3"
awk -v search="/stock-rom/images/" -v replace="/images/" '{ gsub(search, replace); print }' "$file3" > flash_all.txt && mv flash_all.txt "$file3"
fi
echo -e "\033[0;32m Modified Flash file restored! \033[0m"
source ./flash.sh
;;
*)
echo "Aborting..."
if grep -q "$replace" "$file1"; then
awk -v search="$replace" -v replace="$look" '{ gsub(search, replace); print }' "$file1" > flash_all.txt && mv flash_all.txt "$file1"
awk -v search="/stock-rom/images/" -v replace="/images/" '{ gsub(search, replace); print }' "$file1" > flash_all.txt && mv flash_all.txt "$file1"
fi
if grep -q "$replace" "$file2"; then
awk -v search="$replace" -v replace="$look" '{ gsub(search, replace); print }' "$file2" > flash_all.txt && mv flash_all.txt "$file2"
awk -v search="/stock-rom/images/" -v replace="/images/" '{ gsub(search, replace); print }' "$file2" > flash_all.txt && mv flash_all.txt "$file2"
fi
if grep -q "$replace" "$file3"; then
awk -v search="$replace" -v replace="$look" '{ gsub(search, replace); print }' "$file3" > flash_all.txt && mv flash_all.txt "$file3"
awk -v search="/stock-rom/images/" -v replace="/images/" '{ gsub(search, replace); print }' "$file3" > flash_all.txt && mv flash_all.txt "$file3"
fi
echo -e "\033[0;32m Modified Flash file restored! \033[0m"
source ./flash.sh
;;
esac