Skip to content

Commit

Permalink
Rename func log_* to msg_*
Browse files Browse the repository at this point in the history
  • Loading branch information
AkinaAcct committed Jun 5, 2024
1 parent 133a58a commit 665bddc
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 75 deletions.
66 changes: 33 additions & 33 deletions AAP.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ BLUE="\E[1;34m"
GREEN="\E[1;32m"
RESET="\E[0m"
LUOYANRANDOM="$(date "+%N")"
log_info() {
msg_info() {
echo -e "${BLUE}[INFO] $(date "+%H:%M:%S"): $1${RESET}"
}
log_err() {
msg_err() {
echo -e "${RED}[ERROR] $(date "+%H:%M:%S"): $1${RESET}"
}
log_warn() {
msg_warn() {
echo -e "${YELLOW}[WARN] $(date "+%H:%M:%S"): $1${RESET}"
}
if (command -v getprop >/dev/null 2>&1); then
OS="android"
log_info "OS: ${OS}"
msg_info "OS: ${OS}"
else
OS="linux"
log_warn "You are using ${OS}. Using this script on ${OS} is still under testing."
msg_warn "You are using ${OS}. Using this script on ${OS} is still under testing."
fi

print_help() {
Expand Down Expand Up @@ -53,9 +53,9 @@ while getopts ":hvi:k:IVs:SE:" OPT; do
i) # 处理选项i
BOOTPATH="${OPTARG}"
if [[ -e "${BOOTPATH}" ]]; then
log_info "Boot image path specified. Current image path: ${BOOTPATH}"
msg_info "Boot image path specified. Current image path: ${BOOTPATH}"
else
log_err "SPECIFIED BOOT IMAGE PATH IS WRONG! NO SUCH FILE!"
msg_err "SPECIFIED BOOT IMAGE PATH IS WRONG! NO SUCH FILE!"
exit 1
fi
;;
Expand All @@ -64,51 +64,51 @@ while getopts ":hvi:k:IVs:SE:" OPT; do
;;
S)
SAVEROOT="true"
log_info "The -S parameter was received. The patched image will be flashed into another slot if this is a ab partition device."
msg_info "The -S parameter was received. The patched image will be flashed into another slot if this is a ab partition device."
;;
V)
set -x
log_warn "DEBUG MODE IS ON."
msg_warn "DEBUG MODE IS ON."
;;
I)
if [[ "${OS}" == "android" ]]; then
INSTALL="true"
log_info "The -I parameter was received. Will install after patching."
msg_info "The -I parameter was received. Will install after patching."
else
log_err "Do not use this arg without Android!"
msg_err "Do not use this arg without Android!"
exit 1
fi
;;
s)
SUPERKEY="${OPTARG}"
log_info "The -s parameter was received. Currently specified SuperKey: ${SUPERKEY}."
msg_info "The -s parameter was received. Currently specified SuperKey: ${SUPERKEY}."
;;
k)
KPTOOLVER="${OPTARG}"
log_info "The -k parameter was received. Will use kptool ${KPTOOLVER}."
msg_info "The -k parameter was received. Will use kptool ${KPTOOLVER}."
;;
E)
EXTRAARGS="${OPTARG}"
log_info "The -E parameter was received. Current extra args: ${EXTRAARGS}"
msg_info "The -E parameter was received. Current extra args: ${EXTRAARGS}"
;;
:)
log_err "Option -${OPTARG} requires an argument.." >&2 && exit 1
msg_err "Option -${OPTARG} requires an argument.." >&2 && exit 1
;;

?)
log_err "Invalid option: -${OPTARG}" >&2 && exit 1
msg_err "Invalid option: -${OPTARG}" >&2 && exit 1
;;
esac
done

