module config file

This commit is contained in:
j-hc 2024-03-31 02:07:23 +03:00
parent a1332c1937
commit d5de11f48f
No known key found for this signature in database
GPG Key ID: CDF97F1DBFE904CD
3 changed files with 55 additions and 57 deletions

View File

@ -1,13 +1,17 @@
# shellcheck disable=SC2148,SC2086 # shellcheck disable=SC2148,SC2086,SC1091
. $MODPATH/config
ui_print "" ui_print ""
${MODPATH:?} if [ -n "$MODULE_ARCH" ] && [ $MODULE_ARCH != $ARCH ]; then
abort "ERROR: Wrong arch
Your device: $ARCH
Module: $MODULE_ARCH"
fi
if [ $ARCH = "arm" ]; then if [ $ARCH = "arm" ]; then
#arm
ARCH_LIB=armeabi-v7a ARCH_LIB=armeabi-v7a
alias cmpr='$MODPATH/bin/arm/cmpr' alias cmpr='$MODPATH/bin/arm/cmpr'
elif [ $ARCH = "arm64" ]; then elif [ $ARCH = "arm64" ]; then
#arm64
ARCH_LIB=arm64-v8a ARCH_LIB=arm64-v8a
alias cmpr='$MODPATH/bin/arm64/cmpr' alias cmpr='$MODPATH/bin/arm64/cmpr'
elif [ $ARCH = "x86" ]; then elif [ $ARCH = "x86" ]; then
@ -27,75 +31,75 @@ else
alias mm='nsenter -t1 -m' alias mm='nsenter -t1 -m'
fi fi
mm grep __PKGNAME /proc/mounts | while read -r line; do mm grep $PKG_NAME /proc/mounts | while read -r line; do
ui_print "* Un-mount" ui_print "* Un-mount"
mp=${line#* } mp=${line#* }
mp=${mp%% *} mp=${mp%% *}
mm umount -l ${mp%%\\*} mm umount -l ${mp%%\\*}
done done
am force-stop __PKGNAME am force-stop $PKG_NAME
INS=true INS=true
if BASEPATH=$(pm path __PKGNAME); then if BASEPATH=$(pm path $PKG_NAME); then
BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH##*:}
BASEPATH=${BASEPATH%/*} BASEPATH=${BASEPATH%/*}
if [ ${BASEPATH:1:6} = system ]; then if [ ${BASEPATH:1:6} = system ]; then
ui_print "* __PKGNAME is a system app" ui_print "* $PKG_NAME is a system app"
elif [ ! -d ${BASEPATH}/lib ]; then elif [ ! -d ${BASEPATH}/lib ]; then
ui_print "* Invalid installation found. Uninstalling..." ui_print "* Invalid installation found. Uninstalling..."
pm uninstall -k --user 0 __PKGNAME pm uninstall -k --user 0 $PKG_NAME
elif [ ! -f $MODPATH/__PKGNAME.apk ]; then elif [ ! -f $MODPATH/$PKG_NAME.apk ]; then
ui_print "* Stock __PKGNAME APK was not found" ui_print "* Stock $PKG_NAME APK was not found"
VERSION=$(dumpsys package __PKGNAME | grep -m1 versionName) VERSION=$(dumpsys package $PKG_NAME | grep -m1 versionName)
VERSION="${VERSION#*=}" VERSION="${VERSION#*=}"
if [ "$VERSION" = __PKGVER ] || [ -z "$VERSION" ]; then if [ "$VERSION" = $PKG_VER ] || [ -z "$VERSION" ]; then
ui_print "* Skipping stock installation" ui_print "* Skipping stock installation"
INS=false INS=false
else else
abort "ERROR: Version mismatch abort "ERROR: Version mismatch
installed: $VERSION installed: $VERSION
module: __PKGVER module: $PKG_VER
" "
fi fi
elif cmpr $BASEPATH/base.apk $MODPATH/__PKGNAME.apk; then elif cmpr $BASEPATH/base.apk $MODPATH/$PKG_NAME.apk; then
ui_print "* __PKGNAME is up-to-date" ui_print "* $PKG_NAME is up-to-date"
INS=false INS=false
fi fi
fi fi
install() { install() {
if [ ! -f $MODPATH/__PKGNAME.apk ]; then if [ ! -f $MODPATH/$PKG_NAME.apk ]; then
abort "ERROR: Stock __PKGNAME apk was not found" abort "ERROR: Stock $PKG_NAME apk was not found"
fi fi
ui_print "* Updating __PKGNAME to __PKGVER" ui_print "* Updating $PKG_NAME to $PKG_VER"
settings put global verifier_verify_adb_installs 0 settings put global verifier_verify_adb_installs 0
SZ=$(stat -c "%s" $MODPATH/__PKGNAME.apk) SZ=$(stat -c "%s" $MODPATH/$PKG_NAME.apk)
if ! SES=$(pm install-create --user 0 -i com.android.vending -r -d -S "$SZ" 2>&1); then if ! SES=$(pm install-create --user 0 -i com.android.vending -r -d -S "$SZ" 2>&1); then
ui_print "ERROR: install-create failed" ui_print "ERROR: install-create failed"
abort "$SES" abort "$SES"
fi fi
SES=${SES#*[} SES=${SES#*[}
SES=${SES%]*} SES=${SES%]*}
set_perm "$MODPATH/__PKGNAME.apk" 1000 1000 644 u:object_r:apk_data_file:s0 set_perm "$MODPATH/$PKG_NAME.apk" 1000 1000 644 u:object_r:apk_data_file:s0
if ! op=$(pm install-write -S "$SZ" "$SES" "__PKGNAME.apk" "$MODPATH/__PKGNAME.apk" 2>&1); then if ! op=$(pm install-write -S "$SZ" "$SES" "$PKG_NAME.apk" "$MODPATH/$PKG_NAME.apk" 2>&1); then
ui_print "ERROR: install-write failed" ui_print "ERROR: install-write failed"
abort "$op" abort "$op"
fi fi
if ! op=$(pm install-commit "$SES" 2>&1); then if ! op=$(pm install-commit "$SES" 2>&1); then
if echo "$op" | grep INSTALL_FAILED_VERSION_DOWNGRADE; then if echo "$op" | grep -q INSTALL_FAILED_VERSION_DOWNGRADE; then
ui_print "* INSTALL_FAILED_VERSION_DOWNGRADE. Uninstalling..." ui_print "* INSTALL_FAILED_VERSION_DOWNGRADE. Uninstalling..."
pm uninstall -k --user 0 __PKGNAME pm uninstall -k --user 0 $PKG_NAME
return 1 return 1
fi fi
ui_print "ERROR: install-commit failed" ui_print "ERROR: install-commit failed"
abort "$op" abort "$op"
fi fi
settings put global verifier_verify_adb_installs 1 settings put global verifier_verify_adb_installs 1
if BASEPATH=$(pm path __PKGNAME); then if BASEPATH=$(pm path $PKG_NAME); then
BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH##*:}
BASEPATH=${BASEPATH%/*} BASEPATH=${BASEPATH%/*}
else else
abort "ERROR: install __PKGNAME manually and reflash the module" abort "ERROR: install $PKG_NAME manually and reflash the module"
fi fi
} }
if [ $INS = true ]; then if [ $INS = true ]; then
@ -110,7 +114,7 @@ BASEPATHLIB=${BASEPATH}/lib/${ARCH}
if [ -z "$(ls -A1 ${BASEPATHLIB})" ]; then if [ -z "$(ls -A1 ${BASEPATHLIB})" ]; then
ui_print "* Extracting native libs" ui_print "* Extracting native libs"
mkdir -p $BASEPATHLIB mkdir -p $BASEPATHLIB
if ! op=$(unzip -j $MODPATH/__PKGNAME.apk lib/${ARCH_LIB}/* -d ${BASEPATHLIB} 2>&1); then if ! op=$(unzip -j $MODPATH/$PKG_NAME.apk lib/${ARCH_LIB}/* -d ${BASEPATHLIB} 2>&1); then
ui_print "ERROR: extracting native libs failed" ui_print "ERROR: extracting native libs failed"
abort "$op" abort "$op"
fi fi
@ -119,7 +123,7 @@ fi
ui_print "* Setting Permissions" ui_print "* Setting Permissions"
set_perm $MODPATH/base.apk 1000 1000 644 u:object_r:apk_data_file:s0 set_perm $MODPATH/base.apk 1000 1000 644 u:object_r:apk_data_file:s0
ui_print "* Mounting __PKGNAME" ui_print "* Mounting $PKG_NAME"
mkdir -p $NVBASE/rvhc mkdir -p $NVBASE/rvhc
RVPATH=$NVBASE/rvhc/${MODPATH##*/}.apk RVPATH=$NVBASE/rvhc/${MODPATH##*/}.apk
mv -f $MODPATH/base.apk $RVPATH mv -f $MODPATH/base.apk $RVPATH
@ -128,12 +132,12 @@ if ! op=$(mm mount -o bind $RVPATH $BASEPATH/base.apk 2>&1); then
ui_print "ERROR: Mount failed!" ui_print "ERROR: Mount failed!"
ui_print "$op" ui_print "$op"
fi fi
am force-stop __PKGNAME am force-stop $PKG_NAME
ui_print "* Optimizing __PKGNAME" ui_print "* Optimizing $PKG_NAME"
nohup cmd package compile --reset __PKGNAME >/dev/null 2>&1 & nohup cmd package compile --reset $PKG_NAME >/dev/null 2>&1 &
ui_print "* Cleanup" ui_print "* Cleanup"
rm -rf $MODPATH/bin $MODPATH/__PKGNAME.apk rm -rf ${MODPATH:?}/bin $MODPATH/$PKG_NAME.apk
for s in "uninstall.sh" "service.sh"; do for s in "uninstall.sh" "service.sh"; do
sed -i "2 i\NVBASE=${NVBASE}" $MODPATH/$s sed -i "2 i\NVBASE=${NVBASE}" $MODPATH/$s

View File

@ -1,12 +1,14 @@
#!/system/bin/sh #!/system/bin/sh
# shellcheck disable=SC2086 # shellcheck disable=SC2086,SC1091
. $MODPATH/config
MODDIR=${0%/*} MODDIR=${0%/*}
RVPATH=$NVBASE/rvhc/${MODDIR##*/}.apk RVPATH=$NVBASE/rvhc/${MODDIR##*/}.apk
until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done
until [ -d "/sdcard/Android" ]; do sleep 1; done until [ -d "/sdcard/Android" ]; do sleep 1; done
while while
BASEPATH=$(pm path __PKGNAME) BASEPATH=$(pm path $PKG_NAME)
svcl=$? svcl=$?
[ $svcl = 20 ] [ $svcl = 20 ]
do sleep 2; done do sleep 2; done
@ -21,23 +23,23 @@ if [ $svcl = 0 ]; then
BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH##*:}
BASEPATH=${BASEPATH%/*} BASEPATH=${BASEPATH%/*}
if [ -d $BASEPATH/lib ]; then if [ -d $BASEPATH/lib ]; then
VERSION=$(dumpsys package __PKGNAME | grep -m1 versionName) VERSION=$(dumpsys package $PKG_NAME | grep -m1 versionName)
VERSION="${VERSION#*=}" VERSION="${VERSION#*=}"
if [ "$VERSION" = __PKGVER ] || [ -z "$VERSION" ]; then if [ "$VERSION" = $PKG_VER ] || [ -z "$VERSION" ]; then
grep __PKGNAME /proc/mounts | while read -r line; do grep $PKG_NAME /proc/mounts | while read -r line; do
mp=${line#* } mp=${line#* }
mp=${mp%% *} mp=${mp%% *}
umount -l ${mp%%\\*} umount -l ${mp%%\\*}
done done
if chcon u:object_r:apk_data_file:s0 $RVPATH; then if chcon u:object_r:apk_data_file:s0 $RVPATH; then
mount -o bind $RVPATH $BASEPATH/base.apk mount -o bind $RVPATH $BASEPATH/base.apk
am force-stop __PKGNAME am force-stop $PKG_NAME
[ -f $MODDIR/err ] && mv -f $MODDIR/err $MODDIR/module.prop [ -f $MODDIR/err ] && mv -f $MODDIR/err $MODDIR/module.prop
else else
err "mount failed" err "mount failed"
fi fi
else else
err "version mismatch (installed:${VERSION}, module:__PKGVER)" err "version mismatch (installed:${VERSION}, module:$PKG_VER)"
fi fi
else else
err "zygote crashed" err "zygote crashed"

View File

@ -10,9 +10,6 @@ NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')}
REBUILD=${REBUILD:-false} REBUILD=${REBUILD:-false}
OS=$(uname -o) OS=$(uname -o)
SERVICE_SH=$(cat scripts/service.sh)
CUSTOMIZE_SH=$(cat scripts/customize.sh)
# -------------------- json/toml -------------------- # -------------------- json/toml --------------------
json_get() { grep -o "\"${1}\":[^\"]*\"[^\"]*\"" | sed -E 's/".*".*"(.*)"/\1/'; } json_get() { grep -o "\"${1}\":[^\"]*\"[^\"]*\"" | sed -E 's/".*".*"(.*)"/\1/'; }
toml_prep() { __TOML__=$(tr -d '\t\r' <<<"$1" | tr "'" '"' | grep -o '^[^#]*' | grep -v '^$' | sed -r 's/(\".*\")|\s*/\1/g; 1i []'); } toml_prep() { __TOML__=$(tr -d '\t\r' <<<"$1" | tr "'" '"' | grep -o '^[^#]*' | grep -v '^$' | sed -r 's/(\".*\")|\s*/\1/g; 1i []'); }
@ -468,8 +465,7 @@ build_rv() {
cp -a $MODULE_TEMPLATE_DIR/. "$base_template" cp -a $MODULE_TEMPLATE_DIR/. "$base_template"
local upj="${table,,}-update.json" local upj="${table,,}-update.json"
service_sh "$pkg_name" "$version" "$base_template" module_config "$base_template" "$pkg_name" "$version" "$arch"
customize_sh "$pkg_name" "$version" "$arch" "$base_template"
module_prop \ module_prop \
"${args[module_prop_name]}" \ "${args[module_prop_name]}" \
"${app_name} ${args[rv_brand]}" \ "${app_name} ${args[rv_brand]}" \
@ -494,20 +490,16 @@ build_rv() {
list_args() { tr -d '\t\r' <<<"$1" | tr -s ' ' | sed 's/" "/"\n"/g' | sed 's/\([^"]\)"\([^"]\)/\1'\''\2/g' | grep -v '^$' || :; } list_args() { tr -d '\t\r' <<<"$1" | tr -s ' ' | sed 's/" "/"\n"/g' | sed 's/\([^"]\)"\([^"]\)/\1'\''\2/g' | grep -v '^$' || :; }
join_args() { list_args "$1" | sed "s/^/${2} /" | paste -sd " " - || :; } join_args() { list_args "$1" | sed "s/^/${2} /" | paste -sd " " - || :; }
customize_sh() { module_config() {
local s="${CUSTOMIZE_SH//__PKGNAME/$1}" local ma=""
s="${s//__EXTRCT/$4}" if [ "$4" = "arm64-v8a" ]; then
# shellcheck disable=SC2001 ma="arm64"
if [ "$3" = "arm64-v8a" ]; then elif [ "$4" = "arm-v7a" ]; then
s=$(sed 's/#arm$/abort "ERROR: Wrong arch\nYour device: arm\nModule: arm64"/g' <<<"$s") ma="arm"
elif [ "$3" = "arm-v7a" ]; then
s=$(sed 's/#arm64$/abort "ERROR: Wrong arch\nYour device: arm64\nModule: arm"/g' <<<"$s")
fi fi
echo "${s//__PKGVER/$2}" >"${5}/customize.sh" echo "PKG_NAME=$2
} PKG_VER=$3
service_sh() { MODULE_ARCH=$ma" >"$1/config"
local s="${SERVICE_SH//__PKGNAME/$1}"
echo "${s//__PKGVER/$2}" >"${3}/service.sh"
} }
module_prop() { module_prop() {
echo "id=${1} echo "id=${1}