Fix update operation in ksu/apatch

Simplified the code, better readability.
This commit is contained in:
KOWX712
2024-12-11 15:05:45 +08:00
parent 06d2edf57f
commit 9302d39910
10 changed files with 116 additions and 101 deletions

View File

@@ -27,7 +27,7 @@ Telegram channel: [KOW's Little World](https://t.me/kowchannel)
- New way to detect Xposed module, now can catch all Xposed module apk package name in Deselect Unnecessary option, feedback in [Telegram](https://t.me/kowchannel) or [create issue](https://github.com/KOWX712/Tricky-Addon-Update-Target-List/issues) if missed any.
- **Initial support for multiple languages**
- Language available: **en-US**, **ru-RU**, **tl-PH**, **zh-CN**, **zh-TW**
- Add language or fix translation error? [Read here](https://github.com/KOWX712/Tricky-Addon-Update-Target-List/tree/master/module/webroot/locales/A-translate.md).
- Add language or fix translation error? [Read here](https://github.com/KOWX712/Tricky-Addon-Update-Target-List/tree/master/module/webui/locales/A-translate.md).
### v2.6-beta.3
- Check in [release notes](https://github.com/KOWX712/Tricky-Addon-Update-Target-List/releases/tag/v2.6-beta.3).

View File

@@ -5,16 +5,68 @@
MODPATH="/data/adb/modules/.TA_utl"
COMPATH="$MODPATH/common"
SCRIPT_DIR="/data/adb/tricky_store"
URL="https://github.com/5ec1cff/KsuWebUIStandalone/releases/download/v1.0/KsuWebUI-1.0-34-release.apk"
APK_DIR="$COMPATH/tmp"
BBPATH="/data/adb/magisk/busybox \
/data/adb/ksu/bin/busybox \
/data/adb/ap/bin/busybox \
/data/adb/modules/busybox-ndk/system/*/busybox"
. "$COMPATH/util_func.sh"
check_wget() {
for path in $BBPATH; do
[ -f "$path" ] && BUSYBOX="$path" && break
done
if ! command -v wget >/dev/null || grep -q "wget-curl" "$(command -v wget)"; then
if [ -n "$BUSYBOX" ]; then
wget() { "$BUSYBOX" wget "$@"; }
else
exit 1
fi
fi
}
if pm list packages | grep -q "$PACKAGE_NAME"; then
get_webui() {
echo "- Downloading the WebUI APK..."
check_wget
if ! wget --no-check-certificate -P "$APK_DIR" "$URL"; then
echo "! Error: APK download failed."
exit 1
fi
echo "- Download complete."
APK_PATH=$(find "$APK_DIR" -type f -name "*.apk" | head -n 1)
if [ -z "$APK_PATH" ]; then
echo "! Error: No APK file found in $APK_DIR."
exit 1
fi
echo "- Installing..."
if ! pm install -r "$APK_PATH" >/dev/null 2>&1; then
echo "! Error: APK installation failed."
rm -f "$APK_PATH"
exit 1
fi
echo "- Done."
rm -f "$APK_PATH"
echo "- Launching..."
if ! am start -n "io.github.a13e300.ksuwebui/.WebUIActivity" -e id "tricky_store"; then
echo "! Error: WebUI launch failed."
exit 1
fi
echo "- Application launched successfully."
}
# Lunch KSUWebUI standalone or MMRL, install KSUWebUI standalone if both are not installed
if pm list packages | grep -q "io.github.a13e300.ksuwebui"; then
echo "- Launching WebUI in KSUWebUIStandalone..."
am start -n "${PACKAGE_NAME}/.WebUIActivity" -e id "tricky_store"
am start -n "io.github.a13e300.ksuwebui/.WebUIActivity" -e id "tricky_store"
elif pm list packages | grep -q "com.dergoogler.mmrl"; then
echo "- Launching WebUI in MMRL WebUI..."
am start -n "com.dergoogler.mmrl/.ui.activity.webui.WebUIActivity" -e MOD_ID "tricky_store"
else
echo "- Installing KSU WebUI..."
. "$COMPATH/get_WebUI.sh"
fi
get_webui
fi

View File

@@ -1,26 +0,0 @@
URL="https://github.com/5ec1cff/KsuWebUIStandalone/releases/download/v1.0/KsuWebUI-1.0-34-release.apk"
APK_DIR="$COMPATH"
check_wget
echo "- Downloading the WebUI apk..."
download_webui
echo "- Download complete."
APK_PATH=$(find "$APK_DIR" -type f -name "*.apk" | head -n 1)
if [ -z "$APK_PATH" ]; then
echo "Error: No APK file found in $APK_DIR."
exit 1
fi
echo "- Installing..."
install_webui
echo "- Done."
rm -f "$APK_PATH"
echo "- Launching..."
am start -n "${PACKAGE_NAME}/.WebUIActivity" -e id "tricky_store" </dev/null 2>&1 | cat
if [ $? -ne 0 ]; then
echo "Error: Failed to start application."
exit 1
fi
echo "- Application launched successfully."

View File

@@ -1,20 +1,37 @@
#!/system/bin/sh
MODPATH=${0%/*}
SKIPLIST="$MODPATH/skiplist"
OUTPUT="$MODPATH/exclude-list"
KBOUTPUT="$MODPATH/.extra"
SKIPLIST="$MODPATH/tmp/skiplist"
OUTPUT="$MODPATH/tmp/exclude-list"
KBOUTPUT="$MODPATH/tmp/.extra"
BBPATH="/data/adb/magisk/busybox \
/data/adb/ksu/bin/busybox \
/data/adb/ap/bin/busybox \
/data/adb/modules/busybox-ndk/system/*/busybox"
. $MODPATH/util_func.sh
check_wget() {
for path in $BBPATH; do
[ -f "$path" ] && BUSYBOX="$path" && break
done
if ! command -v wget >/dev/null || grep -q "wget-curl" "$(command -v wget)"; then
if [ -n "$BUSYBOX" ]; then
wget() { "$BUSYBOX" wget "$@"; }
else
exit 1
fi
fi
}
check_wget
aapt() { "$MODPATH/aapt" "$@"; }
get_kb() {
check_wget
wget --no-check-certificate -qO "$KBOUTPUT" "https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/.extra"
[ -s "$KBOUTPUT" ] || rm -f "$KBOUTPUT"
}
get_unnecessary() {
check_wget
if [ ! -s "$OUTPUT" ] || [ ! -f "$OUTPUT" ]; then
wget --no-check-certificate -q -O - "https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/more-excldue.json" 2>/dev/null | \
grep -o '"package-name": *"[^"]*"' | \
@@ -34,10 +51,11 @@ get_xposed() {
}
check_update() {
if [ -d "$MODPATH/temp" ]; then
check_wget
if [ -d "$MODPATH/update" ]; then
JSON=$(wget --no-check-certificate -q -O - "https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/update.json")
REMOTE_VERSION=$(echo "$JSON" | grep -o '"versionCode": *[0-9]*' | awk -F: '{print $2}' | tr -d ' ')
LOCAL_VERSION=$(grep -o 'versionCode=[0-9]*' "$MODPATH/temp/module.prop" | awk -F= '{print $2}')
LOCAL_VERSION=$(grep -o 'versionCode=[0-9]*' "$MODPATH/update/module.prop" | awk -F= '{print $2}')
if [ "$REMOTE_VERSION" -gt "$LOCAL_VERSION" ]; then
echo "update"
fi
@@ -49,4 +67,4 @@ case "$1" in
--unnecessary) get_unnecessary; exit ;;
--xposed) get_xposed; exit ;;
--update) check_update; exit ;;
esac
esac

View File

@@ -1,38 +0,0 @@
PACKAGE_NAME="io.github.a13e300.ksuwebui"
MODID="set-id"
BBPATH="/data/adb/magisk/busybox \
/data/adb/ksu/bin/busybox \
/data/adb/ap/bin/busybox \
/data/adb/modules/busybox-ndk/system/*/busybox"
check_wget() {
for path in $BBPATH; do
[ -f "$path" ] && BUSYBOX="$path" && break
done
if ! command -v wget >/dev/null || grep -q "wget-curl" "$(command -v wget)"; then
if [ -n "$BUSYBOX" ]; then
wget() { "$BUSYBOX" wget "$@"; }
else
exit 1
fi
fi
}
aapt() { "$MODPATH/aapt" "$@"; }
download_webui() {
wget --no-check-certificate -P "$APK_DIR" "$URL"
if [ $? -ne 0 ]; then
echo "Error: APK download failed."
exit 1
fi
}
install_webui() {
pm install -r "$APK_PATH" </dev/null 2>&1 | cat
if [ $? -ne 0 ]; then
echo "Error: APK installation failed."
rm -f "$APK_PATH"
exit 1
fi
}

View File

@@ -39,5 +39,11 @@ migrate_old_boot_hash
rm -f "$MODPATH/install_func.sh"
ui_print " "
ui_print "! This module is not a part of the Tricky Store module. DO NOT report any issues to Tricky Store if encountered."
ui_print " "
sleep 1
ui_print "- Installation completed successfully! "
ui_print " "

View File

@@ -4,17 +4,15 @@ initialize() {
# Set permission
set_perm $COMPATH/get_extra.sh 0 2000 0755
set_perm $COMPATH/get_WebUI.sh 0 2000 0755
# Handdle Magisk/non-Magisk root manager
if [ "$ACTION" = "false" ]; then
rm -f "$MODPATH/action.sh"
rm -f "$COMPATH/get_WebUI.sh"
NEW_MODID="$MODID"
else
mkdir -p "$COMPATH/temp/common"
cp "$COMPATH/.default" "$COMPATH/temp/common/.default"
cp "$MODPATH/uninstall.sh" "$COMPATH/temp/uninstall.sh"
mkdir -p "$COMPATH/update/common"
cp "$COMPATH/.default" "$COMPATH/update/common/.default"
cp "$MODPATH/uninstall.sh" "$COMPATH/update/uninstall.sh"
fi
#Set specific path
@@ -22,13 +20,9 @@ initialize() {
ui_print "! Failed to set path"
abort
}
sed -i "s|\"set-id\"|\"$NEW_MODID\"|" "$COMPATH/util_func.sh" || {
ui_print "! Failed to set id"
abort
}
# Set aapt binary
cp "$MODPATH/module.prop" "$COMPATH/temp/module.prop"
cp "$MODPATH/module.prop" "$COMPATH/update/module.prop"
mv "$MODPATH/bin/$(getprop ro.product.cpu.abi)/aapt" "$COMPATH/aapt"
set_perm $COMPATH/aapt 0 2000 0755
rm -rf "$MODPATH/bin"

View File

@@ -36,13 +36,14 @@ rm -f "$MODPATH/module.prop"
ln -s "$MODPATH/webui" "$TS/webroot"
# Optimization
OUTPUT_APP="$MODPATH/common/applist"
OUTPUT_SKIP="$MODPATH/common/skiplist"
OUTPUT_APP="$MODPATH/common/tmp/applist"
OUTPUT_SKIP="$MODPATH/common/tmp/skiplist"
until [ "$(getprop sys.boot_completed)" = "1" ]; do
sleep 1
done
mkdir -p "$MODPATH/common/tmp"
echo "# This file is generated from service.sh to speed up load time" > "$OUTPUT_APP"
echo "# This file is generated from service.sh to speed up load time" > "$OUTPUT_SKIP"
pm list packages -3 </dev/null 2>&1 | cat | awk -F: '{print $2}' | while read -r PACKAGE; do

View File

@@ -356,9 +356,17 @@ async function updateCheck() {
showPrompt("new_update");
updateCard.style.display = "flex";
await execCommand(`
su -c "mkdir -p '/data/adb/modules/TA_utl' &&
cp -rf '${basePath}common/temp/'* '/data/adb/modules/TA_utl/'"
`);
su -c "
if [ -f '${basePath}action.sh' ]; then
if [ -d "/data/adb/modules/TA_utl" ]; then
rm -rf "/data/adb/modules/TA_utl"
fi
cp -rf '${basePath}common/update' '/data/adb/modules/TA_utl'
else
cp '${basePath}common/update/module.prop' '/data/adb/modules/TA_utl/module.prop'
fi
"
`);
} else {
console.log("No update detected from extra script.");
}
@@ -372,19 +380,19 @@ async function updateCheck() {
// Function to read the exclude list and uncheck corresponding apps
async function deselectUnnecessaryApps() {
try {
const fileCheck = await execCommand(`test -f ${basePath}common/exclude-list && echo "exists" || echo "not found"`);
const fileCheck = await execCommand(`test -f ${basePath}common/tmp/exclude-list && echo "exists" || echo "not found"`);
if (fileCheck.trim() === "not found") {
setTimeout(async () => {
await execCommand(`sh ${basePath}common/get_extra.sh --unnecessary`);
}, 100);
}, 0);
console.log("Exclude list not found. Running the unnecessary apps script.");
} else {
setTimeout(async () => {
await execCommand(`sh ${basePath}common/get_extra.sh --xposed`);
}, 100);
}, 0);
console.log("Exclude list found. Running xposed script.");
}
const result = await execCommand(`cat ${basePath}common/exclude-list`);
const result = await execCommand(`cat ${basePath}common/tmp/exclude-list`);
const UnnecessaryApps = result.split("\n").map(app => app.trim()).filter(Boolean);
const apps = document.querySelectorAll(".card");
apps.forEach(app => {
@@ -467,7 +475,7 @@ async function extrakb() {
setTimeout(async () => {
await execCommand(`sh ${basePath}common/get_extra.sh --kb`);
}, 100);
const sourcePath = `${basePath}common/.extra`;
const sourcePath = `${basePath}common/tmp/.extra`;
const destinationPath = "/data/adb/tricky_store/keybox.xml";
try {
await new Promise(resolve => setTimeout(resolve, 300));
@@ -581,7 +589,7 @@ async function fetchAppList() {
let applistMap = {};
try {
const applistResult = await execCommand(`cat ${basePath}common/applist`);
const applistResult = await execCommand(`cat ${basePath}common/tmp/applist`);
applistMap = applistResult
.split("\n")
.reduce((map, line) => {
@@ -718,7 +726,7 @@ document.querySelector(".uninstall-container").addEventListener("click", async (
if [ -d "/data/adb/modules/TA_utl" ]; then
rm -rf "/data/adb/modules/TA_utl"
fi
cp -rf '${basePath}common/temp' '/data/adb/modules/TA_utl' &&
cp -rf '${basePath}common/update' '/data/adb/modules/TA_utl' &&
touch '/data/adb/modules/TA_utl/remove'
else
touch '${basePath}remove'