Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NoName-exe authored Feb 5, 2023
2 parents 68057a9 + 4d35c6e commit c028b5a
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 53 deletions.
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: Bug report
about: Bug report
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
**DO NOT REPORT REVANCED BUGS IN THIS REPO**
17 changes: 12 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ jobs:
fetch-depth: 0
submodules: true

- name: Get last tag
id: last_tag
uses: oprypin/find-latest-tag@v1
continue-on-error: true
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
releases-only: true

- name: Get next version code
id: next_ver_code
run: |
TAG=$(git tag --sort=creatordate | tail -1)
TAG="${{ steps.last_tag.outputs.tag }}"
if [ -z "$TAG" ]; then TAG=0; fi
echo "NEXT_VER_CODE=$((TAG + 1))" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -61,12 +70,10 @@ jobs:
file_glob: true
overwrite: false

- name: Switch to update branch
run: git checkout -f update || git switch --discard-changes --orphan update

- name: Update changelog and Magisk update jsons
- name: Update changelog and Magisk update json
id: update_config
run: |
git checkout -f update || git switch --discard-changes --orphan update
cp -f build.tmp build.md
get_update_json() {
echo "{
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ jobs:
toml_prep "$(cat config.toml)"
is_youtube_latest() {
v=$(toml_get "$(toml_get_table "YouTube")" "version") || version=""
t=$(toml_get_table YouTube)
v=$(toml_get "$t" "version") || v=
if [ "$v" = latest ]; then
declare -r cur_yt=$(sed -n 's/.*YouTube: \(.*\)/\1/p' build.md | xargs)
cur_yt=$(sed -n 's/.*YouTube: \(.*\)/\1/p' build.md | xargs)
[ -z "$cur_yt" ] && return 1 # empty, fail=>dont build
declare -r last_ver=$(get_apk_vers "https://www.apkmirror.com/uploads/?appcategory=youtube" | get_largest_ver)
echo "current yt version: $cur_yt"
echo "latest yt version: $last_ver"
aav=$(toml_get "$t" "allow-alpha-version") || aav=false
last_ver=$(get_apkmirror_vers youtube "$aav" | get_largest_ver)
[ -z "$last_ver" ] && return 1 # cant fetch, dont build
echo "current yt version: '$cur_yt'"
echo "latest yt version: '$last_ver'"
[ "$cur_yt" != "$last_ver" ] # test success=>build, fail=>dont build
else
return 1 # not experimental, dont build
Expand All @@ -37,8 +39,8 @@ jobs:
is_patches_latest() {
PATCHES_SRC=$(toml_get "$(toml_get_table "")" patches-source) || PATCHES_SRC="revanced/revanced-patches"
declare -r last_patches_url=$(wget -nv --header="Authorization: token ${{ secrets.GITHUB_TOKEN }}" -O- https://api.github.com/repos/${PATCHES_SRC}/releases/latest | json_get 'browser_download_url' | grep 'jar')
declare -r last_patches=${last_patches_url##*/}
last_patches_url=$(wget -nv --header="Authorization: token ${{ secrets.GITHUB_TOKEN }}" -O- https://api.github.com/repos/${PATCHES_SRC}/releases/latest | json_get 'browser_download_url' | grep 'jar')
last_patches=${last_patches_url##*/}
cur_patches=$(sed -n 's/.*Patches: \(.*\)/\1/p' build.md | xargs)
echo "current patches version: $cur_patches"
Expand Down
9 changes: 8 additions & 1 deletion CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ uptodown-dlurl = "https://app.en.uptodown.com/android"
## If you'd like to get to know more about other options:

There exists an example below with all defaults shown and all the keys explicitly set.
All keys are optional (except download urls) and are assigned to their default values if not set explicitly.
**All keys are optional** (except download urls) and are assigned to their default values if not set explicitly.

```toml
patches-source = "revanced/revanced-patches" # where to fetch patches bundle from. default: "revanced/revanced-patches"
integrations-source = "revanced/revanced-integrations" # where to fetch integrations from. default: "revanced/revanced-integrations"
rv-brand = "ReVanced Extended" # rebrand from 'ReVanced' to something different. default: "ReVanced"

patches-version = "v2.160.0" # locks the patches version. default: latest available
integrations-version = "v0.95.0" # locks the integrations version. default: latest available

[Some-App]
app-name = "SomeApp" # if set, app name becomes SomeApp instead of Some-App. default is same as table name, which is 'Some-App' here.
# this affects the release name and stuff like that
Expand Down
12 changes: 8 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail

source utils.sh
trap "rm -rf temp/tmp.*" INT
trap "rm -rf temp/tmp.*; exit 1" INT

: >build.md

Expand All @@ -21,12 +21,16 @@ vtf() {
}

toml_prep "$(cat 2>/dev/null "${1:-config.toml}")" || abort "could not find config file '${1}'"

# -- Main config --
main_config_t=$(toml_get_table "")
COMPRESSION_LEVEL=$(toml_get "$main_config_t" compression-level) || abort "ERROR: compression-level is missing"
ENABLE_MAGISK_UPDATE=$(toml_get "$main_config_t" enable-magisk-update) || abort "ERROR: enable-magisk-update is missing"
PARALLEL_JOBS=$(toml_get "$main_config_t" parallel-jobs) || abort "ERROR: parallel-jobs is missing"
BUILD_MINDETACH_MODULE=$(toml_get "$main_config_t" build-mindetach-module) || abort "ERROR: build-mindetach-module is missing"
LOGGING_F=$(toml_get "$main_config_t" logging-to-file) && vtf "$LOGGING_F" "logging-to-file" || LOGGING_F=false
CONF_PATCHES_VER=$(toml_get "$main_config_t" patches-version) || CONF_PATCHES_VER=
CONF_INTEGRATIONS_VER=$(toml_get "$main_config_t" integrations-version) || CONF_INTEGRATIONS_VER=

PATCHES_SRC=$(toml_get "$main_config_t" patches-source) || PATCHES_SRC="revanced/revanced-patches"
INTEGRATIONS_SRC=$(toml_get "$main_config_t" integrations-source) || INTEGRATIONS_SRC="revanced/revanced-integrations"
Expand All @@ -35,13 +39,13 @@ RV_BRAND_F=${RV_BRAND,,}
RV_BRAND_F=${RV_BRAND_F// /-}
PREBUILTS_DIR="${TEMP_DIR}/tools-${RV_BRAND_F}"
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 [ "$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"
get_cmpr

log "**App Versions:**"
idx=0
Expand All @@ -61,7 +65,7 @@ for table_name in $(toml_get_table_names); do
app_args[allow_alpha_version]=$(toml_get "$t" allow-alpha-version) && vtf "${app_args[allow_alpha_version]}" "allow-alpha-version" || app_args[allow_alpha_version]=false
app_args[build_mode]=$(toml_get "$t" build-mode) && {
if ! isoneof "${app_args[build_mode]}" both apk module; then
abort "ERROR: '${app_args[build_mode]}' is not a valid option for '${table_name}': only 'both', 'apk' or 'module' is allowed"
abort "ERROR: build-mode '${app_args[build_mode]}' is not a valid option for '${table_name}': only 'both', 'apk' or 'module' is allowed"
fi
} || app_args[build_mode]=apk
app_args[uptodown_dlurl]=$(toml_get "$t" uptodown-dlurl) && {
Expand All @@ -79,7 +83,7 @@ for table_name in $(toml_get_table_names); do
fi
app_args[arch]=$(toml_get "$t" arch) && {
if ! isoneof "${app_args[arch]}" all arm64-v8a arm-v7a; then
abort "ERROR: '${app_args[arch]}' is not a valid option for 'arch': only 'all', 'arm64-v8a', 'arm-v7a' is allowed"
abort "ERROR: arch '${app_args[arch]}' is not a valid option for '${table_name}': only 'all', 'arm64-v8a', 'arm-v7a' is allowed"
fi
} || app_args[arch]="all"
app_args[module_prop_name]=$(toml_get "$t" module-prop-name) || {
Expand Down
2 changes: 1 addition & 1 deletion mindetach-magisk
13 changes: 8 additions & 5 deletions scripts/customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
ui_print ""

if [ $ARCH = "arm" ]; then
alias cmpr='$MODPATH/bin/arm/cmpr'
#arm
ARCH_LIB=armeabi-v7a
elif [ $ARCH = "arm64" ] || [ $ARCH = "x64" ]; then
alias cmpr='$MODPATH/bin/arm/cmpr'
elif [ $ARCH = "arm64" ]; then
#arm64
ARCH_LIB=arm64-v8a
alias cmpr='$MODPATH/bin/arm64/cmpr'
else
abort "ERROR: unsupported arch: ${ARCH}"
fi
set_perm_recursive $MODPATH/bin 0 0 0755 0777

grep __PKGNAME /proc/self/mountinfo | while read -r line; do
grep __PKGNAME /proc/mounts | while read -r line; do
ui_print "- Un-mount"
mountpoint=$(echo "$line" | cut -d' ' -f5)
umount -l "${mountpoint%%\\*}"
mp=${line#* }
mp=${mp%% *}
umount -l ${mp%%\\*}
done
am force-stop __PKGNAME

Expand Down
37 changes: 21 additions & 16 deletions scripts/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
MODDIR=${0%/*}
RVPATH=/data/adb/rvhc/__PKGNAME_rv.apk
until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done
timeout 15 logcat -T1 -m1 -e HOME ActivityManager:I
until [ "$(getprop init.svc.bootanim)" = stopped ]; do sleep 1; done
sleep 3

err() {
cp -n $MODDIR/module.prop $MODDIR/err
Expand All @@ -12,24 +13,28 @@ err() {

BASEPATH=$(pm path __PKGNAME | grep base)
BASEPATH=${BASEPATH#*:}
if [ $BASEPATH ] && [ -d ${BASEPATH%base.apk}lib ]; then
VERSION=$(dumpsys package __PKGNAME | grep -m1 versionName)
if [ ${VERSION#*=} = __PKGVER ]; then
grep __PKGNAME /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
am force-stop __PKGNAME
mv -f $MODDIR/err $MODDIR/module.prop 2>/dev/null
if [ $BASEPATH ]; then
if [ -d ${BASEPATH%base.apk}lib ]; then
VERSION=$(dumpsys package __PKGNAME | grep -m1 versionName)
if [ ${VERSION#*=} = __PKGVER ]; then
grep __PKGNAME /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
am force-stop __PKGNAME
[ -f $MODDIR/err ] && mv -f $MODDIR/err $MODDIR/module.prop
else
err "mount failed"
fi
else
err "APK was not found"
err "version mismatch (${VERSION#*=})"
fi
else
err "Version mismatch (${VERSION#*=})"
err "invalid installation"
fi
else
err "Invalid installation"
err "app not installed"
fi
42 changes: 29 additions & 13 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,27 @@ pr() { echo -e "\033[0;32m[+] ${1}\033[0m"; }

get_prebuilts() {
pr "Getting prebuilts"
local rv_cli_url rv_integrations_url rv_patches rv_patches_changelog rv_patches_dl rv_patches_url
local rv_cli_url rv_integrations_url rv_patches rv_patches_changelog rv_patches_dl rv_patches_url rv_integrations_rel rv_patches_rel
rv_cli_url=$(gh_req "https://api.github.com/repos/j-hc/revanced-cli/releases/latest" - | json_get 'browser_download_url') || return 1
RV_CLI_JAR="${PREBUILTS_DIR}/${rv_cli_url##*/}"
log "CLI: ${rv_cli_url##*/}"

rv_integrations_url=$(gh_req "https://api.github.com/repos/${INTEGRATIONS_SRC}/releases/latest" - | json_get 'browser_download_url')
if [ "$CONF_INTEGRATIONS_VER" ]; then
rv_integrations_rel="https://api.github.com/repos/${INTEGRATIONS_SRC}/releases/tags/${CONF_INTEGRATIONS_VER}"
else
rv_integrations_rel="https://api.github.com/repos/${INTEGRATIONS_SRC}/releases/latest"
fi
if [ "$CONF_PATCHES_VER" ]; then
rv_patches_rel="https://api.github.com/repos/${PATCHES_SRC}/releases/tags/${CONF_PATCHES_VER}"
else
rv_patches_rel="https://api.github.com/repos/${PATCHES_SRC}/releases/latest"
fi

rv_integrations_url=$(gh_req "$rv_integrations_rel" - | json_get 'browser_download_url')
RV_INTEGRATIONS_APK="${PREBUILTS_DIR}/${rv_integrations_url##*/}"
log "Integrations: ${rv_integrations_url##*/}"

rv_patches=$(gh_req "https://api.github.com/repos/${PATCHES_SRC}/releases/latest" -)
rv_patches=$(gh_req "$rv_patches_rel" -)
rv_patches_changelog=$(echo "$rv_patches" | json_get 'body' | sed 's/\(\\n\)\+/\\n/g')
rv_patches_dl=$(json_get 'browser_download_url' <<<"$rv_patches")
RV_PATCHES_JSON="${PREBUILTS_DIR}/patches-$(json_get 'tag_name' <<<"$rv_patches").json"
Expand All @@ -68,9 +79,6 @@ get_prebuilts() {
if [ "$(uname -m)" = aarch64 ]; then arch=arm64; else arch=arm; fi
dl_if_dne ${TEMP_DIR}/aapt2 https://github.com/rendiix/termux-aapt/raw/main/prebuilt-binary/${arch}/aapt2
fi
}

get_cmpr() {
mkdir -p ${MODULE_TEMPLATE_DIR}/bin/arm64 ${MODULE_TEMPLATE_DIR}/bin/arm
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"
Expand Down Expand Up @@ -156,13 +164,14 @@ dl_apkmirror() {
}
get_apkmirror_vers() {
local apkmirror_category=$1 allow_alpha_version=$2
local vers
local vers apkm_resp
apkm_resp=$(req "https://www.apkmirror.com/uploads/?appcategory=${apkmirror_category}" -)
# apkm_name=$(echo "$apkm_resp" | sed -n 's;.*Latest \(.*\) Uploads.*;\1;p')
vers=$(sed -n 's;.*Version:</span><span class="infoSlide-value">\(.*\) </span>.*;\1;p' <<<"$apkm_resp")
if [ "$allow_alpha_version" = false ]; then
local IFS=$'\n'
vers=$(grep -iv "\(beta\|alpha\)" <<<"$vers")
local v
local r_vers=()
for v in $vers; do
grep -iq "${v} \(beta\|alpha\)" <<<"$apkm_resp" || r_vers+=("$v")
Expand All @@ -177,11 +186,12 @@ get_apkmirror_pkg_name() { req "$1" - | sed -n 's;.*id=\(.*\)" class="accent_col

# -------------------- uptodown --------------------
get_uptodown_resp() { req "${1}/versions" -; }
get_uptodown_vers() { sed -n 's;\(^.*\) <span>.*</span>.*;\1;p' <<<"$1"; }
get_uptodown_vers() { sed -n 's;.*version>\(.*\)<\/span>$;\1;p' <<<"$1"; }
dl_uptodown() {
local uptwod_resp=$1 version=$2 output=$3
url=$(echo "$uptwod_resp" | grep "${version} <span>" -B 1 | head -1 | sed -n 's;.*data-url="\(.*\)".*;\1;p')
url=$(req "$url" - | sed -n 's;.*data-url="\(.*\)".*;\1;p')
local url
url=$(echo "$uptwod_resp" | grep "${version}<\/span>" -B 2 | head -1 | sed -n 's;.*data-url="\(.*\)".*;\1;p') || return 1
url=$(req "$url" - | sed -n 's;.*data-url="\(.*\)".*;\1;p') || return 1
req "$url" "$output"
}
get_uptodown_pkg_name() {
Expand Down Expand Up @@ -305,7 +315,7 @@ build_rv() {
build_mode_arr=(apk module)
fi

local patcher_args patched_apk
local patcher_args patched_apk build_mode
for build_mode in "${build_mode_arr[@]}"; do
patcher_args=("${p_patcher_args[@]}")
pr "Building '${app_name}' (${arch}) in '$build_mode' mode"
Expand Down Expand Up @@ -346,7 +356,7 @@ build_rv() {

uninstall_sh "$pkg_name" "$base_template"
service_sh "$pkg_name" "$version" "$base_template"
customize_sh "$pkg_name" "$version" "$base_template"
customize_sh "$pkg_name" "$version" "$arch" "$base_template"
module_prop \
"${args[module_prop_name]}" \
"${app_name} ${RV_BRAND}" \
Expand All @@ -371,7 +381,13 @@ join_args() {
uninstall_sh() { echo "${UNINSTALL_SH//__PKGNAME/$1}" >"${2}/uninstall.sh"; }
customize_sh() {
local s="${CUSTOMIZE_SH//__PKGNAME/$1}"
echo "${s//__PKGVER/$2}" >"${3}/customize.sh"
# shellcheck disable=SC2016,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"
}
service_sh() {
local s="${SERVICE_SH//__PKGNAME/$1}"
Expand Down

0 comments on commit c028b5a

Please sign in to comment.