Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NoName-exe authored Feb 9, 2023
2 parents c2de26f + 891a6de commit 7a23f81
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
release_name: ${{ steps.get_output.outputs.RELEASE_NAME }}
tag: ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }}
file_glob: true
overwrite: false
overwrite: true

- name: Update changelog and Magisk update json
id: update_config
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mkdir -p "$BUILD_DIR" "$PREBUILTS_DIR"
# -- Main config --

if ((COMPRESSION_LEVEL > 9)) || ((COMPRESSION_LEVEL < 0)); then abort "compression-level must be from 0 to 9"; fi
if [ "${DRYRUN:-}" = true ]; then set_prebuilts; else get_prebuilts || set_prebuilts; fi
if [ "${NOSET:-}" = true ]; then set_prebuilts; else get_prebuilts || set_prebuilts; fi
if [ "$BUILD_MINDETACH_MODULE" = true ]; then : >$PKGS_LIST; fi
if [ "$LOGGING_F" = true ]; then mkdir -p logs; fi
jq --version >/dev/null || abort "\`jq\` is not installed. install it with 'apt install jq' or equivalent"
Expand Down
14 changes: 11 additions & 3 deletions scripts/customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ fi
BASEPATHLIB=${BASEPATH%base.apk}lib/${ARCH}
if [ -z "$(ls -A1 ${BASEPATHLIB})" ]; then
ui_print "- Extracting native libs"
if ! op=$(unzip -j $MODPATH/__PKGNAME.apk lib/${ARCH_LIB}/* -d ${BASEPATHLIB} 2>&1); then
mkdir -p $BASEPATHLIB
if ! op=$(unzip -j $MODPATH/__EXTRCT lib/${ARCH_LIB}/* -d ${BASEPATHLIB} 2>&1); then
ui_print "ERROR: extracting native libs failed"
abort "$op"
fi
Expand All @@ -65,12 +66,19 @@ RVPATH=$NVBASE/rvhc/__PKGNAME_rv.apk
mv -f $MODPATH/base.apk $RVPATH

if ! op=$(su -Mc mount -o bind $RVPATH $BASEPATH 2>&1); then
ui_print "ERROR: Mount failed!"
ui_print "$op"
abort "Flash the module in official Magisk Manager app"
ui_print "WARNING: Mount failed! Trying in non-global mountspace mode"
if ! op=$(mount -o bind $RVPATH $BASEPATH 2>&1); then
ui_print "ERROR: $op"
abort "Try flasing the module in official Magisk Manager app"
fi
fi
am force-stop __PKGNAME
ui_print "- Optimizing __PKGNAME"
cmd package compile --reset __PKGNAME &

ui_print "* Cleanup"
rm -rf $MODPATH/bin $MODPATH/__PKGNAME.apk $NVBASE/__PKGNAME_rv.apk
for s in "uninstall.sh" "service.sh"; do
sed -i "2 i\NVBASE=${NVBASE}" $MODPATH/$s
done
2 changes: 1 addition & 1 deletion scripts/service.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/system/bin/sh
# shellcheck disable=SC2086
MODDIR=${0%/*}
RVPATH=/data/adb/rvhc/__PKGNAME_rv.apk
RVPATH=${NVBASE}/rvhc/__PKGNAME_rv.apk
until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done
until [ "$(getprop init.svc.bootanim)" = stopped ]; do sleep 1; done
sleep 3
Expand Down
10 changes: 8 additions & 2 deletions scripts/uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/system/bin/sh
{
rm /data/adb/rvhc/__PKGNAME_rv.apk
rmdir /data/adb/rvhc
rm ${NVBASE}/rvhc/__PKGNAME_rv.apk
rmdir ${NVBASE}/rvhc
if __ISBNDL :; then
until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done
until [ "$(getprop init.svc.bootanim)" = stopped ]; do sleep 1; done
sleep 3
pm uninstall __PKGNAME
fi
} &
56 changes: 47 additions & 9 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ build_rv() {
fi
pr "Choosing version '${version}' (${app_name})"
local version_f=${version// /}
local stock_apk="${TEMP_DIR}/${pkg_name}-stock-${version_f}-${arch}.apk"
local stock_apk="${TEMP_DIR}/${pkg_name}-${version_f}-${arch}.apk"
if [ ! -f "$stock_apk" ]; then
if [ "$dl_from" = apkmirror ]; then
pr "Downloading '${app_name}' from APKMirror"
Expand Down Expand Up @@ -307,14 +307,34 @@ build_rv() {
if [ "$microg_patch" ]; then
p_patcher_args=("${p_patcher_args[@]//-[ei] ${microg_patch}/}")
fi

local stock_bundle="${TEMP_DIR}/${pkg_name}-${version_f}-${arch}-bundle.zip"
local stock_bundle_apk="${TEMP_DIR}/${pkg_name}-${version_f}-${arch}-bundle.apk"
local is_bundle=false
if [ "$mode_arg" = module ] || [ "$mode_arg" = both ]; then
if [ -f "$stock_bundle_apk" ]; then
is_bundle=true
elif [ "$dl_from" = apkmirror ]; then
pr "Downloading '${app_name}' bundle from APKMirror"
if dl_apkmirror "${args[apkmirror_dlurl]}" "$version" "BUNDLE</span>[^@]*@\([^#]*\)" "$stock_bundle"; then
pr "'${app_name}' bundle was downloaded successfully and will be used for the module"
is_bundle=true
unzip "$stock_bundle" "base.apk" -d $TEMP_DIR
mv ${TEMP_DIR}/base.apk "$stock_bundle_apk"
rm -f "$stock_bundle"
else
pr "'${app_name}' bundle was not found"
fi
fi
fi

if [ "$mode_arg" = module ]; then
build_mode_arr=(module)
elif [ "$mode_arg" = apk ]; then
build_mode_arr=(apk)
elif [ "$mode_arg" = both ]; then
build_mode_arr=(apk module)
fi

local patcher_args patched_apk build_mode
for build_mode in "${build_mode_arr[@]}"; do
patcher_args=("${p_patcher_args[@]}")
Expand All @@ -330,7 +350,11 @@ build_rv() {
patched_apk="${TEMP_DIR}/${app_name_l}-${RV_BRAND_F}-${version_f}-${arch}.apk"
fi
if [ "$build_mode" = module ]; then
patcher_args+=("--unsigned --rip-lib arm64-v8a --rip-lib armeabi-v7a")
if [ $is_bundle = false ]; then
patcher_args+=("--unsigned --rip-lib arm64-v8a --rip-lib armeabi-v7a")
else
patcher_args+=("--unsigned")
fi
fi
if [ ! -f "$patched_apk" ] || [ "$REBUILD" = true ]; then
if ! patch_apk "$stock_apk" "$patched_apk" "${patcher_args[*]}"; then
Expand All @@ -353,10 +377,20 @@ build_rv() {
else
upj="${app_name_l}-${arch}-update.json"
fi
local isbndl extrct stock_apk_module
if [ $is_bundle = true ]; then
isbndl=""
extrct="base.apk"
stock_apk_module=$stock_bundle_apk
else
isbndl="!"
extrct="${pkg_name}.apk"
stock_apk_module=$stock_apk
fi

uninstall_sh "$pkg_name" "$base_template"
uninstall_sh "$pkg_name" "$isbndl" "$base_template"
service_sh "$pkg_name" "$version" "$base_template"
customize_sh "$pkg_name" "$version" "$arch" "$base_template"
customize_sh "$pkg_name" "$version" "$arch" "$extrct" "$base_template"
module_prop \
"${args[module_prop_name]}" \
"${app_name} ${RV_BRAND}" \
Expand All @@ -367,7 +401,7 @@ build_rv() {

local module_output="${app_name_l}-${RV_BRAND_F}-magisk-v${version}-${arch}.zip"
if [ ! -f "$module_output" ] || [ "$REBUILD" = true ]; then
zip_module "$patched_apk" "$module_output" "$stock_apk" "$pkg_name" "$base_template"
zip_module "$patched_apk" "$module_output" "$stock_apk_module" "$pkg_name" "$base_template"
fi

pr "Built ${app_name} (${arch}) (root): '${BUILD_DIR}/${module_output}'"
Expand All @@ -378,16 +412,20 @@ join_args() {
echo "$1" | tr -d '\t\r' | tr ' ' '\n' | grep -v '^$' | sed "s/^/${2} /" | paste -sd " " - || :
}

uninstall_sh() { echo "${UNINSTALL_SH//__PKGNAME/$1}" >"${2}/uninstall.sh"; }
uninstall_sh() {
local s="${UNINSTALL_SH//__PKGNAME/$1}"
echo "${s//__ISBNDL/$2}" >"${3}/uninstall.sh"
}
customize_sh() {
local s="${CUSTOMIZE_SH//__PKGNAME/$1}"
# shellcheck disable=SC2016,SC2001
s="${s//__EXTRCT/$4}"
# shellcheck disable=SC2001
if [ "$3" = "arm64-v8a" ]; then
s=$(sed 's/#arm$/abort "ERROR: Wrong arch\nYour device: arm\nModule: arm64"/g' <<<"$s")
elif [ "$3" = "arm-v7a" ]; then
s=$(sed 's/#arm64$/abort "ERROR: Wrong arch\nYour device: arm64\nModule: arm"/g' <<<"$s")
fi
echo "${s//__PKGVER/$2}" >"${4}/customize.sh"
echo "${s//__PKGVER/$2}" >"${5}/customize.sh"
}
service_sh() {
local s="${SERVICE_SH//__PKGNAME/$1}"
Expand Down

0 comments on commit 7a23f81

Please sign in to comment.