# ROOT 检测
if [[ $(id -u) -ne 0 ]]; then
log_err "Run this script with root!"
msg_err "Run this script with root!"
exit 127
fi
# 镜像路径检测(For Linux)
if [[ $"${OS}" == "linux" && -z "${BOOTPATH}" ]]; then
log_err "You are using ${OS}, but there is no image specified by you. Exited."
msg_err "You are using ${OS}, but there is no image specified by you. Exited."
exit 1
fi
# 设置工作文件夹
Expand All @@ -124,23 +124,23 @@ if [[ "${OS}" == "android" ]]; then
BOOTSUFFIX=$(getprop ro.boot.slot_suffix)
fi
else
log_warn "Current OS is: ${OS}. Skip boot slot check."
msg_warn "Current OS is: ${OS}. Skip boot slot check."
fi
if [[ -n "${SAVEROOT}" && -n "${BOOTSUFFIX}" && "${OS}" == "android" ]]; then
if [[ "${BOOTSUFFIX}" == "_a" ]]; then
TBOOTSUFFIX="_b"
else
TBOOTSUFFIX="_a"
fi
log_warn "You have specified the installation to another slot. Current slot:${BOOTSUFFIX}. Slot to be flashed into:${TBOOTSUFFIX}."
msg_warn "You have specified the installation to another slot. Current slot:${BOOTSUFFIX}. Slot to be flashed into:${TBOOTSUFFIX}."
fi
if [[ -z "${SUPERKEY}" ]]; then
SUPERKEY=${LUOYANRANDOM}
fi
# 检测可能存在的APatch app, 并输出相关信息
if [[ "${OS}" == "android" ]]; then
if (pm path me.bmax.apatch >/dev/null 2>&1); then
log_info "Detected that APatch is installed."
msg_info "Detected that APatch is installed."
APKPATH="$(command echo "$(pm path me.bmax.apatch)" | sed 's/base.apk//g' | sed 's/package://g')"
APKLIBPATH="${APKPATH}lib/arm64"
APDVER="$(${APKLIBPATH}/libapd.so -V)"
Expand All @@ -157,27 +157,27 @@ rm -rf /tmp/LuoYanTmp_*
rm -rf ./LuoYanTmp_*
mkdir -p "${WORKDIR}"

log_info "Downloading function file from GitHub..."
msg_info "Downloading function file from GitHub..."
curl -L --progress-bar "https://raw.githubusercontent.com/nya-main/APatchAutoPatchTool/main/new/AAPFunction" -o ${WORKDIR}/AAPFunction
EXITSTATUS=$?
if [[ $EXITSTATUS != 0 ]]; then
log_err "SOMETHING WENT WRONG! CHECK YOUR INTERNET CONNECTION!"
msg_err "SOMETHING WENT WRONG! CHECK YOUR INTERNET CONNECTION!"
exit 1
fi

# 备份boot
if [[ "${OS}" == "android" ]]; then
log_info "Backing up boot image..."
msg_info "Backing up boot image..."
dd if=${BYNAMEPATH}/boot${BOOTSUFFIX} of=/storage/emulated/0/stock_boot${BOOTSUFFIX}.img
EXITSTATUS=$?
if [[ "${EXITSTATUS}" != "0" ]]; then
log_err "BOOT IMAGE BACKUP FAILED!"
log_warn "Now skiping backingup boot image..."
msg_err "BOOT IMAGE BACKUP FAILED!"
msg_warn "Now skiping backingup boot image..."
else
log_info "Done. Boot image path: /storage/emulated/0/stock_boot${BOOTSUFFIX}.img"
msg_info "Done. Boot image path: /storage/emulated/0/stock_boot${BOOTSUFFIX}.img"
fi
else
log_info "Current OS: ${OS}. Skiping backup..."
msg_info "Current OS: ${OS}. Skiping backup..."
fi

# 加载操作文件
Expand All @@ -187,18 +187,18 @@ get_device_boot
get_tools
patch_boot
if [[ -n ${INSTALL} ]]; then
log_warn "The -I parameter was received. Will install patched image."
msg_warn "The -I parameter was received. Will install patched image."
flash_boot
else
if [[ "${OS}" == "android" ]]; then
log_info "Now copying patched image to /storage/emulated/0/patched_boot.img..."
msg_info "Now copying patched image to /storage/emulated/0/patched_boot.img..."
mv ${WORKDIR}/new-boot.img /storage/emulated/0/patched_boot.img
else
log_info "Now copying patched image to ${HOME}/patched_boot.img..."
msg_info "Now copying patched image to ${HOME}/patched_boot.img..."
mv ${WORKDIR}/new-boot.img ${HOME}/patched_boot.img
fi
log_info "Done. Now deleting tmp files..."
msg_info "Done. Now deleting tmp files..."
rm -rf ${WORKDIR}
log_info "Done."
msg_info "Done."
fi
print_superkey
84 changes: 42 additions & 42 deletions AAPFunction → AAPFunction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
#2024-06-03

get_device_boot() { # 未指定boot路径时从设备boot分区获取boot镜像
log_info "Getting boot image..."
msg_info "Getting boot image..."
if [[ -z "${BOOTPATH}" ]]; then
log_info "Current boot: ${BOOTSUFFIX}(If empty: A-Only devices)"
msg_info "Current boot: ${BOOTSUFFIX}(If empty: A-Only devices)"
dd if=${BYNAMEPATH}/boot${BOOTSUFFIX} of=${WORKDIR}/boot${BOOTSUFFIX}.img
EXITSTATUS=$?
if [[ $EXITSTATUS != 0 ]]; then
log_err "GET BOOT IMAGE FAILED!"
msg_err "GET BOOT IMAGE FAILED!"
exit 1
fi
else
cp ${BOOTPATH} ${WORKDIR}/boot${BOOTSUFFIX}.img
fi
log_info "Done."
msg_info "Done."
}

