From 14068f6ccbffa11c732cb7adf51eefb883af02b3 Mon Sep 17 00:00:00 2001 From: Atopes Sayuri <108107785+AtopesSayuri@users.noreply.github.com> Date: Tue, 4 Jun 2024 23:34:29 +0800 Subject: [PATCH] Major Upd: bump version && drop old version --- AAP.sh | 173 ++++++++++++++++++++++------------------- AAPFunction | 97 +++++++++++------------ README.md | 33 +++----- README_CN.md | 67 ---------------- new/AAP-New.sh | 200 ------------------------------------------------ new/AAPFunction | 148 ----------------------------------- new/README.md | 72 ----------------- 7 files changed, 153 insertions(+), 637 deletions(-) delete mode 100644 README_CN.md delete mode 100755 new/AAP-New.sh delete mode 100755 new/AAPFunction delete mode 100644 new/README.md diff --git a/AAP.sh b/AAP.sh index e997263..3298918 100755 --- a/AAP.sh +++ b/AAP.sh @@ -1,46 +1,61 @@ #!/bin/sh -#by nya -#2024-02-06 +#by Akina | LuoYan +#2024-06-03 Rewrite RED="\E[1;31m" YELLOW="\E[1;33m" BLUE="\E[1;34m" GREEN="\E[1;32m" RESET="\E[0m" - -alias echo="echo -e" +LUOYANRANDOM="$(date "+%N")" +log_info() { + echo -e "${BLUE}[INFO] $(date "+%H:%M:%S"): $1${RESET}" +} +log_err() { + echo -e "${RED}[ERROR] $(date "+%H:%M:%S"): $1${RESET}" +} +log_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}" +else + OS="linux" + log_warn "You are using ${OS}. Using this script on ${OS} is still under testing." +fi print_help() { - echo "${GREEN}" + echo -e "${GREEN}" cat <<-EOF -APatch Auto Patch Tool -Written by Akina -Version: 1.0.1 -Current DIR: $(pwd) + APatch Auto Patch Tool + Written by Akina + Version: 2.1.0 + Current DIR: $(pwd) --h, -v, print the usage and version. + -h, -v, print the usage and version. --i [BOOT IMAGE PATH], specify a boot image path. --n, do not install the patched boot image, save the image in /storage/emulated/0/patched_boot.img, or on Linux ${HOME}/patched_boot.img. --k [RELEASE NAME], specify a kernelpatch version [RELEASE NAME]. --s "STRING", specify a superkey. Use STRING as superkey. --S, Install to another slot (for OTA). --E [ARGS], Add args [ARGS] to kptools when patching. --V, verbose mode. + -i [BOOT IMAGE PATH], specify a boot image path. + -n, do not install the patched boot image, save the image in /storage/emulated/0/patched_boot.img, or on Linux ${HOME}/patched_boot.img. + -k [RELEASE NAME], specify a kernelpatch version [RELEASE NAME]. + -s "STRING", specify a superkey. Use STRING as superkey. + -S, Install to another slot (for OTA). + -E [ARGS], Add args [ARGS] to kptools when patching. + -V, verbose mode. EOF - echo "${RESET}" + echo -e "${RESET}" exit 0 } # 参数解析 -while getopts ":hvi:k:nVs:SE:" OPT; do +while getopts ":hvi:k:IVs:SE:" OPT; do case $OPT in i) # 处理选项i BOOTPATH="${OPTARG}" if [[ -e "${BOOTPATH}" ]]; then - echo "${BLUE}I: Boot image path specified. Current image path: ${BOOTPATH}${RESET}" + log_info "Boot image path specified. Current image path: ${BOOTPATH}" else - echo "${RED}E: SPECIFIED BOOT IMAGE PATH IS WRONG! NO SUCH FILE!${RESET}" + log_err "SPECIFIED BOOT IMAGE PATH IS WRONG! NO SUCH FILE!" exit 1 fi ;; @@ -49,63 +64,67 @@ while getopts ":hvi:k:nVs:SE:" OPT; do ;; S) SAVEROOT="true" - echo "${BLUE}I: The -S parameter was received. The patched image will be flashed into another slot if this is a ab partition device." + log_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 - echo "${YELLOW}W: DEBUG MODE IS ON.${RESET}" + log_warn "DEBUG MODE IS ON." ;; - n) - NOINSTALL="true" - echo "${BLUE}I: The -n parameter was received. Won't install after patch.${RESET}" + I) + if [[ "${OS}" == "android" ]]; then + INSTALL="true" + log_info "The -I parameter was received. Will install after patching." + else + log_err "Do not use this arg without Android!" + exit 1 + fi ;; s) SUPERKEY="${OPTARG}" - echo "${BLUE}I: The -s parameter was received. Currently specified SuperKey: ${SUPERKEY}.${RESET}" + log_info "The -s parameter was received. Currently specified SuperKey: ${SUPERKEY}." ;; k) KPTOOLVER="${OPTARG}" - echo "${BLUE}I: The -k parameter was received. Will use kptool ${KPTOOLVER}.${RESET}" + log_info "The -k parameter was received. Will use kptool ${KPTOOLVER}." + ;; + E) + EXTRAARGS="${OPTARG}" + log_info "The -E parameter was received. Current extra args: ${EXTRAARGS}" ;; - E) - EXTRAARGS="${OPTARG}" - echo "${BLUE}I: The -E parameter was received. Current extra args: ${EXTRAARGS}" - ;; :) - echo "${YELLOW}W: Option -$OPTARG requires an argument..${RESET}" >&2 && exit 1 + log_err "Option -${OPTARG} requires an argument.." >&2 && exit 1 ;; ?) - echo "${RED}E: Invalid option: -$OPTARG${RESET}" >&2 && exit 1 + log_err "Invalid option: -${OPTARG}" >&2 && exit 1 ;; esac done -# 设置工作文件夹 -WORKDIR="$(pwd)/nyatmp_${RANDOM}" # ROOT 检测 -if [[ "$(id -u)" != "0" ]]; then - echo "${RED}E: RUN THIS SCRIPT WITH ROOT PERMISSION!${RESET}" - exit 2 +if [[ $(id -u) -ne 0 ]]; then + log_err "Run this script with root!" + exit 127 fi -# OS 检测 -if (command -v getprop >/dev/null 2>&1); then - OS="android" - echo "${BLUE}I: OS: ${OS}${RESET}" +# 镜像路径检测(For Linux) +if [[ $"${OS}" == "linux" && -z "${BOOTPATH}" ]]; then + log_err "You are using ${OS}, but there is no image specified by you. Exited." + exit 1 +fi +# 设置工作文件夹 +if [[ "${OS}" == "android" ]]; then + WORKDIR="/data/local/tmp/LuoYanTmp_${LUOYANRANDOM}" else - OS="linux" - echo "${YELLOW}W: You are using ${OS}.Using this script on ${OS} is still under testing.${RESET}" - if [[ -z "${BOOTPATH}" ]]; then - echo "${RED}E: You are using ${OS}, but there is no image specified by you. Exited.${RESET}" - exit 1 - fi + WORKDIR="/tmp/LuoYanTmp_${LUOYANRANDOM}" fi # 判断用户设备是否为ab分区,是则设置$BOOTSUFFIX BYNAMEPATH="$(getprop ro.frp.pst | sed 's/\/frp//g')" -if [[ ! -e ${BYNAMEPATH}/boot && "${OS}" == "android" ]]; then - BOOTSUFFIX=$(getprop ro.boot.slot_suffix) +if [[ "${OS}" == "android" ]]; then + if [[ ! -e ${BYNAMEPATH}/boot ]]; then + BOOTSUFFIX=$(getprop ro.boot.slot_suffix) + fi else - echo "${BLUE}I: Current OS is: ${OS}. Skip boot slot check.${RESET}" + log_warn "Current OS is: ${OS}. Skip boot slot check." fi if [[ -n "${SAVEROOT}" && -n "${BOOTSUFFIX}" && "${OS}" == "android" ]]; then if [[ "${BOOTSUFFIX}" == "_a" ]]; then @@ -113,52 +132,52 @@ if [[ -n "${SAVEROOT}" && -n "${BOOTSUFFIX}" && "${OS}" == "android" ]]; then else TBOOTSUFFIX="_a" fi - echo "${BLUE}I: You have specified the installation to another slot. Current slot:${BOOTSUFFIX}. Slot to be flashed into:${TBOOTSUFFIX}." + log_warn "You have specified the installation to another slot. Current slot:${BOOTSUFFIX}. Slot to be flashed into:${TBOOTSUFFIX}." fi if [[ -z "${SUPERKEY}" ]]; then - SUPERKEY=${RANDOM} + SUPERKEY=${LUOYANRANDOM} fi # 检测可能存在的APatch app, 并输出相关信息 if [[ "${OS}" == "android" ]]; then if (pm path me.bmax.apatch >/dev/null 2>&1); then - echo "${BLUE}I: Detected that APatch is installed.${RESET}" + log_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)" LKPVER="$(${APKLIBPATH}/libkpatch.so -v)" cat <<-EOF - Installed manager(apd) version: $(echo "${BLUE}${APDVER}${RESET}") - APatch app built-in KernelPatch version: $(echo "${BLUE}${LKPVER}${RESET}") + Installed manager(apd) version: $(echo -e "${BLUE}${APDVER}${RESET}") + APatch app built-in KernelPatch version: $(echo -e "${BLUE}${LKPVER}${RESET}") EOF fi fi # 清理可能存在的上次运行文件 -rm -rf ./nyatmp_* +rm -rf /tmp/LuoYanTmp_* +rm -rf ./LuoYanTmp_* +mkdir -p "${WORKDIR}" -mkdir -p ${WORKDIR} - -echo "${BLUE}I: Downloading function file from GitHub...${RESET}" -curl -L --progress-bar "https://raw.githubusercontent.com/nya-main/APatchAutoPatchTool/main/AAPFunction" -o ${WORKDIR}/AAPFunction +log_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 - echo "${RED}E: SOMETHING WENT WRONG! CHECK YOUR INTERNET CONNECTION!${RESET}" + log_err "SOMETHING WENT WRONG! CHECK YOUR INTERNET CONNECTION!" exit 1 fi # 备份boot if [[ "${OS}" == "android" ]]; then - echo "${BLUE}I: Backing up boot image...${RESET}" + log_info "Backing up boot image..." dd if=${BYNAMEPATH}/boot${BOOTSUFFIX} of=/storage/emulated/0/stock_boot${BOOTSUFFIX}.img EXITSTATUS=$? if [[ "${EXITSTATUS}" != "0" ]]; then - echo "${RED}E: BOOT IMAGE BACKUP FAILED!${RESET}" - echo "${YELLOW}W: Now skiping backingup boot image...${RESET}" + log_err "BOOT IMAGE BACKUP FAILED!" + log_warn "Now skiping backingup boot image..." else - echo "${GREEN}I: Done. Boot image path: /storage/emulated/0/stock_boot${BOOTSUFFIX}.img${RESET}" + log_info "Done. Boot image path: /storage/emulated/0/stock_boot${BOOTSUFFIX}.img" fi else - echo "${BLUE}I: Current OS: ${OS}. Skiping backup...${RESET}" + log_info "Current OS: ${OS}. Skiping backup..." fi # 加载操作文件 @@ -167,21 +186,19 @@ source ${WORKDIR}/AAPFunction get_device_boot get_tools patch_boot -if [[ -n ${NOINSTALL} ]]; then - echo "${YELLOW}W: The -n parameter was received. Won't install patched image.${RESET}" +if [[ -n ${INSTALL} ]]; then + log_warn "The -I parameter was received. Will install patched image." + flash_boot +else if [[ "${OS}" == "android" ]]; then - echo "${BLUE}I: Now copying patched image to /storage/emulated/0/patched_boot.img...${RESET}" + log_info "Now copying patched image to /storage/emulated/0/patched_boot.img..." mv ${WORKDIR}/new-boot.img /storage/emulated/0/patched_boot.img else - echo "${BLUE}I: Now copying patched image to ${HOME}/patched_boot.img...${RESET}" + log_info "Now copying patched image to ${HOME}/patched_boot.img..." mv ${WORKDIR}/new-boot.img ${HOME}/patched_boot.img fi - echo "${BLUE}I: Done. Now deleting tmp files...${RESET}" + log_info "Done. Now deleting tmp files..." rm -rf ${WORKDIR} - echo "${GREEN}I: Done.${RESET}" -elif [[ "${OS}" != "android" ]]; then - echo "${BLUE}I: Current OS is: ${OS}. Won't install patched image.${RESET}" -else - flash_boot + log_info "Done." fi print_superkey diff --git a/AAPFunction b/AAPFunction index 4f9024d..01912b6 100755 --- a/AAPFunction +++ b/AAPFunction @@ -1,30 +1,30 @@ #!/bin/env bash -#by nya -#2024-02-04 +#by Akina +#2024-06-03 get_device_boot() { # 未指定boot路径时从设备boot分区获取boot镜像 - echo "${BLUE}I: Getting boot image...${RESET}" + log_info "Getting boot image..." if [[ -z "${BOOTPATH}" ]]; then - echo "${BLUE}I: Current boot: ${BOOTSUFFIX}(If empty: A-Only devices)${RESET}" + log_info "Current boot: ${BOOTSUFFIX}(If empty: A-Only devices)" dd if=${BYNAMEPATH}/boot${BOOTSUFFIX} of=${WORKDIR}/boot${BOOTSUFFIX}.img EXITSTATUS=$? if [[ $EXITSTATUS != 0 ]]; then - echo "${RED}E: GET BOOT IMAGE FAILED${RESET}" + log_err "GET BOOT IMAGE FAILED!" exit 1 fi else cp ${BOOTPATH} ${WORKDIR}/boot${BOOTSUFFIX}.img fi - echo "${GREEN}I: Done.${RESET}" + log_info "Done." } get_tools() { # 从GitHub下载工具 cd ${WORKDIR} || exit 1 - echo "${BLUE}I: Downloading kptools-${OS}...${RESET}" + log_info "Downloading kptools-${OS}..." if [[ -n "${KPTOOLVER}" ]]; then - echo "${BLUE}I: Use the specified version: ${KPTOOLVER}${RESET}" + log_info "Use the specified version: ${KPTOOLVER}" else - echo "${BLUE}I: Use the latest kptools.${RESET}" + log_info "Use the latest kptools." fi if [[ -n "${KPTOOLVER}" ]]; then curl -LO --progress-bar "https://github.com/bmax121/KernelPatch/releases/download/${KPTOOLVER}/kptools-${OS}" @@ -34,13 +34,13 @@ get_tools() { # 从GitHub下载工具 EXITSTATUS=$? fi if [[ $EXITSTATUS != 0 ]]; then - echo "${RED}E: DOWNLOAD FAILED${RESET}" - echo "Please check your internet connection." + log_err "DOWNLOAD FAILED!" + log_err "Please check your internet connection." exit 1 fi chmod +x kptools-${OS} - echo "${GREEN}I: Done.${RESET}" - echo "${BLUE}I: Downloading kpimg-android...${RESET}" + log_info "Done." + log_info "Downloading kpimg-android..." if [[ -n "${KPTOOLVER}" ]]; then curl -LO --progress-bar "https://github.com/bmax121/KernelPatch/releases/download/${KPTOOLVER}/kpimg-android" EXITSTATUS=$? @@ -49,85 +49,86 @@ get_tools() { # 从GitHub下载工具 EXITSTATUS=$? fi if [[ $EXITSTATUS != 0 ]]; then - echo "${RED}E: DOWNLOAD FAILED${RESET}" - echo "Please check your internet connection." + log_err "DOWNLOAD FAILED!" + log_err "Please check your internet connection." exit 1 fi - echo "${GREEN}I: Done.${RESET}" - echo "${BLUE}I: Downloading magiskboot...${RESET}" - curl -LO --progress-bar "https://raw.githubusercontent.com/nya-main/APatchAutoPatchTool/main/bin/magiskboot" + log_info "Done." + log_info "Downloading magiskboot..." + curl -LO --progress-bar "https://raw.githubusercontent.com/AkinaAcct/APatchTool/main/bin/magiskboot" EXITSTATUS=$? if [[ $EXITSTATUS != 0 ]]; then - echo "${RED}E: DOWNLOAD FAILED${RESET}" - echo "Please check your internet connection." + log_err "DOWNLOAD FAILED!" + log_err "Please check your internet connection." exit 1 fi chmod +x magiskboot - echo "${GREEN}I: Done.${RESET}" + log_info "Done." } patch_boot() { # 修补boot镜像 - echo "${BLUE}I: Unpacking image...${RESET}" + log_info "Unpacking image..." ./magiskboot unpack boot${BOOTSUFFIX}.img EXITSTATUS=$? if [[ $EXITSTATUS != 0 ]]; then - echo "${RED}E: UNPACK BOOT IMAGE FAILED!${RESET}" + log_err "UNPACK BOOT IMAGE FAILED!" exit 1 fi - echo "${GREEN}I: Done.${RESET}" - echo "${BLUE}I: Unpatching current image...${RESET}" - ./kptools-${OS} --unpatch --image kernel --out kernel ${EXTRAARGS} || EXITSTATUS=$? + log_info "Done." + log_info "Unpatching current image..." + ./kptools-${OS} --unpatch --image kernel --out kernel || EXITSTATUS=$? if [[ ${EXITSTATUS} != 0 ]]; then - echo "${YELLOW}I: Maybe you are using stock boot image?${RESET}" - echo "${YELLOW}W: Now skipping unpatching...${RESET}" + log_warn "Unpatch failed. Maybe you are using a unpatched boot image?" + log_warn "Now skipping unpatching..." else - echo "${GREEN}I: Done.${RESET}" + log_warn "Done." fi - echo "${BLUE}I: Patching image...Current Superkey: ${SUPERKEY}${RESET}" - ./kptools-${OS} --patch --kpimg kpimg-android --skey "${SUPERKEY}" --image kernel --out kernel + log_info "Patching image...Current Superkey: ${SUPERKEY}" + ./kptools-${OS} --patch --kpimg kpimg-android --skey "${SUPERKEY}" --image kernel --out kernel ${EXTRAARGS} EXITSTATUS=$? if [[ ${EXITSTATUS} != 0 ]]; then - echo "${RED}E: PATCH FAILED!${RESET}" + log_err "PATCH FAILED!" exit 1 fi - echo "${GREEN}I: Done${RESET}" - echo "${BLUE}I: Repacking...${RESET}" + log_info "Done." + log_info "Repacking..." ./magiskboot repack boot${BOOTSUFFIX}.img EXITSTATUS=$? if [[ $EXITSTATUS != 0 ]]; then - echo "${RED}E: REPACK FAILED!${RESET}" + log_err "REPACK FAILED!" exit 1 fi - echo "${GREEN}I: Done.${RESET}" + log_info "Done. Finished paching." } flash_boot() { # 刷入boot镜像 - if [[ "${OS}" != "linux" ]]; then - echo "${BLUE}I: Flashing boot image...${RESET}" + if [[ "${OS}" == "android" ]]; then + log_info "Flashing boot image..." if [[ -n "${TBOOTSUFFIX}" ]]; then - echo "${BLUE}I: You previously specified that you want to install to another slot. Target slot:${TBOOTSUFFIX}." + log_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 - echo "${RED}E: WARNING!!! IMAGE FLASH FAILED${RESET}" - echo "${YELLOW}I: Now trying to restore...${RESET}" + log_err "WARNING! IMAGE FLASH FAILED!" + log_err "Now trying to restore..." dd if=${WORKDIR}/boot${BOOTSUFFIX}.img of=${BYNAMEPATH}/boot${BOOTSUFFIX} EXITSTATUS=$? if [[ ${EXITSTATUS} != 0 ]]; then - echo "${RED}E: WARNING!!! RESTORE FAILED!!!" - echo "Even I can't help you now. You can try to restore boot manually.${RESET}" + log_err "WARNING!!! RESTORE FAILED!!!" + log_err "Even I can't help you now. You can try to restore boot manually." exit 1 fi - echo "${YELLOW}I: Restore Sucessfully.${RESET}" + log_info "Restore Sucessfully." fi - echo "${GREEN}I: Flash done.${RESET}" - echo "${BLUE}I: Cleaning temporary files...${RESET}" + log_info "Flash done." + log_info "Cleaning temporary files..." rm -rf ${WORKDIR} - echo "${GREEN}I: Done.${RESET}" + log_info "Done." else - echo "${RED}E: You are trying to change this script. Linux does not require a flashing step. This is the second level of warning.${RESET}" + log_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 } diff --git a/README.md b/README.md index 295c9e8..93eb763 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ # APatch Auto Patch Tool A script that provides custom patching options. -> [!NOTE] -> You can also try the [new version](/new) - -[中文](./README_CN.md) +> [!WARNING] +> Still under testing! --- @@ -19,14 +17,14 @@ This script has the following functions: ## Usage -- Open Termux +- Open Termux(or MT terminal,etc.) - Prepare ```bash cd ${HOME} -curl -LO https://raw.githubusercontent.com/nya-main/APatchAutoPatchTool/main/AAP.sh -chmod +x AAP.sh +curl -LO https://raw.githubusercontent.com/nya-main/APatchAutoPatchTool/main/new/AAP.sh +chmod +x AAP-New.sh ``` *After this, You can directly run AAP.sh after command tsu is executed.* @@ -34,21 +32,9 @@ chmod +x AAP.sh - Run Usage: -```text -APatch Auto Patch Tool -Written by Akina -Version: 1.0.1 -Current DIR: $(pwd) - --h, -v, print the usage and version. - --i [BOOT IMAGE PATH], specify a boot image path. --n, do not install the patched boot image, save the image in /storage/emulated/0/patched_boot.img, or on Linux /home/atopes/patched_boot.img. --k [RELEASE NAME], specify a kernelpatch version [RELEASE NAME]. --s "STRING", specify a superkey. Use STRING as superkey. --S, Install to another slot (for OTA). --E [ARGS], Add args [ARGS] to kptools when patching. --V, verbose mode. + +```shell +./AAP.sh -h ``` --- @@ -63,8 +49,7 @@ Current DIR: $(pwd) --- - -If you encounter any issues, please submit a issue on github or provide feedback to me: [Telegram](https://t.me/RhineNya) +If you encounter any issues, please submit a issue on github. --- diff --git a/README_CN.md b/README_CN.md deleted file mode 100644 index 1deb98e..0000000 --- a/README_CN.md +++ /dev/null @@ -1,67 +0,0 @@ -# APatch 自动补丁工具 - -一个提供自定义 APatch 修补功能的脚本. - -[English](./README.md) - ---- - -这个脚本有以下功能: - -- 用户自定义boot镜像路径或从当前手机获取. -- 用户自定义KernelPatch版本. 或,默认最新. -- 用户自定义SuperKey.[什么是SuperKey](https://github.com/bmax121/APatch/blob/main/docs/en/faq.md#what-is-superkey) -- 支持仅修补不安装 - ---- - -## 食用方法 - -- 打开Termux - -- 一些准备 - -```bash -cd ${HOME} -curl -LO https://raw.githubusercontent.com/nya-main/APatchAutoPatchTool/main/AAP.sh -chmod +x AAP.sh -``` - -*在此之后,您可以在执行命令 tsu 后直接运行 AAP.sh。* - -- 运行 - -使用方法: - -``` -APatch Auto Patch Tool -Written by nya -Version: 1.0.0 - --h, -v, print the usage and version. - --i [BOOT IMAGE PATH], specify a boot image path. --n, do not install the patched boot image, save the image in /storage/emulated/0/patched_boot.img, or on Linux, ${HOME}/patched_boot.img. --k [RELEASE NAME], specify a kernelpatch version [RELEASE NAME]. --s "STRING", specify a superkey. Use STRING as superkey. --V, verbose mode. -``` - -## 待办事项 - -- [x] 用户指定的启动映像路径。 -- [x] 用户指定的超级密钥。 -- [x] 用户指定的 KernelPatch 版本。 -- [x] 其他终端软件支持(如MT)。 -- [x] Linux 支持。 - ---- - -如果您遇到任何问题,请在 GitHub 上提交问题或向我提供反馈: [Telegram](https://t.me/RhineNya) - ---- - -特别鸣谢: - -- [Magisk](https://github.com/topjohnwu/magisk): 由 magiskboot 提供支持。 -- [KernelPatch](https://github.com/bmax121/KernelPatch): 由 kptools 和 kpimg 提供支持。 diff --git a/new/AAP-New.sh b/new/AAP-New.sh deleted file mode 100755 index afe6395..0000000 --- a/new/AAP-New.sh +++ /dev/null @@ -1,200 +0,0 @@ -#!/bin/sh -#by Akina | LuoYan -#2024-06-03 Rewrite - -RED="\E[1;31m" -YELLOW="\E[1;33m" -BLUE="\E[1;34m" -GREEN="\E[1;32m" -RESET="\E[0m" -LUOYANRANDOM="$(date "+%N")" -log_info() { - echo -e "${BLUE}[INFO] $(date "+%H:%M:%S"): $1${RESET}" -} -log_err() { - echo -e "${RED}[ERROR] $(date "+%H:%M:%S"): $1${RESET}" -} -log_warn() { - echo -e "${YELLOW}[WARN] $(date "+%H:%M:%S"): $1${RESET}" -} -print_help() { - echo -e "${GREEN}" - cat <<-EOF - APatch Auto Patch Tool - Written by Akina - Version: 2.0.0 - Current DIR: $(pwd) - - -h, -v, print the usage and version. - - -i [BOOT IMAGE PATH], specify a boot image path. - -n, do not install the patched boot image, save the image in /storage/emulated/0/patched_boot.img, or on Linux ${HOME}/patched_boot.img. - -k [RELEASE NAME], specify a kernelpatch version [RELEASE NAME]. - -s "STRING", specify a superkey. Use STRING as superkey. - -S, Install to another slot (for OTA). - -E [ARGS], Add args [ARGS] to kptools when patching. - -V, verbose mode. - EOF - echo -e "${RESET}" - exit 0 -} - -# 参数解析 -while getopts ":hvi:k:nVs:SE:" OPT; do - case $OPT in - i) # 处理选项i - BOOTPATH="${OPTARG}" - if [[ -e "${BOOTPATH}" ]]; then - log_info "Boot image path specified. Current image path: ${BOOTPATH}" - else - log_err "SPECIFIED BOOT IMAGE PATH IS WRONG! NO SUCH FILE!" - exit 1 - fi - ;; - h | v) - print_help - ;; - 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." - ;; - V) - set -x - log_warn "DEBUG MODE IS ON." - ;; - n) - NOINSTALL="true" - log_info "The -n parameter was received. Won't install after patch." - ;; - s) - SUPERKEY="${OPTARG}" - log_info "The -s parameter was received. Currently specified SuperKey: ${SUPERKEY}." - ;; - k) - KPTOOLVER="${OPTARG}" - log_info "The -k parameter was received. Will use kptool ${KPTOOLVER}." - ;; - E) - EXTRAARGS="${OPTARG}" - log_info "The -E parameter was received. Current extra args: ${EXTRAARGS}" - ;; - :) - log_err "Option -${OPTARG} requires an argument.." >&2 && exit 1 - ;; - - ?) - log_err "Invalid option: -${OPTARG}" >&2 && exit 1 - ;; - esac -done - -# ROOT 检测 -if [[ $(id -u) -ne 0 ]]; then - log_err "Run this script with root!" - exit 127 -fi -# OS 检测 -if (command -v getprop >/dev/null 2>&1); then - OS="android" - log_info "OS: ${OS}" -else - OS="linux" - log_warn "You are using ${OS}.Using this script on ${OS} is still under testing." - if [[ -z "${BOOTPATH}" ]]; then - log_err "You are using ${OS}, but there is no image specified by you. Exited." - exit 1 - fi -fi -# 设置工作文件夹 -if [[ "${OS}" == "android" ]]; then - WORKDIR="./LuoYanTmp_${LUOYANRANDOM}" -else - WORKDIR="/tmp/LuoYanTmp_${LUOYANRANDOM}" -fi -# 判断用户设备是否为ab分区,是则设置$BOOTSUFFIX -BYNAMEPATH="$(getprop ro.frp.pst | sed 's/\/frp//g')" -if [[ "${OS}" == "android" ]]; then - if [[ ! -e ${BYNAMEPATH}/boot ]]; then - BOOTSUFFIX=$(getprop ro.boot.slot_suffix) - fi -else - log_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}." -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." - 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)" - LKPVER="$(${APKLIBPATH}/libkpatch.so -v)" - cat <<-EOF - Installed manager(apd) version: $(echo -e "${BLUE}${APDVER}${RESET}") - APatch app built-in KernelPatch version: $(echo -e "${BLUE}${LKPVER}${RESET}") - EOF - fi -fi - -# 清理可能存在的上次运行文件 -rm -rf /tmp/LuoYanTmp_* -rm -rf ./LuoYanTmp_* -mkdir -p "${WORKDIR}" - -log_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!" - exit 1 -fi - -# 备份boot -if [[ "${OS}" == "android" ]]; then - log_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..." - else - log_info "Done. Boot image path: /storage/emulated/0/stock_boot${BOOTSUFFIX}.img" - fi -else - log_info "Current OS: ${OS}. Skiping backup..." -fi - -# 加载操作文件 -source ${WORKDIR}/AAPFunction - -get_device_boot -get_tools -patch_boot -if [[ -n ${NOINSTALL} ]]; then - log_warn "The -n parameter was received. Won't install patched image." - if [[ "${OS}" == "android" ]]; then - log_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..." - mv ${WORKDIR}/new-boot.img ${HOME}/patched_boot.img - fi - log_info "Done. Now deleting tmp files..." - rm -rf ${WORKDIR} - log_info "Done." -elif [[ "${OS}" != "android" ]]; then - log_info "Current OS is: ${OS}. Won't install patched image." -else - flash_boot -fi -print_superkey diff --git a/new/AAPFunction b/new/AAPFunction deleted file mode 100755 index 01912b6..0000000 --- a/new/AAPFunction +++ /dev/null @@ -1,148 +0,0 @@ -#!/bin/env bash -#by Akina -#2024-06-03 - -get_device_boot() { # 未指定boot路径时从设备boot分区获取boot镜像 - log_info "Getting boot image..." - if [[ -z "${BOOTPATH}" ]]; then - log_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!" - exit 1 - fi - else - cp ${BOOTPATH} ${WORKDIR}/boot${BOOTSUFFIX}.img - fi - log_info "Done." -} - -get_tools() { # 从GitHub下载工具 - cd ${WORKDIR} || exit 1 - log_info "Downloading kptools-${OS}..." - if [[ -n "${KPTOOLVER}" ]]; then - log_info "Use the specified version: ${KPTOOLVER}" - else - log_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 - log_err "DOWNLOAD FAILED!" - log_err "Please check your internet connection." - exit 1 - fi - chmod +x kptools-${OS} - log_info "Done." - log_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 - log_err "DOWNLOAD FAILED!" - log_err "Please check your internet connection." - exit 1 - fi - log_info "Done." - log_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." - exit 1 - fi - chmod +x magiskboot - log_info "Done." -} - -patch_boot() { # 修补boot镜像 - log_info "Unpacking image..." - ./magiskboot unpack boot${BOOTSUFFIX}.img - EXITSTATUS=$? - if [[ $EXITSTATUS != 0 ]]; then - log_err "UNPACK BOOT IMAGE FAILED!" - exit 1 - fi - log_info "Done." - log_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..." - else - log_warn "Done." - fi - log_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!" - exit 1 - fi - log_info "Done." - log_info "Repacking..." - ./magiskboot repack boot${BOOTSUFFIX}.img - EXITSTATUS=$? - if [[ $EXITSTATUS != 0 ]]; then - log_err "REPACK FAILED!" - exit 1 - fi - log_info "Done. Finished paching." -} - -flash_boot() { # 刷入boot镜像 - if [[ "${OS}" == "android" ]]; then - log_info "Flashing boot image..." - if [[ -n "${TBOOTSUFFIX}" ]]; then - log_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..." - 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." - exit 1 - fi - log_info "Restore Sucessfully." - fi - log_info "Flash done." - log_info "Cleaning temporary files..." - rm -rf ${WORKDIR} - log_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." - exit 1 - fi -} - -print_superkey() { # 打印 SUPERKEY - cat < [!NOTE] -> This is the `new` folder, which means that the new version of APatch Auto Patch Tool is stored here. - ---- - -This script has the following functions: - -- User-specified image path or get from current Android device. -- User-specified KernelPatch version. Or default, latest release. -- User-specified SuperKey.[What is SuperKey?](https://apatch.top/faq.html#what-is-superkey) -- Only patch but not install support. - ---- - -## Usage - -- Open Termux(or MT terminal,etc.) - -- Prepare - -```bash -cd ${HOME} -curl -LO https://raw.githubusercontent.com/nya-main/APatchAutoPatchTool/main/new/AAP-New.sh -chmod +x AAP-New.sh -``` - -*After this, You can directly run AAP-New.sh after command tsu is executed.* - -- Run - -Usage: -```text -APatch Auto Patch Tool -Written by Akina -Version: 2.0.0 -Current DIR: $(pwd) - --h, -v, print the usage and version. - --i [BOOT IMAGE PATH], specify a boot image path. --n, do not install the patched boot image, save the image in /storage/emulated/0/patched_boot.img, or on Linux /home/atopes/patched_boot.img. --k [RELEASE NAME], specify a kernelpatch version [RELEASE NAME]. --s "STRING", specify a superkey. Use STRING as superkey. --S, Install to another slot (for OTA). --E [ARGS], Add args [ARGS] to kptools when patching. --V, verbose mode. -``` - ---- - -## TODO - -- [x] User-specified boot image path. -- [x] User-specified Superkey. -- [x] User-specified KernelPatch version. -- [x] Other terminal software support(e.g. MT). -- [x] Linux Support. - ---- - -If you encounter any issues, please submit a issue on github. - ---- - -Credits: - -- [Magisk](https://github.com/topjohnwu/magisk): For magiskboot - -- [KernelPatch](https://github.com/bmax121/KernelPatch): For kptools and kpimg