Skip to content

Commit

Permalink
chore: sync upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
RiverOnVenus committed Nov 29, 2024
2 parents 201eae0 + 5315c08 commit caed8e6
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
if git checkout origin/update build.md; then
UPDATE_CFG=$(./build.sh config.toml --config-update)
if [ "$UPDATE_CFG" ]; then
echo "$UPDATE_CFG" > config.toml
echo "$UPDATE_CFG" > config.json
fi
fi
Expand All @@ -45,7 +45,7 @@ jobs:
echo "NEXT_VER_CODE=$((TAG + 1))" >> $GITHUB_OUTPUT
- name: Build modules/APKs
run: ./build.sh config.toml
run: if [ -f "config.json" ]; then ./build.sh config.json; else ./build.sh config.toml; fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: $GITHUB_REPOSITORY
Expand Down
42 changes: 29 additions & 13 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,47 @@ There exists an example below with all defaults shown and all the keys explicitl
**All keys are optional** (except download urls) and are assigned to their default values if not set explicitly.

```toml
parallel-jobs = 1 # amount of cores to use for parallel patching, if not set nproc is used
compression-level = 9 # module zip compression level
parallel-jobs = 1 # amount of cores to use for parallel patching, if not set $(nproc) is used
compression-level = 9 # module zip compression level
remove-rv-integrations-checks = true # remove checks from the revanced integrations

patches-source = "revanced/revanced-patches" # where to fetch patches bundle from. default: "revanced/revanced-patches"
cli-source = "j-hc/revanced-cli" # where to fetch cli from. default: "j-hc/revanced-cli"
cli-source = "j-hc/revanced-cli" # where to fetch cli from. default: "j-hc/revanced-cli"
# options like cli-source can also set per app
rv-brand = "ReVanced Extended" # rebrand from 'ReVanced' to something different. default: "ReVanced"

patches-version = "v2.160.0" # 'latest', 'dev', or a version number. default: "latest"
cli-version = "v5.0.0" # 'latest', 'dev', or a version number. default: "latest"

[Some-App]
app-name = "SomeApp" # if set, release name becomes SomeApp instead of Some-App. default is same as table name, which is 'Some-App' here.
enabled = true # whether to build the app. default: true
enabled = true # whether to build the app. default: true
version = "auto" # 'auto', 'latest', 'beta' or a version number (e.g. '17.40.41'). default: auto
build-mode = "apk" # 'both', 'apk' or 'module'. default: apk

# optional args to be passed to cli. can be used to set patch options
# multiline strings in the config is supported
patcher-args = """\
-OdarkThemeBackgroundColor=#FF0F0F0F \
-Oanother-option=value \
"""

# 'auto' option gets the latest possible version supported by all the included patches
# 'latest' gets the latest stable without checking patches support. 'beta' gets the latest beta/alpha
include-stock = true # includes stock apk in the module. default: true
build-mode = "apk" # 'both', 'apk' or 'module'. default: apk
excluded-patches = "'Some Patch' 'Some Other Patch'" # whitespace seperated list of patches to exclude. default: "" (empty)
included-patches = "'Patch something'" # whitespace seperated list of patches to include, all default patches are included by default. default: "" (empty)
exclusive-patches = false # exclude all patches by default. default: false
# whitespace seperated list of patches to exclude. default: ""
excluded-patches = """\
'Some Patch' \
'Some Other Patch' \
"""

included-patches = "'Some Patch'" # whitespace seperated list of non-default patches to include. default: ""
include-stock = true # includes stock apk in the module. default: true
exclusive-patches = false # exclude all patches by default. default: false
apkmirror-dlurl = "https://www.apkmirror.com/apk/inc/app"
uptodown-dlurl = "https://spotify.en.uptodown.com/android"
module-prop-name = "some-app-magisk" # magisk module prop name.
apkmirror-dpi = "360-480dpi" # used to select apk variant from apkmirror. default: nodpi
arch = "arm64-v8a" # 'arm64-v8a', 'arm-v7a', 'all', 'both'. 'both' downloads both arm64-v8a and arm-v7a. default: all
riplib = true # enables ripping x86 and x86_64 libs from apks with j-hc revanced cli. default: true
module-prop-name = "some-app-magisk" # magisk module prop name.
apkmirror-dpi = "360-480dpi" # used to select apk variant from apkmirror. default: nodpi
arch = "arm64-v8a" # 'arm64-v8a', 'arm-v7a', 'all', 'both'. 'both' downloads both arm64-v8a and arm-v7a. default: all
riplib = true # enables ripping x86 and x86_64 libs from apks with j-hc revanced cli. default: true

```
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<<<<<<< HEAD
=======
#### ⚠️ Do not download modules from 3rd party sources like random websites you found on Google. There are many that uses my modules and impersonates ReVanced.

