-
Notifications
You must be signed in to change notification settings - Fork 0
/
AAPFunction
executable file
·150 lines (142 loc) · 4.16 KB
/
AAPFunction
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
#!/bin/sh
#rewrited
#shellcheck disable=SC2086
get_device_boot() {
msg_info "Getting boot image..."
if [ -z "${BOOTPATH}" ]; then
msg_info "Current boot: ${BOOTSUFFIX}(If empty: A-Only device)"
dd if=${BYNAMEPATH}/boot${BOOTSUFFIX} of=${WORKDIR}/boot${BOOTSUFFIX}.img
EXITSTATUS=$?
if [ $EXITSTATUS != 0 ]; then
msg_fatal "Get boot image from device failed!"
fi
else
cp ${BOOTPATH} "${WORKDIR}/boot${BOOTSUFFIX}.img"
fi
msg_info "Done."
}
get_tools() {
cd "${WORKDIR}" || exit 1
msg_info "Downloading kptools-${OS}..."
if [ -n "${KPTOOLVER}" ]; then
msg_info "Use the specified version: ${KPTOOLVER}"
else
msg_info "Use the latest kptools."
fi
if [ -n "${KPTOOLVER}" ]; then
curl -LO --progress-bar "https://github.com/bmax121/KernelPatch/releases/download/${KPTOOLVER}/kptools-${OS}"
EXITSTATUS=$?
else
curl -LO --progress-bar "https://github.com/bmax121/KernelPatch/releases/latest/download/kptools-${OS}"
EXITSTATUS=$?
fi
if [ $EXITSTATUS != 0 ]; then
msg_fatal "DOWNLOAD FAILED!"
msg_fatal "Please check your internet connection."
exit 1
fi
chmod +x kptools-${OS}
msg_info "Done."
msg_info "Downloading kpimg-android..."
if [ -n "${KPTOOLVER}" ]; then
curl -LO --progress-bar "https://github.com/bmax121/KernelPatch/releases/download/${KPTOOLVER}/kpimg-android"
EXITSTATUS=$?
else
curl -LO --progress-bar "https://github.com/bmax121/KernelPatch/releases/latest/download/kpimg-android"
EXITSTATUS=$?
fi
if [ $EXITSTATUS != 0 ]; then
msg_fatal "DOWNLOAD FAILED!"
msg_fatal "Please check your internet connection."
exit 1
fi
msg_info "Done."
msg_info "Downloading magiskboot..."
curl -LO --progress-bar "https://raw.githubusercontent.com/AkinaAcct/APatchTool/main/bin/magiskboot"
EXITSTATUS=$?
if [ $EXITSTATUS != 0 ]; then
msg_fatal "DOWNLOAD FAILED!"
msg_fatal "Please check your internet connection."
exit 1
fi
chmod +x magiskboot
msg_info "Done."
}
patch_boot() {
msg_info "Unpacking image..."
./magiskboot unpack boot${BOOTSUFFIX}.img
EXITSTATUS=$?
if [ $EXITSTATUS != 0 ]; then
msg_fatal "UNPACK BOOT IMAGE FAILED!"
exit 1
fi
msg_info "Done."
msg_info "Unpatching current image..."
./kptools-${OS} --unpatch --image kernel --out kernel || EXITSTATUS=$?
if [ ${EXITSTATUS} != 0 ]; then
msg_warn "Unpatch failed. Maybe you are using a unpatched boot image?"
msg_warn "Now skipping unpatching..."
else
msg_warn "Done."
fi
msg_info "Patching image...Current Superkey: ${SUPERKEY}"
./kptools-${OS} --patch --kpimg kpimg-android --skey "${SUPERKEY}" --image kernel --out kernel ${EXTRAARGS}
EXITSTATUS=$?
if [ ${EXITSTATUS} != 0 ]; then
msg_fatal "PATCH FAILED!"
exit 1
fi
msg_info "Done."
msg_info "Repacking..."
./magiskboot repack boot${BOOTSUFFIX}.img
EXITSTATUS=$?
if [ $EXITSTATUS != 0 ]; then
msg_fatal "REPACK FAILED!"
exit 1
fi
msg_info "Done. Finished paching."
}
flash_boot() {
if [ "${OS}" = "android" ]; then
if ${ROOT}; then
msg_info "Flashing boot image..."
if [ -n "${TBOOTSUFFIX}" ]; then
msg_warn "You previously specified that you want to install to another slot. Target slot:${TBOOTSUFFIX}."
BOOTSUFFIX=${TBOOTSUFFIX}
fi
dd if=${WORKDIR}/new-boot.img of=${BYNAMEPATH}/boot${BOOTSUFFIX}
EXITSTATUS=$?
if [ ${EXITSTATUS} != 0 ]; then
msg_fatal "WARNING! IMAGE FLASH FAILED!"
msg_fatal "Now trying to restore..."
dd if=${WORKDIR}/boot${BOOTSUFFIX}.img of=${BYNAMEPATH}/boot${BOOTSUFFIX}
EXITSTATUS=$?
if [ ${EXITSTATUS} != 0 ]; then
msg_fatal "WARNING!!! RESTORE FAILED!!!"
msg_fatal "Even I can't help you now. You can try to restore boot manually."
exit 1
fi
msg_info "Restore Sucessfully."
fi
msg_info "Flash done."
msg_info "Cleaning temporary files..."
rm -rf ${WORKDIR}
msg_info "Done."
else
msg_fatal "No root. Unable to continue. Aborted."
exit 1
fi
else
msg_fatal "You are trying to change this script. Linux does not require a flashing step. This is the second level of warning."
exit 1
fi
}
print_superkey() {
cat <<EOF
####################################
YOUR SUPERKEY IS "$(printf "${BLUE}%s${RESET}" "${SUPERKEY}")"
DON'T FORGET IT!!
####################################
EOF
exit 0
}