-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·113 lines (100 loc) · 5.95 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·113 lines (100 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/data/data/com.termux/files/usr/bin/bash
# ─────────────────────────────────────────────────────────────────────────────
# COPG — Termux build + package script
#
# Builds the Zygisk companion (.so) and the unified_controller for THIS device's
# ABI, assembles a flashable Magisk/KSU/APatch module ZIP, and drops it in
# /storage/emulated/0/Download/COPG
#
# Termux only. Installs any missing prerequisites (clang, zip, llvm) itself.
# Multi-ABI release builds are done by the json.yml CI; this script builds the
# single native ABI for fast on-device build-&-test.
#
# Usage: ./build.sh [version] [versionCode]
# e.g. ./build.sh 4.3.5 435
# ─────────────────────────────────────────────────────────────────────────────
set -euo pipefail
REPO="$(cd "$(dirname "$0")" && pwd)"
cd "$REPO"
VERSION="${1:-5.4.0}"
VERSION_CODE="${2:-540}"
OUT_DIR="/storage/emulated/0/Download/COPG"
BUILD_DIR="$REPO/.build"
STAGE="$BUILD_DIR/module"
c_info=$'\033[1;36m'; c_ok=$'\033[1;32m'; c_err=$'\033[1;31m'; c_off=$'\033[0m'
log(){ printf '%s▶ %s%s\n' "$c_info" "$*" "$c_off"; }
ok(){ printf '%s✓ %s%s\n' "$c_ok" "$*" "$c_off"; }
die(){ printf '%s✗ %s%s\n' "$c_err" "$*" "$c_off" >&2; exit 1; }
# ── prerequisites ────────────────────────────────────────────────────────────
need(){ # <command> <termux-package>
command -v "$1" >/dev/null 2>&1 && return 0
log "installing $2 …"
pkg install -y "$2" >/dev/null 2>&1 || die "could not install $2 (run: pkg update)"
}
log "checking prerequisites"
need clang++ clang
need zip zip
need llvm-strip llvm
UPX=""; command -v upx >/dev/null 2>&1 && UPX=1 # optional, only shrinks the binary
ls -d /storage/emulated/0 >/dev/null 2>&1 || die "no storage access — run: termux-setup-storage"
# ── detect device ABI ────────────────────────────────────────────────────────
case "$(uname -m)" in
aarch64) ABI=arm64-v8a; CTL=controller_arm64 ;;
armv7l|armv8l) ABI=armeabi-v7a; CTL=controller_armv7 ;;
x86_64) ABI=x86_64; CTL=controller_x86_64 ;;
*) die "unsupported host arch: $(uname -m)" ;;
esac
log "target ABI: $ABI version: $VERSION ($VERSION_CODE)"
# ── fresh staging ────────────────────────────────────────────────────────────
rm -rf "$BUILD_DIR"
mkdir -p "$STAGE/zygisk" "$STAGE/webroot"
# ── assemble static module files ─────────────────────────────────────────────
log "assembling module tree"
cp -r module/. "$STAGE/" # everything that ships at module root: customize/service/uninstall.sh,
# config.json, banner.png, CPU/ (cpuinfo profiles + manifest),
# common/, COPG.json, list.json, META-INF/
cp -r webroot/. "$STAGE/webroot/"
cat > "$STAGE/module.prop" <<EOF
id=COPG
name=✨ COPG SPOOF ✨
version=$VERSION
versionCode=$VERSION_CODE
author=AlirezaParsi
description=Spoof your device for games/apps to unlock new features.
support=https://t.me/theaosp
updateJson=https://raw.githubusercontent.com/AlirezaParsi/COPG/refs/heads/JSON/update.json
minMagisk=20.4
banner=banner.png
EOF
# ── build Zygisk companion (.so) ─────────────────────────────────────────────
# -static-libstdc++ is required for the TERMUX build only: Termux's clang links the
# .so against Termux's libc++_shared.so (a Termux-private path) which app processes
# can't resolve → Zygisk dlopen fails. The CI uses the NDK (c++_shared resolves on
# device) so it stays dynamic + smaller; this static build is just for local testing.
log "building zygisk companion ($ABI.so)"
clang++ -std=c++17 -shared -fPIC -static-libstdc++ -Os -flto -ffunction-sections -fdata-sections \
-Wl,--gc-sections -Wl,--exclude-libs,ALL \
-I src/include src/spoof_module.cpp src/atexit.cpp -llog \
-o "$STAGE/zygisk/$ABI.so"
llvm-strip --strip-unneeded "$STAGE/zygisk/$ABI.so"
ok "zygisk/$ABI.so ($(du -h "$STAGE/zygisk/$ABI.so" | cut -f1))"
# ── build unified_controller (libc++ bundled, libc from /system → ships fine) ─
log "building $CTL"
clang++ -std=c++17 -O3 -Os -fPIE -pie -static-libstdc++ \
-fdata-sections -ffunction-sections -Wl,--gc-sections \
-I src/include src/unified_controller.cpp -o "$STAGE/$CTL"
llvm-strip --strip-unneeded "$STAGE/$CTL"
[ -n "$UPX" ] && upx --best --lzma -q "$STAGE/$CTL" >/dev/null 2>&1 || true
ok "$CTL ($(du -h "$STAGE/$CTL" | cut -f1))"
# ── permissions ──────────────────────────────────────────────────────────────
chmod 0755 "$STAGE/customize.sh" "$STAGE/service.sh" "$STAGE/uninstall.sh" \
"$STAGE/META-INF/com/google/android/update-binary" \
"$STAGE/$CTL" "$STAGE/zygisk/$ABI.so" 2>/dev/null || true
chmod 0644 "$STAGE/COPG.json" "$STAGE/list.json" 2>/dev/null || true
# ── package ──────────────────────────────────────────────────────────────────
mkdir -p "$OUT_DIR"
ZIP="$OUT_DIR/COPG-v$VERSION-$ABI.zip"
rm -f "$ZIP"
( cd "$STAGE" && zip -r -q -X "$ZIP" . -x '.*' )
ok "packaged → $ZIP ($(du -h "$ZIP" | cut -f1))"
log "done"