fix: resolve the issues

This commit is contained in:
2026-05-15 11:08:20 +07:00
parent c48c4abc17
commit d7a7688aa8
17 changed files with 298 additions and 189 deletions
Regular → Executable
+65 -73
View File
@@ -37,98 +37,92 @@ pmex() {
return $RET
}
if ! pmex path "$PKG_NAME" >&2; then
if pmex install-existing "$PKG_NAME" >&2; then
pmex uninstall-system-updates "$PKG_NAME"
if OP=$(dumpsys package "$PKG_NAME") && [ "$OP" ]; then
if echo "$OP" | grep -m1 pkgFlags | grep -Fq UPDATED_SYSTEM_APP; then
pmex uninstall-system-updates "$PKG_NAME" >/dev/null 2>&1
fi
else
if pmex install-existing "$PKG_NAME" >/dev/null 2>&1; then
pmex uninstall-system-updates "$PKG_NAME" >/dev/null 2>&1
fi
fi
IS_SYS=false
INS=true
if BASEPATH=$(pmex path "$PKG_NAME"); then
echo >&2 "'$BASEPATH'"
BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH%/*}
if [ "${BASEPATH:1:4}" != data ]; then
ui_print "* $PKG_NAME is a system app."
IS_SYS=true
elif [ ! -f "$MODPATH/$PKG_NAME.apk" ]; then
ui_print "* Stock $PKG_NAME APK was not found"
VERSION=$(dumpsys package "$PKG_NAME" 2>&1 | grep -m1 versionName) VERSION="${VERSION#*=}"
if [ "$VERSION" = "$PKG_VER" ] || [ -z "$VERSION" ]; then
ui_print "* Skipping stock installation"
INS=false
else
abort "ERROR: Version mismatch
installed: $VERSION
module: $PKG_VER
"
fi
elif "${MODPATH:?}/bin/$ARCH/cmpr" "$BASEPATH/base.apk" "$MODPATH/$PKG_NAME.apk"; then
ui_print "* $PKG_NAME is up-to-date"
INS=false
ui_print "* Detected $PKG_NAME as a system app"
SCNM="/data/adb/post-fs-data.d/$PKG_NAME-uninstall.sh"
mkdir -p /data/adb/post-fs-data.d
echo "mount -t tmpfs none $BASEPATH" >"$SCNM"
chmod +x "$SCNM"
ui_print "* Created the uninstall script."
ui_print ""
ui_print "* Reboot and reflash the module!"
abort
fi
VERSION=$(dumpsys package "$PKG_NAME" 2>&1 | grep -m1 versionName=) VERSION="${VERSION#*=}"
if [ "$VERSION" ] && [ "$VERSION" = "$PKG_VER" ]; then
ui_print "* $PKG_NAME is up-to-date ($VERSION)"
INS=false
elif [ ! -f "$MODPATH/stock/base.apk" ]; then
ui_print "ERROR: Version mismatch
installed: '$VERSION'
module: '$PKG_VER'"
abort
fi
# TODO:
# elif "${MODPATH:?}/bin/$ARCH/cmpr" "$BASEPATH/base.apk" "$MODPATH/$PKG_NAME.apk"; then
# ui_print "* $PKG_NAME is up-to-date"
# INS=false
# fi
fi
install() {
if [ ! -f "$MODPATH/$PKG_NAME.apk" ]; then
if [ ! -f "$MODPATH/stock/base.apk" ]; then
abort "ERROR: Stock $PKG_NAME apk was not found"
fi
ui_print "* Updating $PKG_NAME to $PKG_VER"
install_err=""
VERIF1=$(settings get global verifier_verify_adb_installs)
VERIF2=$(settings get global package_verifier_enable)
settings put global verifier_verify_adb_installs 0
settings put global package_verifier_enable 0
SZ=$(stat -c "%s" "$MODPATH/$PKG_NAME.apk")
SZ=$(stat -c "%s" "$MODPATH"/stock/*.apk | awk '{sum += $0} END {print sum}')
for IT in 1 2; do
if ! SES=$(pmex install-create --user 0 -i com.android.vending -r -d -S "$SZ"); then
ui_print "* Updating $PKG_NAME to $PKG_VER"
if ! SES=$(pmex install-create --user 0 -i com.android.vending -r -S "$SZ"); then
ui_print "ERROR: install-create failed"
install_err="$SES"
break
fi
SES=${SES#*[} SES=${SES%]*}
set_perm "$MODPATH/$PKG_NAME.apk" 1000 1000 644 u:object_r:apk_data_file:s0
if ! op=$(pmex install-write -S "$SZ" "$SES" "$PKG_NAME.apk" "$MODPATH/$PKG_NAME.apk"); then
ui_print "ERROR: install-write failed"
install_err="$op"
break
fi
for apki in "$MODPATH/stock"/*.apk; do
set_perm "${apki}" 1000 1000 644 u:object_r:apk_data_file:s0
if ! op=$(pmex install-write -S "$SZ" "$SES" "$(basename "${apki}")" "${apki}"); then
ui_print "ERROR: install-write failed"
install_err="$op"
break
fi
done
if [ "$install_err" ]; then break; fi
if ! op=$(pmex install-commit "$SES"); then
ui_print "$op"
if echo "$op" | grep -q -e INSTALL_FAILED_VERSION_DOWNGRADE -e INSTALL_FAILED_UPDATE_INCOMPATIBLE; then
ui_print "* Handling install error"
pmex uninstall-system-updates "$PKG_NAME"
if BASEPATH=$(pmex path "$PKG_NAME"); then
BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH%/*}
if [ "${BASEPATH:1:4}" != data ]; then IS_SYS=true; fi
fi
if [ "$IS_SYS" = true ]; then
SCNM="/data/adb/post-fs-data.d/$PKG_NAME-uninstall.sh"
if [ -f "$SCNM" ]; then
ui_print "* Remove the old module. Reboot and reflash!"
ui_print ""
install_err=" "
ui_print "* Uninstalling..."
if ! op=$(pmex uninstall "$PKG_NAME"); then
ui_print "$op"
if [ $IT = 2 ]; then
install_err="ERROR: pm uninstall failed."
break
fi
mkdir -p /data/adb/rvhc/empty /data/adb/post-fs-data.d
echo "mount -o bind /data/adb/rvhc/empty $BASEPATH" >"$SCNM"
chmod +x "$SCNM"
ui_print "* Created the uninstall script."
ui_print ""
ui_print "* Reboot and reflash the module!"
install_err=" "
break
else
ui_print "* Uninstalling..."
if ! op=$(pmex uninstall -k --user 0 "$PKG_NAME"); then
ui_print "$op"
if [ $IT = 2 ]; then
install_err="ERROR: pm uninstall failed."
break
fi
fi
continue
fi
continue
fi
ui_print "ERROR: install-commit failed"
install_err="$op"
@@ -145,8 +139,7 @@ install() {
settings put global verifier_verify_adb_installs "$VERIF1"
settings put global package_verifier_enable "$VERIF2"
if [ "$install_err" ]; then
ui_print "$install_err"
abort "ERROR: disable the module, reboot, install $PKG_NAME manually and reflash again"
abort "$install_err"
fi
}
if [ $INS = true ] && ! install; then abort; fi
@@ -154,11 +147,11 @@ BASEPATHLIB=${BASEPATH}/lib/${ARCH}
if [ $INS = true ] || [ -z "$(ls -A1 "$BASEPATHLIB")" ]; then
ui_print "* Extracting native libs"
if [ ! -d "$BASEPATHLIB" ]; then mkdir -p "$BASEPATHLIB"; else rm -f "$BASEPATHLIB"/* >/dev/null 2>&1 || :; fi
if ! op=$(unzip -o -j "$MODPATH/$PKG_NAME.apk" "lib/${ARCH_LIB}/*" -d "$BASEPATHLIB" 2>&1); then
ui_print "ERROR: extracting native libs failed"
abort "$op"
if op=$(unzip -o -j "$MODPATH/stock/base.apk" "lib/${ARCH_LIB}/*" -d "$BASEPATHLIB" 2>&1); then
set_perm_recursive "${BASEPATH}/lib" 1000 1000 755 755 u:object_r:apk_data_file:s0
else
echo >&2 "ERROR: extracting native libs failed: '$op'"
fi
set_perm_recursive "${BASEPATH}/lib" 1000 1000 755 755 u:object_r:apk_data_file:s0
fi
ui_print "* Setting Permissions"
@@ -176,14 +169,14 @@ fi
am force-stop "$PKG_NAME"
ui_print "* Optimizing $PKG_NAME"
cmd package compile -m speed-profile -f "$PKG_NAME"
cmd package compile -m speed-profile -f "$PKG_NAME" >/dev/null 2>&1
# nohup cmd package compile -m speed-profile -f "$PKG_NAME" >/dev/null 2>&1
if [ "$KSU" ]; then
UID=$(dumpsys package "$PKG_NAME" 2>&1 | grep -m1 uid)
UID=$(dumpsys package "$PKG_NAME" 2>&1 | grep -m1 uid=)
UID=${UID#*=} UID=${UID%% *}
if [ -z "$UID" ]; then
UID=$(dumpsys package "$PKG_NAME" 2>&1 | grep -m1 userId)
UID=$(dumpsys package "$PKG_NAME" 2>&1 | grep -m1 userId=)
UID=${UID#*=} UID=${UID%% *}
fi
if [ "$UID" ]; then
@@ -191,15 +184,14 @@ if [ "$KSU" ]; then
ui_print " $OP"
ui_print "* Because you are using a fork of KernelSU, "
ui_print " you need to go to your root manager app and"
ui_print " disable 'Unmount modules' option for $PKG_NAME"
ui_print " disable 'Unmount modules' for $PKG_NAME"
fi
else
ui_print "ERROR: UID could not be found for $PKG_NAME"
dumpsys package "$PKG_NAME" >&2
fi
fi
rm -rf "${MODPATH:?}/bin" "$MODPATH/$PKG_NAME.apk"
rm -rf "${MODPATH:?}/bin" "$MODPATH/stock/"
ui_print "* Done"
ui_print " by j-hc (github.com/j-hc)"