get_tools() { # 从GitHub下载工具
cd ${WORKDIR} || exit 1
log_info "Downloading kptools-${OS}..."
msg_info "Downloading kptools-${OS}..."
if [[ -n "${KPTOOLVER}" ]]; then
log_info "Use the specified version: ${KPTOOLVER}"
msg_info "Use the specified version: ${KPTOOLVER}"
else
log_info "Use the latest kptools."
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}"
Expand All @@ -34,13 +34,13 @@ get_tools() { # 从GitHub下载工具
EXITSTATUS=$?
fi
if [[ $EXITSTATUS != 0 ]]; then
log_err "DOWNLOAD FAILED!"
log_err "Please check your internet connection."
msg_err "DOWNLOAD FAILED!"
msg_err "Please check your internet connection."
exit 1
fi
chmod +x kptools-${OS}
log_info "Done."
log_info "Downloading kpimg-android..."
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=$?
Expand All @@ -49,85 +49,85 @@ get_tools() { # 从GitHub下载工具
EXITSTATUS=$?
fi
if [[ $EXITSTATUS != 0 ]]; then
log_err "DOWNLOAD FAILED!"
log_err "Please check your internet connection."
msg_err "DOWNLOAD FAILED!"
msg_err "Please check your internet connection."
exit 1
fi
log_info "Done."
log_info "Downloading magiskboot..."
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
log_err "DOWNLOAD FAILED!"
log_err "Please check your internet connection."
msg_err "DOWNLOAD FAILED!"
msg_err "Please check your internet connection."
exit 1
fi
chmod +x magiskboot
log_info "Done."
msg_info "Done."
}

patch_boot() { # 修补boot镜像
log_info "Unpacking image..."
msg_info "Unpacking image..."
./magiskboot unpack boot${BOOTSUFFIX}.img
EXITSTATUS=$?
if [[ $EXITSTATUS != 0 ]]; then
log_err "UNPACK BOOT IMAGE FAILED!"
msg_err "UNPACK BOOT IMAGE FAILED!"
exit 1
fi
log_info "Done."
log_info "Unpatching current image..."
msg_info "Done."
msg_info "Unpatching current image..."
./kptools-${OS} --unpatch --image kernel --out kernel || EXITSTATUS=$?
if [[ ${EXITSTATUS} != 0 ]]; then
log_warn "Unpatch failed. Maybe you are using a unpatched boot image?"
log_warn "Now skipping unpatching..."
msg_warn "Unpatch failed. Maybe you are using a unpatched boot image?"
msg_warn "Now skipping unpatching..."
else
log_warn "Done."
msg_warn "Done."
fi
log_info "Patching image...Current Superkey: ${SUPERKEY}"
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
log_err "PATCH FAILED!"
msg_err "PATCH FAILED!"
exit 1
fi
log_info "Done."
log_info "Repacking..."
msg_info "Done."
msg_info "Repacking..."
./magiskboot repack boot${BOOTSUFFIX}.img
EXITSTATUS=$?
if [[ $EXITSTATUS != 0 ]]; then
log_err "REPACK FAILED!"
msg_err "REPACK FAILED!"
exit 1
fi
log_info "Done. Finished paching."
msg_info "Done. Finished paching."
}

flash_boot() { # 刷入boot镜像
if [[ "${OS}" == "android" ]]; then
log_info "Flashing boot image..."
msg_info "Flashing boot image..."
if [[ -n "${TBOOTSUFFIX}" ]]; then
log_warn "You previously specified that you want to install to another slot. Target slot:${TBOOTSUFFIX}."
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
log_err "WARNING! IMAGE FLASH FAILED!"
log_err "Now trying to restore..."
msg_err "WARNING! IMAGE FLASH FAILED!"
msg_err "Now trying to restore..."
dd if=${WORKDIR}/boot${BOOTSUFFIX}.img of=${BYNAMEPATH}/boot${BOOTSUFFIX}
EXITSTATUS=$?
if [[ ${EXITSTATUS} != 0 ]]; then
log_err "WARNING!!! RESTORE FAILED!!!"
log_err "Even I can't help you now. You can try to restore boot manually."
msg_err "WARNING!!! RESTORE FAILED!!!"
msg_err "Even I can't help you now. You can try to restore boot manually."
exit 1
fi
log_info "Restore Sucessfully."
msg_info "Restore Sucessfully."
fi
log_info "Flash done."
log_info "Cleaning temporary files..."
msg_info "Flash done."
msg_info "Cleaning temporary files..."
rm -rf ${WORKDIR}
log_info "Done."
msg_info "Done."
else
log_err "You are trying to change this script. Linux does not require a flashing step. This is the second level of warning."
msg_err "You are trying to change this script. Linux does not require a flashing step. This is the second level of warning."
exit 1
fi
}
Expand Down

0 comments on commit 665bddc

Please sign in to comment.