>>>>>>> 2d031b5 (Initial commit)
# ReVanced Magisk Module
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/rvc_magisk)
[![CI](https://github.com/j-hc/revanced-magisk-module/actions/workflows/ci.yml/badge.svg?event=schedule)](https://github.com/j-hc/revanced-magisk-module/actions/workflows/ci.yml)
Expand Down
Binary file added bin/toml/tq-arm
Binary file not shown.
Binary file added bin/toml/tq-arm64
Binary file not shown.
Binary file added bin/toml/tq-x86_64
Binary file not shown.
21 changes: 12 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ if [ "${1-}" = "clean" ]; then
fi

source utils.sh
set_prebuilts

vtf() { if ! isoneof "${1}" "true" "false"; then abort "ERROR: '${1}' is not a valid option for '${2}': only true or false is allowed"; fi; }

toml_prep "$(cat 2>/dev/null "${1:-config.toml}")" || abort "could not find config file '${1:-config.toml}'\n\tUsage: $0 <config.toml>"
# -- Main config --
main_config_t=$(toml_get_table "")
toml_prep "${1:-config.toml}" || abort "could not find config file '${1:-config.toml}'\n\tUsage: $0 <config.toml>"
main_config_t=$(toml_get_table_main)
COMPRESSION_LEVEL=$(toml_get "$main_config_t" compression-level) || COMPRESSION_LEVEL="9"
if ! PARALLEL_JOBS=$(toml_get "$main_config_t" parallel-jobs); then
if [ "$OS" = Android ]; then PARALLEL_JOBS=1; else PARALLEL_JOBS=$(nproc); fi
fi
REMOVE_RV_INTEGRATIONS_CHECKS=$(toml_get "$main_config_t" remove-rv-integrations-checks) || REMOVE_RV_INTEGRATIONS_CHECKS="true"

DEF_PATCHES_VER=$(toml_get "$main_config_t" patches-version) || DEF_PATCHES_VER="latest"
DEF_CLI_VER=$(toml_get "$main_config_t" cli-version) || DEF_CLI_VER="latest"
DEF_PATCHES_SRC=$(toml_get "$main_config_t" patches-source) || DEF_PATCHES_SRC="ReVanced/revanced-patches"
Expand All @@ -40,28 +40,30 @@ 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
# -----------------

if ((COMPRESSION_LEVEL > 9)) || ((COMPRESSION_LEVEL < 0)); then abort "compression-level must be within 0-9"; fi

# -- check_deps --
jq --version >/dev/null || abort "\`jq\` is not installed. install it with 'apt install jq' or equivalent"
java --version >/dev/null || abort "\`openjdk 17\` is not installed. install it with 'apt install openjdk-17-jre' or equivalent"
zip --version >/dev/null || abort "\`zip\` is not installed. install it with 'apt install zip' or equivalent"
# ----------------

rm -rf revanced-magisk/bin/*/tmp.*
if [ "$(echo "$TEMP_DIR"/*-rv/changelog.md)" ]; then
: >"$TEMP_DIR"/*-rv/changelog.md || :
fi

get_prebuilts
mkdir -p ${MODULE_TEMPLATE_DIR}/bin/arm64 ${MODULE_TEMPLATE_DIR}/bin/arm ${MODULE_TEMPLATE_DIR}/bin/x86 ${MODULE_TEMPLATE_DIR}/bin/x64
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"

declare -A cliriplib
idx=0
for table_name in $(toml_get_table_names); do
if [ -z "$table_name" ]; then continue; fi
t=$(toml_get_table "$table_name")
enabled=$(toml_get "$t" enabled) && vtf "$enabled" "enabled" || enabled=true
enabled=$(toml_get "$t" enabled) || enabled=true
vtf "$enabled" "enabled"
if [ "$enabled" = false ]; then continue; fi
if ((idx >= PARALLEL_JOBS)); then
wait -n
Expand Down Expand Up @@ -99,6 +101,7 @@ for table_name in $(toml_get_table_names); do
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
app_args[patcher_args]=$(toml_get "$t" patcher-args) || app_args[patcher_args]=""
app_args[table]=$table_name
app_args[build_mode]=$(toml_get "$t" build-mode) && {
if ! isoneof "${app_args[build_mode]}" both apk module; then
Expand Down
7 changes: 5 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enable-magisk-update = true # set this to false if you do not want to receive updates for the module in magisk app
enable-magisk-update = true # set this to false if you do not want to receive updates for the module in magisk app
parallel-jobs = 1

# add 'enabled = false' for not patching a specific app or remove it from the config
Expand All @@ -11,17 +11,20 @@ build-mode = "module"
excluded-patches = ""
included-patches = ""
version = "auto"
apkmirror-dlurl = "https://www.apkmirror.com/apk/google-inc/youtube" # fallback
apkmirror-dlurl = "https://www.apkmirror.com/apk/google-inc/youtube"
uptodown-dlurl = "https://youtube.en.uptodown.com/android"
# archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.google.android.youtube"

[Music]
build-mode = "module"
arch = "arm64-v8a"
apkmirror-dlurl = "https://www.apkmirror.com/apk/google-inc/youtube-music"
uptodown-dlurl = "https://youtube-music.en.uptodown.com/android"
# archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.google.android.apps.youtube.music"

[Twitch]
apkmirror-dlurl = "https://www.apkmirror.com/apk/twitch-interactive-inc/twitch/"
uptodown-dlurl = "https://twitch.en.uptodown.com/android"
# archive-dlurl = "https://archive.org/download/jhc-apks/apks/tv.twitch.android.app"

# [Music-Extended]
Expand Down
107 changes: 58 additions & 49 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@ if [ "${GITHUB_TOKEN-}" ]; then GH_HEADER="Authorization: token ${GITHUB_TOKEN}"
NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')}
OS=$(uname -o)

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
tn=$(grep -x '\[.*\]' <<<"$__TOML__" | tr -d '[]') || return 1
if [ "$(sort <<<"$tn" | uniq -u | wc -l)" != "$(wc -l <<<"$tn")" ]; then
abort "ERROR: Duplicate tables in TOML"
fi
echo "$tn"
toml_prep() {
if [ ! -f "$1" ]; then return 1; fi
if [ "${1##*.}" == toml ]; then
__TOML__=$($TOML --output json --file "$1" .)
elif [ "${1##*.}" == json ]; then
__TOML__=$(cat "$1")
else abort "config extension not supported"; fi
}
toml_get_table() { sed -n "/\[${1}]/,/^\[.*]$/p" <<<"$__TOML__" | sed '${/^\[/d;}'; }
toml_get_table_names() { jq -r -e 'to_entries[] | select(.value | type == "object") | .key' <<<"$__TOML__"; }
toml_get_table_main() { jq -r -e 'to_entries | map(select(.value | type != "object")) | from_entries' <<<"$__TOML__"; }
toml_get_table() { jq -r -e ".\"${1}\"" <<<"$__TOML__"; }
toml_get() {
local table=$1 key=$2 val
val=$(grep -m 1 "^${key}=" <<<"$table") && sed -e "s/^\"//; s/\"$//" <<<"${val#*=}"
local op
op=$(jq -r ".\"${2}\" | values" <<<"$1")
if [ "$op" ]; then
op="${op#"${op%%[![:space:]]*}"}"
op="${op%"${op##*[![:space:]]}"}"
op=${op//"'"/'"'}
echo "$op"
else return 1; fi
}

pr() { echo -e "\033[0;32m[+] ${1}\033[0m"; }
Expand Down Expand Up @@ -110,31 +117,25 @@ get_rv_prebuilts() {
echo
}

get_prebuilts() {
set_prebuilts() {
APKSIGNER="${BIN_DIR}/apksigner.jar"
if [ "$OS" = Android ]; then
local arch
if [ "$(uname -m)" = aarch64 ]; then arch=arm64; else arch=arm; fi
HTMLQ="${BIN_DIR}/htmlq/htmlq-${arch}"
AAPT2="${BIN_DIR}/aapt2/aapt2-${arch}"
TOML="${BIN_DIR}/toml/tq-${arch}"
else
HTMLQ="${BIN_DIR}/htmlq/htmlq-x86_64"
TOML="${BIN_DIR}/toml/tq-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
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() {
if [ ! -f build.md ]; then abort "build.md not available"; fi
declare -A sources
: >"$TEMP_DIR"/skipped
local conf=""
# shellcheck disable=SC2154
conf+=$(sed '1d' <<<"$main_config_t")
conf+=$'\n'
local upped=()
local prcfg=false
for table_name in $(toml_get_table_names); do
if [ -z "$table_name" ]; then continue; fi
Expand All @@ -144,10 +145,7 @@ config_update() {
PATCHES_SRC=$(toml_get "$t" patches-source) || PATCHES_SRC=$DEF_PATCHES_SRC
PATCHES_VER=$(toml_get "$t" patches-version) || PATCHES_VER=$DEF_PATCHES_VER
if [[ -v sources["$PATCHES_SRC/$PATCHES_VER"] ]]; then
if [ "${sources["$PATCHES_SRC/$PATCHES_VER"]}" = 1 ]; then
conf+="$t"
conf+=$'\n'
fi
if [ "${sources["$PATCHES_SRC/$PATCHES_VER"]}" = 1 ]; then upped+=("$table_name"); fi
else
sources["$PATCHES_SRC/$PATCHES_VER"]=0
local rv_rel="https://api.github.com/repos/${PATCHES_SRC}/releases"
Expand All @@ -165,15 +163,21 @@ config_update() {
if ! OP=$(grep "^Patches: ${PATCHES_SRC%%/*}/" build.md | grep "$last_patches"); then
sources["$PATCHES_SRC/$PATCHES_VER"]=1
prcfg=true
conf+="$t"
conf+=$'\n'
upped+=("$table_name")
else
echo "$OP" >>"$TEMP_DIR"/skipped
fi
fi
fi
done
if [ "$prcfg" = true ]; then echo "$conf"; fi
if [ "$prcfg" = true ]; then
local query=""
for table in "${upped[@]}"; do
if [ -n "$query" ]; then query+=" or "; fi
query+=".key == \"$table\""
done
jq "to_entries | map(select(${query} or (.value | type != \"object\"))) | from_entries" <<<"$__TOML__"
fi
}

_req() {
Expand Down Expand Up @@ -356,32 +360,36 @@ get_uptodown_resp() {
}
get_uptodown_vers() { $HTMLQ --text ".version" <<<"$__UPTODOWN_RESP__"; }
dl_uptodown() {
local uptodown_dlurl=$1 version=$2 output=$3 arch=$4 _dpi=$5 is_latest=$6
local url
if [ "$is_latest" = false ]; then
url=$(grep -F "${version}</span>" -B 2 <<<"$__UPTODOWN_RESP__" | head -1 | sed -n 's;.*data-url=".*download\/\(.*\)".*;\1;p') || return 1
url="/$url"
else url=""; fi
local uptodown_dlurl=$1 version=$2 output=$3 arch=$4 _dpi=$5
if [ "$arch" = "arm-v7a" ]; then arch="armeabi-v7a"; fi
local op resp data_code
data_code=$($HTMLQ "#detail-app-name" --attribute data-code <<<"$__UPTODOWN_RESP__")
local versionURL=""
for i in {1..5}; do
resp=$(req "${uptodown_dlurl}/apps/${data_code}/versions/${i}" -)
if ! op=$(jq -e -r ".data | map(select(.version == \"${version}\" and .kindFile == \"apk\")) | .[0]" <<<"$resp"); then
continue
fi
if versionURL=$(jq -e -r '.versionURL' <<<"$op"); then break; else return 1; fi
done
if [ -z "$versionURL" ]; then return 1; fi
resp=$(req "$versionURL" -) || return 1
if [ "$arch" != all ]; then
local app_code data_version files node_arch content resp
if [ "$is_latest" = false ]; then
resp=$(req "${1}/download${url}" -)
else resp="$__UPTODOWN_RESP_PKG__"; fi
app_code=$($HTMLQ "#detail-app-name" --attribute code <<<"$resp")
data_version=$($HTMLQ "button.button:nth-child(2)" --attribute data-version <<<"$resp")
files=$(req "${uptodown_dlurl%/*}/app/${app_code}/version/${data_version}/files" - | jq -r .content)
for ((n = 1; n < 40; n++)); do
local data_version files node_arch data_file_id
data_version=$($HTMLQ '.button.variants' --attribute data-version <<<"$resp") || return 1
files=$(req "${uptodown_dlurl%/*}/app/${data_code}/version/${data_version}/files" - | jq -e -r .content) || return 1
for ((n = 1; n < 12; n += 2)); do
node_arch=$($HTMLQ ".content > p:nth-child($n)" --text <<<"$files" | xargs) || return 1
if [ -z "$node_arch" ]; then return 1; fi
if [ "$node_arch" != "$arch" ]; then continue; fi
content=$($HTMLQ "div.variant:nth-child($((n + 1)))" <<<"$files")
url=$(sed -n "s;.*'.*android\/post-download\/\(.*\)'.*;\1;p" <<<"$content" | head -1)
url="/$url"
data_file_id=$($HTMLQ "div.variant:nth-child($((n + 1))) > .v-report" --attribute data-file-id <<<"$files") || return 1
resp=$(req "${uptodown_dlurl}/download/${data_file_id}" -)
break
done
fi
url="https://dw.uptodown.com/dwn/$(req "${uptodown_dlurl}/post-download${url}" - | sed -n 's;.*class="post-download" data-url="\(.*\)".*;\1;p')" || return 1
req "$url" "$output"
local data_url
data_url=$($HTMLQ "#detail-download-button" --attribute data-url <<<"$resp") || return 1
req "https://dw.uptodown.com/dwn/${data_url}" "$output"
}
get_uptodown_pkg_name() { $HTMLQ --text "tr.full:nth-child(1) > td:nth-child(3)" <<<"$__UPTODOWN_RESP_PKG__"; }

Expand All @@ -404,7 +412,6 @@ 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
# TODO: --options
local cmd="java -jar $rv_cli_jar patch $stock_input --purge -o $patched_apk -p $rv_patches_jar --keystore=ks.keystore \
--keystore-entry-password=123456789 --keystore-password=123456789 --signer=jhc --keystore-entry-alias=jhc $patcher_args"
if [ "$OS" = Android ]; then cmd+=" --custom-aapt2-binary=${AAPT2}"; fi
Expand Down Expand Up @@ -437,7 +444,8 @@ build_rv() {
local arch_f="${arch// /}"

local p_patcher_args=()
p_patcher_args+=("$(join_args "${args[excluded_patches]}" -d) $(join_args "${args[included_patches]}" -e)")
if [ "${args[excluded_patches]}" ]; then p_patcher_args+=("$(join_args "${args[excluded_patches]}" -d)"); fi
if [ "${args[included_patches]}" ]; then p_patcher_args+=("$(join_args "${args[included_patches]}" -e)"); fi
[ "${args[exclusive_patches]}" = true ] && p_patcher_args+=("--exclusive")

local tried_dl=()
Expand Down Expand Up @@ -520,6 +528,7 @@ build_rv() {
local patcher_args patched_apk build_mode
local rv_brand_f=${args[rv_brand],,}
rv_brand_f=${rv_brand_f// /-}
if [ "${args[patcher_args]}" ]; then p_patcher_args+=("${args[patcher_args]}"); fi
for build_mode in "${build_mode_arr[@]}"; do
patcher_args=("${p_patcher_args[@]}")
pr "Building '${table}' in '$build_mode' mode"
Expand Down

0 comments on commit caed8e6

Please sign in to comment.