Files
builders_rubenslte/build.sh
T
2026-09-13 23:01:28 +02:00

95 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
readonly ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT"
readonly BUILD="$ROOT/build-twrp"
readonly MANIFEST_URL="https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git"
readonly MANIFEST_BRANCH="twrp-5.1"
readonly RECOVERY_BUDGET=10485248
rlte_print() { printf '\033[34m[%s] %s\033[0m\n' "$0" "$*" ; }
rlte_error() { printf '\033[31m[%s] error: %s\033[0m\n' "$0" "$*" >&2 ; exit 1; }
rlte_ok() { printf '\033[32m[%s] ok: %s\033[0m\n' "$0" "$*" ; exit 0; }
usage() {
cat <<EOF
usage: $0 [-hn] [build|clean|prune]
flags:
-h show this help
-n don't sync
commands:
build build recovery.img (must be explicit)
clean remove "$BUILD"/out and recovery.img
prune remove all of "$BUILD" and recovery.img
EOF
}
do_build() {
mkdir -p "$BUILD"
cd "$BUILD"
if [ ! -d .repo ]; then
rlte_print "Setting up repo"
repo init --depth 1 -u "$MANIFEST_URL" -b "$MANIFEST_BRANCH"
mkdir -p .repo/local_manifests
cp "$ROOT/manifest.xml" .repo/local_manifests/
fi
if [ ! -v "NO_SYNC" ]; then
rlte_print "Syncing repositories"
repo sync -c -j"$(nproc)"
fi
rlte_print "Applying patches"
for p in "$ROOT"/*.patch; do
[ -e "$p" ] || continue
patch -p1 --forward --batch --dry-run < "$p" || continue
patch -p1 --batch < "$p"
done
export LC_ALL=C LANG=C LC_CTYPE=C TOP="$PWD"
set +u
source build/envsetup.sh
lunch omni_rubenslte-userdebug
set -u
rlte_print "Commencing TWRP build"
mka recoveryimage
if [ ! -f out/target/product/rubenslte/recovery.img ]; then
rlte_error "Build did not produce recovery.img"
exit 1
fi
cp out/target/product/rubenslte/recovery.img "$ROOT/recovery.img"
if [ "$(stat -c%s "$ROOT/recovery.img")" -gt "$RECOVERY_BUDGET" ]; then
rlte_error "$ROOT/recovery.img exceeds the recovery partition budget"
exit 1
fi
rlte_ok "Image at: $ROOT/recovery.img"
}
while getopts ":hn" opt; do
case "$opt" in
h) usage; exit 0 ;;
n) NO_SYNC=1 ;;
*) usage; exit 1 ;;
esac
done
shift $((OPTIND - 1))
case "${1:-}" in
build) do_build ;;
clean) rm -rf "$BUILD"/out recovery.img ;;
prune) rm -rf "$BUILD" recovery.img ;;
*) usage; exit 1 ;;
esac