diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 070f021..74ff10b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,5 +7,6 @@ assignees: '' --- -**DO NOT REPORT REVANCED BUGS IN THIS REPO** +**DO NOT REPORT REVANCED STUFF IN THIS REPO** + **Describe the bug of the rvmm builder or the modules** diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..3ba13e0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false diff --git a/.gitignore b/.gitignore index 82e39cb..7cb0124 100755 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ -*.jar *.apk *.zip -/revanced-cache /temp /build test* diff --git a/README.md b/README.md index ea649db..e13afcc 100755 --- a/README.md +++ b/README.md @@ -17,12 +17,14 @@ Get the [latest CI release](https://github.com/NoName-exe/revanced-extended/rele * Support Magisk and KernelSU. ## Notes -* Use [mindetach](https://github.com/j-hc/mindetach-magisk) or [zygisk-detach](https://github.com/j-hc/zygisk-detach) to block Play Store from updating YouTube and YouTube-Music. -* Non-root versions of YouTube and YouTube-Music require [Vanced MicroG](https://github.com/inotia00/VancedMicroG/releases/latest) or [mMicroG](https://github.com/inotia00/mMicroG/releases/latest) to work. +* Use [zygisk-detach](https://github.com/j-hc/zygisk-detach) to block Play Store from updating YouTube and YouTube-Music. +* Non-root versions of YouTube and YouTube-Music require [MicroG](https://github.com/ReVanced/GmsCore/releases) to work. ## Credits [j-hc](https://github.com/j-hc) for [mindetach](https://github.com/j-hc/mindetach-magisk), [zygisk-detach](https://github.com/j-hc/zygisk-detach) and the [script on which this is based on](https://github.com/j-hc/revanced-magisk-module). -[inotia00](https://github.com/inotia00) for [revanced-extended patches](https://github.com/inotia00/revanced-patches),[Vanced MicroG](https://github.com/inotia00/VancedMicroG) and [mMicroG](https://github.com/inotia00/mMicroG). +[ReVanced Team](https://github.com/revanced) for [MicroG](https://github.com/ReVanced/GmsCore/releases). + +[inotia00](https://github.com/inotia00) for [revanced-extended patches](https://github.com/inotia00/revanced-patches). [Gnad Gnaoh](https://github.com/gnadgnaoh) for helping me figure some stuff out. diff --git a/bin/aapt2/aapt2-arm b/bin/aapt2/aapt2-arm new file mode 100755 index 0000000..f383b2e Binary files /dev/null and b/bin/aapt2/aapt2-arm differ diff --git a/bin/aapt2/aapt2-arm64 b/bin/aapt2/aapt2-arm64 new file mode 100755 index 0000000..7bd9eb2 Binary files /dev/null and b/bin/aapt2/aapt2-arm64 differ diff --git a/bin/apksigner.jar b/bin/apksigner.jar new file mode 100644 index 0000000..f4adcff Binary files /dev/null and b/bin/apksigner.jar differ diff --git a/bin/htmlq/htmlq-arm b/bin/htmlq/htmlq-arm new file mode 100755 index 0000000..fb3d179 Binary files /dev/null and b/bin/htmlq/htmlq-arm differ diff --git a/bin/htmlq/htmlq-arm64 b/bin/htmlq/htmlq-arm64 new file mode 100755 index 0000000..caab99a Binary files /dev/null and b/bin/htmlq/htmlq-arm64 differ diff --git a/bin/htmlq/htmlq-x86_64 b/bin/htmlq/htmlq-x86_64 new file mode 100755 index 0000000..d8c865d Binary files /dev/null and b/bin/htmlq/htmlq-x86_64 differ diff --git a/build.sh b/build.sh index 2d64ee2..f3ff023 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash set -euo pipefail +shopt -s nullglob trap "rm -rf temp/*tmp.* temp/*/*tmp.*; exit 130" INT -if [ "${1:-}" = "clean" ]; then +if [ "${1-}" = "clean" ]; then rm -rf temp build logs build.md exit 0 fi @@ -28,14 +29,14 @@ DEF_CLI_SRC=$(toml_get "$main_config_t" cli-source) || DEF_CLI_SRC="inotia00/rev DEF_RV_BRAND=$(toml_get "$main_config_t" rv-brand) || DEF_RV_BRAND="ReVanced eXtended" mkdir -p $TEMP_DIR $BUILD_DIR -if [ "${2:-}" = "--config-update" ]; then +if [ "${2-}" = "--config-update" ]; then config_update exit 0 fi : >build.md ENABLE_MAGISK_UPDATE=$(toml_get "$main_config_t" enable-magisk-update) || ENABLE_MAGISK_UPDATE=true -if [ "$ENABLE_MAGISK_UPDATE" = true ] && [ -z "${GITHUB_REPOSITORY:-}" ]; then +if [ "$ENABLE_MAGISK_UPDATE" = true ] && [ -z "${GITHUB_REPOSITORY-}" ]; then pr "You are building locally. Magisk updates will not be enabled." ENABLE_MAGISK_UPDATE=false fi @@ -82,7 +83,7 @@ for table_name in $(toml_get_table_names); do cli_ver=$(toml_get "$t" cli-version) || cli_ver=$DEF_CLI_VER if ! set_prebuilts "$integrations_src" "$patches_src" "$cli_src" "$integrations_ver" "$patches_ver" "$cli_ver"; then - if ! RVP="$(get_rv_prebuilts "$integrations_src" "$patches_src" "$integrations_ver" "$patches_ver" "$cli_src" "$cli_ver")"; then + if ! RVP="$(get_rv_prebuilts "$cli_src" "$cli_ver" "$integrations_src" "$integrations_ver" "$patches_src" "$patches_ver")"; then abort "could not download rv prebuilts" fi read -r rv_cli_jar rv_integrations_apk rv_patches_jar rv_patches_json <<<"$RVP" @@ -104,9 +105,9 @@ for table_name in $(toml_get_table_names); do app_args[rv_brand]=$(toml_get "$t" rv-brand) || app_args[rv_brand]="$DEF_RV_BRAND" app_args[excluded_patches]=$(toml_get "$t" excluded-patches) || app_args[excluded_patches]="" - if [ -n "${app_args[excluded_patches]}" ] && [[ "${app_args[excluded_patches]}" != *'"'* ]]; then abort "patch names inside excluded-patches must be quoted"; fi + if [ -n "${app_args[excluded_patches]}" ] && [[ ${app_args[excluded_patches]} != *'"'* ]]; then abort "patch names inside excluded-patches must be quoted"; fi app_args[included_patches]=$(toml_get "$t" included-patches) || app_args[included_patches]="" - if [ -n "${app_args[included_patches]}" ] && [[ "${app_args[included_patches]}" != *'"'* ]]; then abort "patch names inside included-patches must be quoted"; fi + if [ -n "${app_args[included_patches]}" ] && [[ ${app_args[included_patches]} != *'"'* ]]; then abort "patch names inside included-patches must be quoted"; fi app_args[exclusive_patches]=$(toml_get "$t" exclusive-patches) && vtf "${app_args[exclusive_patches]}" "exclusive-patches" || app_args[exclusive_patches]=false app_args[version]=$(toml_get "$t" version) || app_args[version]="auto" app_args[app_name]=$(toml_get "$t" app-name) || app_args[app_name]=$table_name @@ -134,9 +135,9 @@ for table_name in $(toml_get_table_names); do app_args[archive_dlurl]=${app_args[archive_dlurl]%/} app_args[dl_from]=archive } || app_args[archive_dlurl]="" - if [ -z "${app_args[dl_from]:-}" ]; then abort "ERROR: no 'apkmirror_dlurl', 'uptodown_dlurl' or 'apkmonk_dlurl' option was set for '$table_name'."; fi + if [ -z "${app_args[dl_from]-}" ]; then abort "ERROR: no 'apkmirror_dlurl', 'uptodown_dlurl' or 'apkmonk_dlurl' option was set for '$table_name'."; fi app_args[arch]=$(toml_get "$t" arch) || app_args[arch]="all" - if [ "${app_args[arch]}" != "both" ] && [ "${app_args[arch]}" != "all" ] && [[ "${app_args[arch]}" != "arm64-v8a"* ]] && [[ "${app_args[arch]}" != "arm-v7a"* ]]; then + if [ "${app_args[arch]}" != "both" ] && [ "${app_args[arch]}" != "all" ] && [[ ${app_args[arch]} != "arm64-v8a"* ]] && [[ ${app_args[arch]} != "arm-v7a"* ]]; then abort "wrong arch '${app_args[arch]}' for '$table_name'" fi @@ -167,10 +168,9 @@ wait rm -rf temp/tmp.* if [ -z "$(ls -A1 ${BUILD_DIR})" ]; then abort "All builds failed."; fi -log "\nInstall [Vanced Microg](https://github.com/inotia00/VancedMicroG/releases) or [mMicroG](https://github.com/inotia00/mMicroG/releases) to be able to use non-root YouTube or YouTube-Music." -log "Use [mindetach](https://github.com/j-hc/mindetach-magisk) or [zygisk-detach](https://github.com/j-hc/zygisk-detach) to block Play Store from updating YouTube and YouTube-Music." +log "\nInstall [MicroG](https://github.com/ReVanced/GmsCore/releases) to be able to use non-root YouTube or YouTube-Music." +log "Use [zygisk-detach](https://github.com/j-hc/zygisk-detach) to block Play Store from updating YouTube and YouTube-Music." log "\n[Main Repo](https://github.com/NoName-exe/revanced-extended)" -log "\nChangelog:" log "$(cat $TEMP_DIR/*-rv/changelog.md)" SKIPPED=$(cat $TEMP_DIR/skipped 2>/dev/null || :) diff --git a/scripts/customize.sh b/revanced-magisk/customize.sh similarity index 52% rename from scripts/customize.sh rename to revanced-magisk/customize.sh index 500352b..90114db 100755 --- a/scripts/customize.sh +++ b/revanced-magisk/customize.sh @@ -1,12 +1,17 @@ -# shellcheck disable=SC2148,SC2086 +# shellcheck disable=SC2148,SC2086,SC1091 +. $MODPATH/config + ui_print "" +if [ -n "$MODULE_ARCH" ] && [ $MODULE_ARCH != $ARCH ]; then + abort "ERROR: Wrong arch +Your device: $ARCH +Module: $MODULE_ARCH" +fi if [ $ARCH = "arm" ]; then - #arm ARCH_LIB=armeabi-v7a alias cmpr='$MODPATH/bin/arm/cmpr' elif [ $ARCH = "arm64" ]; then - #arm64 ARCH_LIB=arm64-v8a alias cmpr='$MODPATH/bin/arm64/cmpr' elif [ $ARCH = "x86" ]; then @@ -20,76 +25,96 @@ else fi set_perm_recursive $MODPATH/bin 0 0 0755 0777 -su -M -c "grep __PKGNAME /proc/mounts" | while read -r line; do +if su -M -c true >/dev/null 2>/dev/null; then + alias mm='su -M -c' +else + alias mm='nsenter -t1 -m' +fi + +mm grep $PKG_NAME /proc/mounts | while read -r line; do ui_print "- Un-mount" mp=${line#* } mp=${mp%% *} - su -M -c "umount -l ${mp%%\\*}" + mm umount -l ${mp%%\\*} done -am force-stop __PKGNAME +am force-stop $PKG_NAME INS=true -if BASEPATH=$(pm path __PKGNAME); then +if BASEPATH=$(pm path $PKG_NAME); then BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH%/*} 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 ui_print "- Invalid installation found. Uninstalling..." - pm uninstall -k --user 0 __PKGNAME - elif [ ! -f $MODPATH/__PKGNAME.apk ]; then - ui_print "- Stock __PKGNAME APK was not found" - VERSION=$(dumpsys package __PKGNAME | grep -m1 versionName) + pm uninstall -k --user 0 $PKG_NAME + elif [ ! -f $MODPATH/$PKG_NAME.apk ]; then + ui_print "- Stock $PKG_NAME APK was not found" + VERSION=$(dumpsys package $PKG_NAME | grep -m1 versionName) VERSION="${VERSION#*=}" - if [ "$VERSION" = __PKGVER ] || [ -z "$VERSION" ]; then + if [ "$VERSION" = $PKG_VER ] || [ -z "$VERSION" ]; then ui_print "- Skipping stock installation" INS=false else abort "ERROR: Version mismatch installed: $VERSION - module: __PKGVER + module: $PKG_VER " fi - elif cmpr $BASEPATH/base.apk $MODPATH/__PKGNAME.apk; then - ui_print "- __PKGNAME is up-to-date" + elif cmpr $BASEPATH/base.apk $MODPATH/$PKG_NAME.apk; then + ui_print "- $PKG_NAME is up-to-date" INS=false fi fi -if [ $INS = true ]; then - if [ ! -f $MODPATH/__PKGNAME.apk ]; then - abort "ERROR: Stock __PKGNAME apk was not found" + +install() { + if [ ! -f $MODPATH/$PKG_NAME.apk ]; then + abort "ERROR: Stock $PKG_NAME apk was not found" fi - ui_print "- Updating __PKGNAME to __PKGVER" + ui_print "- Updating $PKG_NAME to $PKG_VER" 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 ui_print "ERROR: install-create failed" abort "$SES" fi SES=${SES#*[} SES=${SES%]*} - set_perm "$MODPATH/__PKGNAME.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 + set_perm "$MODPATH/$PKG_NAME.apk" 1000 1000 644 u:object_r:apk_data_file:s0 + if ! op=$(pm install-write -S "$SZ" "$SES" "$PKG_NAME.apk" "$MODPATH/$PKG_NAME.apk" 2>&1); then ui_print "ERROR: install-write failed" abort "$op" fi if ! op=$(pm install-commit "$SES" 2>&1); then + if echo "$op" | grep -q INSTALL_FAILED_VERSION_DOWNGRADE; then + ui_print "- INSTALL_FAILED_VERSION_DOWNGRADE. Uninstalling..." + pm uninstall -k --user 0 $PKG_NAME + return 1 + fi ui_print "ERROR: install-commit failed" abort "$op" fi 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%/*} else - abort "ERROR: install __PKGNAME manually and reflash the module" + abort "ERROR: install $PKG_NAME manually and reflash the module" + fi +} +if [ $INS = true ]; then + if ! install; then + if ! install; then + abort + fi fi fi + BASEPATHLIB=${BASEPATH}/lib/${ARCH} if [ -z "$(ls -A1 ${BASEPATHLIB})" ]; then ui_print "- Extracting native libs" mkdir -p $BASEPATHLIB - if ! op=$(unzip -j $MODPATH/__EXTRCT 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" abort "$op" fi @@ -98,21 +123,21 @@ fi ui_print "- Setting Permissions" 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 RVPATH=$NVBASE/rvhc/${MODPATH##*/}.apk mv -f $MODPATH/base.apk $RVPATH -if ! op=$(su -M -c "mount -o bind $RVPATH $BASEPATH/base.apk" 2>&1); then +if ! op=$(mm mount -o bind $RVPATH $BASEPATH/base.apk 2>&1); then ui_print "ERROR: Mount failed!" ui_print "$op" fi -am force-stop __PKGNAME -ui_print "- Optimizing __PKGNAME" -nohup cmd package compile --reset __PKGNAME >/dev/null 2>&1 & +am force-stop $PKG_NAME +ui_print "- Optimizing $PKG_NAME" +nohup cmd package compile --reset $PKG_NAME >/dev/null 2>&1 & 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 sed -i "2 i\NVBASE=${NVBASE}" $MODPATH/$s diff --git a/scripts/service.sh b/revanced-magisk/service.sh similarity index 62% rename from scripts/service.sh rename to revanced-magisk/service.sh index 01d0cc3..a241f3b 100755 --- a/scripts/service.sh +++ b/revanced-magisk/service.sh @@ -1,12 +1,13 @@ #!/system/bin/sh -# shellcheck disable=SC2086 +# shellcheck disable=SC2086,SC1091 MODDIR=${0%/*} RVPATH=$NVBASE/rvhc/${MODDIR##*/}.apk +. $MODDIR/config until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done until [ -d "/sdcard/Android" ]; do sleep 1; done while - BASEPATH=$(pm path __PKGNAME) + BASEPATH=$(pm path $PKG_NAME) svcl=$? [ $svcl = 20 ] do sleep 2; done @@ -14,33 +15,33 @@ sleep 5 err() { [ ! -f $MODDIR/err ] && cp $MODDIR/module.prop $MODDIR/err - sed -i "s/^des.*/description=⚠️ Module is inactive: '${1}'/g" $MODDIR/module.prop + sed -i "s/^des.*/description=⚠️ Needs reflash: '${1}'/g" $MODDIR/module.prop } if [ $svcl = 0 ]; then BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH%/*} if [ -d $BASEPATH/lib ]; then - VERSION=$(dumpsys package __PKGNAME | grep -m1 versionName) + VERSION=$(dumpsys package $PKG_NAME | grep -m1 versionName) VERSION="${VERSION#*=}" - if [ "$VERSION" = __PKGVER ] || [ -z "$VERSION" ]; then - grep __PKGNAME /proc/mounts | while read -r line; do + if [ "$VERSION" = $PKG_VER ] || [ -z "$VERSION" ]; then + grep $PKG_NAME /proc/mounts | while read -r line; do mp=${line#* } mp=${mp%% *} umount -l ${mp%%\\*} done if chcon u:object_r:apk_data_file:s0 $RVPATH; then 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 else err "mount failed" fi else - err "version mismatch (installed:${VERSION}, module:__PKGVER)" + err "version mismatch (installed:${VERSION}, module:$PKG_VER)" fi else - err "invalid installation" + err "zygote crashed" fi else err "app not installed" diff --git a/revanced-magisk/uninstall.sh b/revanced-magisk/uninstall.sh new file mode 100755 index 0000000..1bf629d --- /dev/null +++ b/revanced-magisk/uninstall.sh @@ -0,0 +1,6 @@ +#!/system/bin/sh +{ + MODDIR=${0%/*} + rm "$NVBASE/rvhc/${MODDIR##*/}".apk + rmdir "$NVBASE/rvhc" +} & diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh deleted file mode 100755 index ab2372e..0000000 --- a/scripts/uninstall.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/system/bin/sh -{ - MODDIR=${0%/*} - rm "$NVBASE/rvhc/${MODDIR##*/}".apk - rmdir "$NVBASE/rvhc" - # if __ISBNDL; then - # until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done - # sleep 15 - # pm uninstall __PKGNAME - # fi -} & diff --git a/sig.txt b/sig.txt new file mode 100644 index 0000000..cfa0675 --- /dev/null +++ b/sig.txt @@ -0,0 +1,6 @@ +a2a1ad7ba7f41dfca4514e2afeb90691719af6d0fdbed4b09bbf0ed897701ceb com.google.android.apps.youtube.music +3d7a1223019aa39d9ea0e3436ab7c0896bfb4fb679f4de5fe7c23f326c8f994a com.google.android.youtube +970b91143813b4c9d5f3634f672c9fcaa5621b4efaaedafd6c235cbbb869736f com.reddit.frontpage +0fd9a0cfb07b65950997b4eaebdc53931392391aa406538a3b04073bc2ce2fe9 com.twitter.android +9041803e91bcb814b4b4399fb5c85a91640b755e5e8ba76813814bf4cf2ab5ba com.zhiliaoapp.musically +1338f9b049893cc70b78432a177582f90bd4bc6296ea4ed35bcc7df59687ac53 tv.twitch.android.app \ No newline at end of file diff --git a/utils.sh b/utils.sh index 646e9b8..51657bf 100755 --- a/utils.sh +++ b/utils.sh @@ -2,19 +2,15 @@ MODULE_TEMPLATE_DIR="revanced-magisk" TEMP_DIR="temp" +BIN_DIR="bin" BUILD_DIR="build" -if [ "${GITHUB_TOKEN:-}" ]; then GH_HEADER="Authorization: token ${GITHUB_TOKEN}"; else GH_HEADER=; fi +if [ "${GITHUB_TOKEN-}" ]; then GH_HEADER="Authorization: token ${GITHUB_TOKEN}"; else GH_HEADER=; fi NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')} REBUILD=${REBUILD:-false} OS=$(uname -o) -SERVICE_SH=$(cat scripts/service.sh) -CUSTOMIZE_SH=$(cat scripts/customize.sh) -UNINSTALL_SH=$(cat scripts/uninstall.sh) - # -------------------- json/toml -------------------- -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_get_table_names() { local tn @@ -34,92 +30,72 @@ toml_get() { pr() { echo -e "\033[0;32m[+] ${1}\033[0m"; } epr() { echo >&2 -e "\033[0;31m[-] ${1}\033[0m" - if [ "${GITHUB_REPOSITORY:-}" ]; then echo -e "::error::utils.sh [-] ${1}\n"; fi + if [ "${GITHUB_REPOSITORY-}" ]; then echo -e "::error::utils.sh [-] ${1}\n"; fi } abort() { - epr "ABORT: ${1:-}" + epr "ABORT: ${1-}" exit 1 } get_rv_prebuilts() { - local integrations_src=$1 patches_src=$2 integrations_ver=$3 patches_ver=$4 cli_src=$5 cli_ver=$6 - local patches_dir=${patches_src%/*} - patches_dir=${TEMP_DIR}/${patches_dir,,}-rv - local integrations_dir=${integrations_src%/*} - integrations_dir=${TEMP_DIR}/${integrations_dir,,}-rv - local cli_dir=${cli_src%/*} - cli_dir=${TEMP_DIR}/${cli_dir,,}-rv - mkdir -p "$patches_dir" "$integrations_dir" "$cli_dir" - + local cli_src=$1 cli_ver=$2 integrations_src=$3 integrations_ver=$4 patches_src=$5 patches_ver=$6 pr "Getting prebuilts (${patches_src%/*})" >&2 - local rv_cli_url rv_integrations_url rv_patches rv_patches_dl rv_patches_url rv_patches_json - - local rv_cli_rel="https://api.github.com/repos/${cli_src}/releases/" - if [ "$cli_ver" ]; then rv_cli_rel+="tags/${cli_ver}"; else rv_cli_rel+="latest"; fi - local rv_integrations_rel="https://api.github.com/repos/${integrations_src}/releases/" - if [ "$integrations_ver" ]; then rv_integrations_rel+="tags/${integrations_ver}"; else rv_integrations_rel+="latest"; fi - local rv_patches_rel="https://api.github.com/repos/${patches_src}/releases/" - if [ "$patches_ver" ]; then rv_patches_rel+="tags/${patches_ver}"; else rv_patches_rel+="latest"; fi - rv_cli_url=$(gh_req "$rv_cli_rel" - | json_get 'browser_download_url') || return 1 - local rv_cli_jar="${cli_dir}/${rv_cli_url##*/}" - echo "CLI: $(cut -d/ -f4 <<<"$rv_cli_url")/$(cut -d/ -f9 <<<"$rv_cli_url") " >"$patches_dir/changelog.md" - - rv_integrations_url=$(gh_req "$rv_integrations_rel" - | json_get 'browser_download_url' | grep -E '\.apk$') || return 1 - local rv_integrations_apk="${integrations_dir}/${rv_integrations_url##*/}" - echo "Integrations: $(cut -d/ -f4 <<<"$rv_integrations_url")/$(cut -d/ -f9 <<<"$rv_integrations_url") " >>"$patches_dir/changelog.md" - - rv_patches=$(gh_req "$rv_patches_rel" -) || return 1 - # rv_patches_changelog=$(json_get 'body' <<<"$rv_patches" | sed 's/\(\\n\)\+/\\n/g') - rv_patches_dl=$(json_get 'browser_download_url' <<<"$rv_patches") - rv_patches_json="${patches_dir}/patches-$(json_get 'tag_name' <<<"$rv_patches").json" - rv_patches_url=$(grep -E '\.jar$' <<<"$rv_patches_dl") - local rv_patches_jar="${patches_dir}/${rv_patches_url##*/}" - [ -f "$rv_patches_jar" ] || REBUILD=true - local nm - nm=$(cut -d/ -f9 <<<"$rv_patches_url") - echo "Patches: $(cut -d/ -f4 <<<"$rv_patches_url")/$nm " >>"$patches_dir/changelog.md" - # shellcheck disable=SC2001 - echo -e "[Changelog](https://github.com/${patches_src}/releases/tag/v$(sed 's/.*-\(.*\)\..*/\1/' <<<"$nm"))\n" >>"$patches_dir/changelog.md" - # echo -e "\n${rv_patches_changelog//# [/### [}\n---" >>"$patches_dir/changelog.md" - - dl_if_dne "$rv_cli_jar" "$rv_cli_url" >&2 || return 1 - dl_if_dne "$rv_integrations_apk" "$rv_integrations_url" >&2 || return 1 - dl_if_dne "$rv_patches_jar" "$rv_patches_url" >&2 || return 1 - dl_if_dne "$rv_patches_json" "$(grep 'json' <<<"$rv_patches_dl")" >&2 || return 1 - - echo "$rv_cli_jar" "$rv_integrations_apk" "$rv_patches_jar" "$rv_patches_json" + for f in "${TEMP_DIR}"/*-rv; do : >"${f}/changelog.md"; done + for src_ver in "$cli_src CLI $cli_ver" "$integrations_src Integrations $integrations_ver" "$patches_src Patches $patches_ver"; do + set -- $src_ver + local src=$1 tag=$2 ver=${3-} ext + if [ "$tag" = "CLI" ] || [ "$tag" = "Patches" ]; then + ext="jar" + elif [ "$tag" = "Integrations" ]; then + ext="apk" + else abort unreachable; fi + local dir=${src%/*} + dir=${TEMP_DIR}/${dir,,}-rv + [ -d "$dir" ] || mkdir "$dir" + + local rv_rel="https://api.github.com/repos/${src}/releases/" + if [ "$ver" ]; then rv_rel+="tags/${ver}"; else rv_rel+="latest"; fi + + local resp asset url name file + resp=$(gh_req "$rv_rel" -) || return 1 + asset=$(jq -e -r ".assets[] | select(.name | endswith(\"$ext\"))" <<<"$resp") || return 1 + url=$(jq -r .url <<<"$asset") + name=$(jq -r .name <<<"$asset") + file="${dir}/${name}" + [ -f "$file" ] || REBUILD=true + + echo "$tag: $(cut -d/ -f5 <<<"$url")/${name} " >>"$dir/changelog.md" + gh_dl "$file" "$url" >&2 || return 1 + echo -n "$file " + if [ "$tag" = "Patches" ]; then + local tag_name + tag_name=$(jq -r '.tag_name' <<<"$resp") + name="patches-${tag_name}.json" + file="${dir}/${name}" + url=$(jq -e -r '.assets[] | select(.name | endswith("json")) | .url' <<<"$resp") || return 1 + gh_dl "$file" "$url" >&2 || return 1 + echo -n "$file " + echo -e "[Changelog](https://github.com/${src}/releases/tag/${tag_name})\n" >>"$dir/changelog.md" + fi + done + echo } get_prebuilts() { + APKSIGNER="${BIN_DIR}/apksigner.jar" if [ "$OS" = Android ]; then local arch if [ "$(uname -m)" = aarch64 ]; then arch=arm64; else arch=arm; fi - dl_if_dne ${TEMP_DIR}/aapt2 https://github.com/rendiix/termux-aapt/raw/d7d4b4a344cc52b94bcdab3500be244151261d8e/prebuilt-binary/${arch}/aapt2 - chmod +x "${TEMP_DIR}/aapt2" + HTMLQ="${BIN_DIR}/htmlq/htmlq-${arch}" + AAPT2="${BIN_DIR}/aapt2/aapt2-${arch}" + else + HTMLQ="${BIN_DIR}/htmlq/htmlq-x86_64" fi mkdir -p ${MODULE_TEMPLATE_DIR}/bin/arm64 ${MODULE_TEMPLATE_DIR}/bin/arm ${MODULE_TEMPLATE_DIR}/bin/x86 ${MODULE_TEMPLATE_DIR}/bin/x64 - dl_if_dne "${MODULE_TEMPLATE_DIR}/bin/arm64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-arm64-v8a" - dl_if_dne "${MODULE_TEMPLATE_DIR}/bin/arm/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-armeabi-v7a" - dl_if_dne "${MODULE_TEMPLATE_DIR}/bin/x86/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86" - dl_if_dne "${MODULE_TEMPLATE_DIR}/bin/x64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86_64" - - HTMLQ="${TEMP_DIR}/htmlq" - if [ ! -f "$HTMLQ" ]; then - if [ "$OS" = Android ]; then - if [ "$arch" = arm64 ]; then arch=arm64-v8a; else arch=armeabi-v7a; fi - dl_if_dne ${TEMP_DIR}/htmlq https://github.com/j-hc/htmlq-ndk/releases/latest/download/htmlq-${arch} - chmod +x $HTMLQ - else - if [ "${DRYRUN:-}" ]; then - : >"$HTMLQ" - else - req "https://github.com/mgdm/htmlq/releases/latest/download/htmlq-x86_64-linux.tar.gz" "${TEMP_DIR}/htmlq.tar.gz" - tar -xf "${TEMP_DIR}/htmlq.tar.gz" -C "$TEMP_DIR" - rm "${TEMP_DIR}/htmlq.tar.gz" - fi - fi - - fi + gh_dl "${MODULE_TEMPLATE_DIR}/bin/arm64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-arm64-v8a" + gh_dl "${MODULE_TEMPLATE_DIR}/bin/arm/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-armeabi-v7a" + gh_dl "${MODULE_TEMPLATE_DIR}/bin/x86/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86" + gh_dl "${MODULE_TEMPLATE_DIR}/bin/x64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86_64" } config_update() { @@ -143,7 +119,8 @@ config_update() { fi else sources[$PATCHES_SRC]=0 - if ! last_patches_url=$(gh_req "https://api.github.com/repos/${PATCHES_SRC}/releases/latest" - 2>&1 | json_get 'browser_download_url' | grep -E '\.jar$'); then + if ! last_patches_url=$(gh_req "https://api.github.com/repos/${PATCHES_SRC}/releases/latest" - \ + | jq -e -r '.assets[] | select(.name | endswith("jar")) | .name'); then abort oops fi last_patches=${last_patches_url##*/} @@ -164,21 +141,29 @@ config_update() { } _req() { - if [ "$2" = - ]; then - wget -nv -O "$2" --header="$3" "$1" + local ip="$1" op="$2" + shift 2 + if [ "$op" = - ]; then + wget -nv -O "$op" "$@" "$ip" else local dlp - dlp="$(dirname "$2")/tmp.$(basename "$2")" + dlp="$(dirname "$op")/tmp.$(basename "$op")" if [ -f "$dlp" ]; then while [ -f "$dlp" ]; do sleep 1; done return fi - wget -nv -O "$dlp" --header="$3" "$1" || return 1 - mv -f "$dlp" "$2" + wget -nv -O "$dlp" "$@" "$ip" || return 1 + mv -f "$dlp" "$op" + fi +} +req() { _req "$1" "$2" --header="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0"; } +gh_req() { _req "$1" "$2" --header="$GH_HEADER"; } +gh_dl() { + if [ ! -f "$1" ]; then + pr "Getting '$1' from '$2'" + _req "$2" "$1" --header="$GH_HEADER" --header="Accept: application/octet-stream" fi } -req() { _req "$1" "$2" "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0"; } -gh_req() { _req "$1" "$2" "$GH_HEADER"; } log() { echo -e "$1 " >>"build.md"; } get_largest_ver() { @@ -198,7 +183,7 @@ get_patch_last_supported_ver() { exc_sel=$(list_args "$3" | sed 's/.*/\.name != &/' | paste -sd '~' | sed 's/~/ and /g' || :) inc_sel=${inc_sel:-false} if [ "$4" = false ]; then inc_sel="${inc_sel} or .use==true"; fi - if ! vs=$(jq -r ".[] + if ! vs=$(jq -e -r ".[] | select(.compatiblePackages // [] | .[] | .name==\"${1}\") | select(${inc_sel}) | select(${exc_sel:-true}) @@ -208,17 +193,6 @@ get_patch_last_supported_ver() { tr -d ' ,\t[]"' <<<"$vs" | sort -u | grep -v '^$' | get_largest_ver || : } -dl_if_dne() { - [ "${DRYRUN:-}" ] && { - : >"$1" - return 0 - } - if [ ! -f "$1" ]; then - pr "Getting '$1' from '$2'" - req "$2" "$1" - fi -} - isoneof() { local i=$1 v shift @@ -230,30 +204,30 @@ isoneof() { dl_apkmirror() { local url=$1 version=${2// /-} output=$3 arch=$4 dpi=$5 apkorbundle=APK if [ "$arch" = "arm-v7a" ]; then arch="armeabi-v7a"; fi - [ "${DRYRUN:-}" ] && { - : >"$output" - return 0 - } local apparch resp node app_table dlurl="" if [ "$arch" = all ]; then apparch=(universal noarch 'arm64-v8a + armeabi-v7a') else apparch=("$arch" universal noarch 'arm64-v8a + armeabi-v7a'); fi url="${url}/${url##*/}-${version//./-}-release/" resp=$(req "$url" -) || return 1 - for ((n = 1; n < 40; n++)); do - node=$($HTMLQ "div.table-row.headerFont:nth-last-child($n)" -r "span:nth-child(n+3)" <<<"$resp") - if [ -z "$node" ]; then break; fi - app_table=$($HTMLQ --text --ignore-whitespace <<<"$node") - if [ "$(sed -n 3p <<<"$app_table")" = "$apkorbundle" ] && { [ "$apkorbundle" = BUNDLE ] || - { [ "$apkorbundle" = APK ] && [ "$(sed -n 6p <<<"$app_table")" = "$dpi" ] && - isoneof "$(sed -n 4p <<<"$app_table")" "${apparch[@]}"; }; }; then - dlurl=$($HTMLQ --base https://www.apkmirror.com --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node") - break - fi - done - [ -z "$dlurl" ] && return 1 - url=$(req "$dlurl" - | $HTMLQ --base https://www.apkmirror.com --attribute href "a.btn") || return 1 - if [ "$apkorbundle" = BUNDLE ] && [[ "$url" != *"&forcebaseapk=true" ]]; then url="${url}&forcebaseapk=true"; fi + node=$($HTMLQ "div.table-row.headerFont:nth-last-child(1)" -r "span:nth-child(n+3)" <<<"$resp") + if [ "$node" ]; then + for ((n = 1; n < 40; n++)); do + node=$($HTMLQ "div.table-row.headerFont:nth-last-child($n)" -r "span:nth-child(n+3)" <<<"$resp") + if [ -z "$node" ]; then break; fi + app_table=$($HTMLQ --text --ignore-whitespace <<<"$node") + if [ "$(sed -n 3p <<<"$app_table")" = "$apkorbundle" ] && { [ "$apkorbundle" = BUNDLE ] \ + || { [ "$apkorbundle" = APK ] && [ "$(sed -n 6p <<<"$app_table")" = "$dpi" ] \ + && isoneof "$(sed -n 4p <<<"$app_table")" "${apparch[@]}"; }; }; then + dlurl=$($HTMLQ --base https://www.apkmirror.com --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node") + break + fi + done + [ -z "$dlurl" ] && return 1 + resp=$(req "$dlurl" -) + fi + url=$(echo "$resp" | $HTMLQ --base https://www.apkmirror.com --attribute href "a.btn") || return 1 + if [ "$apkorbundle" = BUNDLE ] && [[ $url != *"&forcebaseapk=true" ]]; then url="${url}&forcebaseapk=true"; fi url=$(req "$url" - | $HTMLQ --base https://www.apkmirror.com --attribute href "span > a[rel = nofollow]") || return 1 req "$url" "$output" } @@ -328,18 +302,23 @@ get_archive_pkg_name() { echo "$__ARCHIVE_PKG_NAME__"; } patch_apk() { local stock_input=$1 patched_apk=$2 patcher_args=$3 rv_cli_jar=$4 rv_patches_jar=$5 - local cmd="java -jar $rv_cli_jar patch $stock_input -p -o $patched_apk -b $rv_patches_jar \ ---keystore=ks.keystore --keystore-entry-password=123456789 --keystore-password=123456789 --signer=jhc --alias=jhc $patcher_args --options=options.json" - if [ "$OS" = Android ]; then cmd+=" --custom-aapt2-binary=${TEMP_DIR}/aapt2"; fi + local cmd="java -jar $rv_cli_jar patch $stock_input -p -o $patched_apk -b $rv_patches_jar $patcher_args --keystore=ks.keystore \ +--keystore-entry-password=123456789 --keystore-password=123456789 --signer=jhc --keystore-entry-alias=jhc --options=options.json" + if [ "$OS" = Android ]; then cmd+=" --custom-aapt2-binary=${AAPT2}"; fi pr "$cmd" - if [ "${DRYRUN:-}" = true ]; then - cp -f "$stock_input" "$patched_apk" - else - eval "$cmd" - fi + eval "$cmd" [ -f "$patched_apk" ] } +check_sig() { + local file=$1 pkg_name=$2 + local sig + if grep -q "$pkg_name" sig.txt; then + sig=$(java -jar "$APKSIGNER" verify --print-certs "$file" | grep ^Signer | grep SHA-256 | tail -1 | awk '{print $NF}') + grep -qFx "$sig $pkg_name" sig.txt + fi +} + build_rv() { eval "declare -A args=${1#*=}" local version build_mode_arr pkg_name @@ -408,6 +387,9 @@ build_rv() { done if [ ! -f "$stock_apk" ]; then return 0; fi fi + if ! check_sig "$stock_apk" "$pkg_name"; then + abort "apk signature mismatch '$stock_apk'" + fi log "${table}: ${version}" p_patcher_args+=("-m ${args[integ]}") @@ -418,25 +400,6 @@ build_rv() { p_patcher_args=("${p_patcher_args[@]//-[ei] ${microg_patch}/}") fi - local stock_bundle_apk="${TEMP_DIR}/${pkg_name}-${version_f}-${arch_f}-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 '${table}' bundle from APKMirror" - # if dl_apkmirror "${args[apkmirror_dlurl]}" "$version" "$stock_bundle_apk" BUNDLE "" ""; then - # if (($(stat -c%s "$stock_apk") - $(stat -c%s "$stock_bundle_apk") > 10000000)); then - # pr "'${table}' bundle was downloaded successfully and will be used for the module" - # is_bundle=true - # else - # pr "'${table}' bundle was downloaded but will not be used" - # fi - # else - # pr "'${table}' bundle was not found" - # fi - # fi - # fi if [ "$mode_arg" = module ]; then build_mode_arr=(module) elif [ "$mode_arg" = apk ]; then @@ -490,33 +453,20 @@ build_rv() { cp -a $MODULE_TEMPLATE_DIR/. "$base_template" local upj="${table,,}-update.json" - 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" "$isbndl" "$base_template" - service_sh "$pkg_name" "$version" "$base_template" - customize_sh "$pkg_name" "$version" "$arch" "$extrct" "$base_template" + module_config "$base_template" "$pkg_name" "$version" "$arch" module_prop \ "${args[module_prop_name]}" \ "${app_name} ${args[rv_brand]}" \ "$version" \ "${app_name} ${args[rv_brand]} Magisk Module" \ - "https://raw.githubusercontent.com/${GITHUB_REPOSITORY:-}/update/${upj}" \ + "https://raw.githubusercontent.com/${GITHUB_REPOSITORY-}/update/${upj}" \ "$base_template" local module_output="${app_name_l}-${rv_brand_f}-magisk-v${version_f}-${arch_f}.zip" if [ ! -f "$module_output" ] || [ "$REBUILD" = true ]; then pr "Packing module ${table}" cp -f "$patched_apk" "${base_template}/base.apk" - if [ "${args[include_stock]}" = true ]; then cp -f "$stock_apk_module" "${base_template}/${pkg_name}.apk"; fi + if [ "${args[include_stock]}" = true ]; then cp -f "$stock_apk" "${base_template}/${pkg_name}.apk"; fi pushd >/dev/null "$base_template" || abort "Module template dir not found" zip -"$COMPRESSION_LEVEL" -FSqr "../../${BUILD_DIR}/${module_output}" . popd >/dev/null || : @@ -528,24 +478,16 @@ build_rv() { 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 " " - || :; } -uninstall_sh() { - local s="${UNINSTALL_SH//__PKGNAME/$1}" - echo "${s//__ISBNDL/$2}" >"${3}/uninstall.sh" -} -customize_sh() { - local s="${CUSTOMIZE_SH//__PKGNAME/$1}" - 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") +module_config() { + local ma="" + if [ "$4" = "arm64-v8a" ]; then + ma="arm64" + elif [ "$4" = "arm-v7a" ]; then + ma="arm" fi - echo "${s//__PKGVER/$2}" >"${5}/customize.sh" -} -service_sh() { - local s="${SERVICE_SH//__PKGNAME/$1}" - echo "${s//__PKGVER/$2}" >"${3}/service.sh" + echo "PKG_NAME=$2 +PKG_VER=$3 +MODULE_ARCH=$ma" >"$1/config" } module_prop() { echo "id=${1}