From e87ee9c5b8b2d735aba56873e144e7a94aeea043 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 19 Oct 2024 06:35:25 +0200 Subject: [PATCH] chore: Add click-to-run scripts --- .gitignore | 5 +++- docs/0_prerequisites.md | 2 +- scripts/1-setup-environment.bat | 29 ++++++++++++++++++ scripts/2-download.bat | 11 +++++++ scripts/3-patch.bat | 14 +++++++++ scripts/4-cleanup.bat | 11 +++++++ scripts/README.md | 8 +++++ scripts/customize.bat | 1 + scripts/modules/check-java.bat | 12 ++++++++ scripts/modules/composite.bat | 51 ++++++++++++++++++++++++++++++++ scripts/modules/create.bat | 19 ++++++++++++ scripts/modules/delete.bat | 20 +++++++++++++ scripts/modules/download.bat | 30 +++++++++++++++++++ scripts/modules/env.bat | 6 ++++ scripts/modules/install-java.bat | 1 + scripts/modules/install-jq.bat | 1 + scripts/modules/install.bat | 14 +++++++++ scripts/modules/patch.bat | 28 ++++++++++++++++++ scripts/modules/run.bat | 23 ++++++++++++++ 19 files changed, 284 insertions(+), 2 deletions(-) create mode 100644 scripts/1-setup-environment.bat create mode 100644 scripts/2-download.bat create mode 100644 scripts/3-patch.bat create mode 100644 scripts/4-cleanup.bat create mode 100644 scripts/README.md create mode 100644 scripts/customize.bat create mode 100644 scripts/modules/check-java.bat create mode 100644 scripts/modules/composite.bat create mode 100644 scripts/modules/create.bat create mode 100644 scripts/modules/delete.bat create mode 100644 scripts/modules/download.bat create mode 100644 scripts/modules/env.bat create mode 100644 scripts/modules/install-java.bat create mode 100644 scripts/modules/install-jq.bat create mode 100644 scripts/modules/install.bat create mode 100644 scripts/modules/patch.bat create mode 100644 scripts/modules/run.bat diff --git a/.gitignore b/.gitignore index a1c73c7..88fa361 100644 --- a/.gitignore +++ b/.gitignore @@ -122,4 +122,7 @@ revanced-cache/ options.toml # Generated by Android projects -local.properties \ No newline at end of file +local.properties + +# Generated by scripts +scripts/workspace \ No newline at end of file diff --git a/docs/0_prerequisites.md b/docs/0_prerequisites.md index c3f5746..7648b3e 100644 --- a/docs/0_prerequisites.md +++ b/docs/0_prerequisites.md @@ -4,7 +4,7 @@ To use ReVanced CLI, you will need to fulfill specific requirements. ## 🤝 Requirements -- Java Runtime Environment 11 ([Azul Zulu JRE](https://www.azul.com/downloads/?version=java-11-lts&package=jre#zulu) or [OpenJDK](https://jdk.java.net/archive/)) +- Java Runtime Environment 11 or higher ([Eclipse Temurin JRE](https://adoptium.net/temurin/releases/?package=jre) or [OpenJDK](https://jdk.java.net/archive/)) - [Android Debug Bridge (ADB)](https://developer.android.com/studio/command-line/adb) if you want to install the patched APK file on your device - x86 or x86-64 (For [other architectures](https://github.com/ReVanced/revanced-manager/tree/main/android/app/src/main/jniLibs) use the `--custom-aapt2-binary` option) diff --git a/scripts/1-setup-environment.bat b/scripts/1-setup-environment.bat new file mode 100644 index 0000000..8253bb6 --- /dev/null +++ b/scripts/1-setup-environment.bat @@ -0,0 +1,29 @@ +@echo off + +echo Check, if OpenJDK/ Eclipse Temurin 11 or newer is installed. +pause +echo: + +cd modules +call run java -version +cd .. + +echo: +set /P INSTALLED_JAVA=Can you see OpenJDK/ Eclipse Temurin 11 or newer? (y/n) + +if "%INSTALLED_JAVA%"=="y" ( + echo The environment is set up. + pause + exit +) + +cls +echo Install Eclipse Temurin JRE 21. +pause + +cd modules +call install-java +cd .. + +echo The environment is set up. Rerun this script to check your environment. +pause diff --git a/scripts/2-download.bat b/scripts/2-download.bat new file mode 100644 index 0000000..52fd177 --- /dev/null +++ b/scripts/2-download.bat @@ -0,0 +1,11 @@ +@echo off + +echo Download necessary files from GitHub. +pause + +cd modules +call composite download %~dp0\workspace +cd .. + +echo Files downloaded. +pause diff --git a/scripts/3-patch.bat b/scripts/3-patch.bat new file mode 100644 index 0000000..e3dcc5f --- /dev/null +++ b/scripts/3-patch.bat @@ -0,0 +1,14 @@ +@echo off +setlocal + +echo Patch an APK with the patches in the workspace. +pause + +cd modules +call composite patch %~dp0\workspace +cd .. + +mv %~dp0\workspace\patched.apk %~dp0\patched.apk + +echo Patched APK saved at %~dp0\patched.apk. +pause diff --git a/scripts/4-cleanup.bat b/scripts/4-cleanup.bat new file mode 100644 index 0000000..978d590 --- /dev/null +++ b/scripts/4-cleanup.bat @@ -0,0 +1,11 @@ +@echo off + +echo Clean the workspace. +pause + +cd modules +call composite clean %~dp0\workspace +cd .. + +echo Cleaned workspace. +pause diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..f9f46ed --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,8 @@ +# 📜 Scripts + +This directory contain click-to-run scripts to use ReVanced CLI. + +## Prerequisites + +- [cURL](https://curl.haxx.se/) +- [WinGet](https://aka.ms/getwinget), if you are on Windows diff --git a/scripts/customize.bat b/scripts/customize.bat new file mode 100644 index 0000000..eaa7e85 --- /dev/null +++ b/scripts/customize.bat @@ -0,0 +1 @@ +notepad modules\env.bat \ No newline at end of file diff --git a/scripts/modules/check-java.bat b/scripts/modules/check-java.bat new file mode 100644 index 0000000..46becdf --- /dev/null +++ b/scripts/modules/check-java.bat @@ -0,0 +1,12 @@ +@echo off +setlocal + +for /f "tokens=8 delims=. " %%a in ('java --version 2^>nul ^| findstr /r "build"') do ( + set JAVA_VERSION_MAJOR=%%a + goto :break +) +:break + +if %JAVA_VERSION_MAJOR% LSS 11 ( + echo It looks like Java version is less than 11. Install OpenJDK/ Eclipse Temurin 11 or newer. +) diff --git a/scripts/modules/composite.bat b/scripts/modules/composite.bat new file mode 100644 index 0000000..fa41688 --- /dev/null +++ b/scripts/modules/composite.bat @@ -0,0 +1,51 @@ +@echo off +setlocal EnableDelayedExpansion + +if "%~1"=="" ( + set INVALID_ARGS=true +) +if "%~2"=="" ( + set INVALID_ARGS=true +) +if defined INVALID_ARGS ( + echo Runs curated compositions of scripts. + echo: + echo Usage: composite ^ ^ + echo Example: composite patch C:/revanced + echo: + echo Available commands: + echo: download - Download files + echo: patch - Patches an application + echo: clean - Cleans the workspace + echo: env - Check for a valid environment setup + exit /b 1 +) + +call env + +set WORKSPACE=%2 + +if "%~1"=="download" ( + call create %WORKSPACE% + + if not exist %WORKSPACE%/revanced-cli.jar ( + echo Downloading ReVanced CLI... + call download %CLI_REPO% jar %WORKSPACE%/revanced-cli.jar + ) + + if not exist %WORKSPACE%/patches.rvp ( + echo Downloading ReVanced patches... + call download %PATCHES_REPO% jar %WORKSPACE%/patches.rvp + ) +) +if "%~1"=="patch" ( + set /p APK="Path to the APK file: " + + call patch !APK! %WORKSPACE% +) +if "%~1"=="clean" ( + call delete %WORKSPACE% +) +if "%~1"=="env" ( + call check-java +) diff --git a/scripts/modules/create.bat b/scripts/modules/create.bat new file mode 100644 index 0000000..ebfe25e --- /dev/null +++ b/scripts/modules/create.bat @@ -0,0 +1,19 @@ +@echo off +setlocal + +if "%~1"=="" ( + set INVALID_ARGS=true +) +if defined INVALID_ARGS ( + echo Creates a directory using the mkdir command. + echo: + echo Usage: create ^ + echo Example: create C:/revanced + exit /b 1 +) + +set DIRECTORY=%1 + +if not exist %DIRECTORY% ( + run "mkdir.exe" -p %DIRECTORY% +) diff --git a/scripts/modules/delete.bat b/scripts/modules/delete.bat new file mode 100644 index 0000000..d5d9cbb --- /dev/null +++ b/scripts/modules/delete.bat @@ -0,0 +1,20 @@ +@echo off +setlocal + +if "%~1"=="" ( + set INVALID_ARGS=true +) +if defined INVALID_ARGS ( + echo Deletes a directory relative to the current directory using the rmdir command. + echo: + echo Usage: delete ^ + echo Example: delete C:/revanced + exit /b 1 +) + +set DIRECTORY=%1 + +if exist %DIRECTORY% ( + echo Confirm deletion of + run rmdir /s %DIRECTORY% +) diff --git a/scripts/modules/download.bat b/scripts/modules/download.bat new file mode 100644 index 0000000..8b86205 --- /dev/null +++ b/scripts/modules/download.bat @@ -0,0 +1,30 @@ +@echo off +setlocal + +if "%~1"=="" ( + set INVALID_ARGS=true +) +if "%~2"=="" ( + set INVALID_ARGS=true +) +if "%~3"=="" ( + set INVALID_ARGS=true +) +if defined INVALID_ARGS ( + echo Downloads a file from a GitHub repository release. + echo: + echo Usage: download ^ ^ ^ + echo Example: download revanced/revanced-cli jar C:/revanced/revanced-cli.jar + exit /b 1 +) + +set REPO=%1 +set ASSET_EXTENSION=%2 +set OUT=%3 + +set URL=https://api.github.com/repos/%REPO%/releases/latest +for /f "delims=" %%i in ('curl -s %URL% ^| jq -r ".assets[] | select(.name | endswith(\"%ASSET_EXTENSION%\")) | .browser_download_url"') do ( + set JAR_URL=%%i +) + +run curl --silent --location --output %OUT% %JAR_URL% diff --git a/scripts/modules/env.bat b/scripts/modules/env.bat new file mode 100644 index 0000000..dbcd67c --- /dev/null +++ b/scripts/modules/env.bat @@ -0,0 +1,6 @@ +@echo off + +:: Customize your environment. + +set CLI_REPO=revanced/revanced-cli +set PATCHES_REPO=revanced/revanced-patches diff --git a/scripts/modules/install-java.bat b/scripts/modules/install-java.bat new file mode 100644 index 0000000..b0d7aac --- /dev/null +++ b/scripts/modules/install-java.bat @@ -0,0 +1 @@ +run install EclipseAdoptium.Temurin.21.JRE diff --git a/scripts/modules/install-jq.bat b/scripts/modules/install-jq.bat new file mode 100644 index 0000000..dcb6eae --- /dev/null +++ b/scripts/modules/install-jq.bat @@ -0,0 +1 @@ +run install jqlang.jq diff --git a/scripts/modules/install.bat b/scripts/modules/install.bat new file mode 100644 index 0000000..12aa705 --- /dev/null +++ b/scripts/modules/install.bat @@ -0,0 +1,14 @@ +@echo off + +if "%~1"=="" ( + set INVALID_ARGS=true +) +if defined INVALID_ARGS ( + echo Installs a package using winget. + echo: + echo Usage: install ^ + echo Example: install jqlang.jq + exit /b 1 +) + +run winget install -e --id=%1 diff --git a/scripts/modules/patch.bat b/scripts/modules/patch.bat new file mode 100644 index 0000000..30de7ac --- /dev/null +++ b/scripts/modules/patch.bat @@ -0,0 +1,28 @@ +@echo off +setlocal + +if "%~1"=="" ( + set INVALID_ARGS=true +) +if "%~2"=="" ( + set INVALID_ARGS=true +) +if defined INVALID_ARGS ( + echo Patches an application using the specified patches. + echo: + echo Usage: patch ^ ^ + echo Example: patch C:/app.apk C:/workspace + exit /b 1 +) + +set APK=%1 +set WORKSPACE=%2 + +call run java -jar %WORKSPACE%/revanced-cli.jar patch ^ + --patch-bundle %WORKSPACE%/patches.rvp ^ + --temporary-files-path %WORKSPACE%/temporary-files ^ + --out %WORKSPACE%/patched.apk ^ + --purge ^ + %APK% + +mv %WORKSPACE%/patched.apk diff --git a/scripts/modules/run.bat b/scripts/modules/run.bat new file mode 100644 index 0000000..fa3bf48 --- /dev/null +++ b/scripts/modules/run.bat @@ -0,0 +1,23 @@ +@echo off + +if "%~1"=="" ( + set INVALID_ARGS=true +) +if defined INVALID_ARGS ( + echo Run a command with arguments. + echo: + echo Usage: run.bat ^ [arguments] + echo Example: run.bat echo Hello, World! + exit /b 1 +) + +%* + +if %ERRORLEVEL% NEQ 0 ( + echo: + echo Failed to run command with exit code %ERRORLEVEL%. + echo Failed command: %* + echo: + pause + exit /b %ERRORLEVEL% +)