Files
baji-vc/scripts/package-release.sh
T

47 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# Ordinary workspace shell: normal build entry, true package/signature checks, archive + HTTP check.
set -euo pipefail
cd "$(dirname "$0")/.."
./scripts/build.sh
source /home/ubuntu/android-build/env.sh
TOOLS=/home/ubuntu/android-build/sdk/build-tools/34.0.0
APK=app/build/outputs/apk/debug/app-debug.apk
mkdir -p logs/voice-investigation artifacts
"$TOOLS/aapt" dump badging "$APK" > logs/voice-investigation/release-badging.txt
"$TOOLS/apksigner" verify --verbose --print-certs "$APK" > logs/voice-investigation/release-signature.txt
python3 - <<'PY'
import hashlib,json,re,shutil,urllib.request,subprocess
from pathlib import Path
root=Path.cwd()
badging=(root/'logs/voice-investigation/release-badging.txt').read_text()
assert "name='com.gorios.lanvoice'" in badging
assert "versionCode='7'" in badging and "versionName='0.4.0'" in badging
native=re.search(r'^native-code: (.+)$',badging,re.M)
assert native and native[1].strip()=="'arm64-v8a'", 'unexpected ABI'
source=root/'app/build/outputs/apk/debug/app-debug.apk'
previous=root/'artifacts/lan-voice-v033-arm64-debug.apk'
if previous.exists():
old=subprocess.check_output(['/home/ubuntu/android-build/sdk/build-tools/34.0.0/apksigner','verify','--print-certs',str(previous)],text=True)
new=(root/'logs/voice-investigation/release-signature.txt').read_text()
pattern=r'Signer #1 certificate SHA-256 digest: (\w+)'
assert re.search(pattern,old)[1]==re.search(pattern,new)[1], 'signing certificate changed: update install would fail'
artifact=root/'artifacts/lan-voice-v040-arm64-debug.apk'
shutil.copy2(source,artifact)
digest=hashlib.sha256(artifact.read_bytes()).hexdigest()
artifact.with_suffix('.apk.sha256').write_text(f'{digest} {artifact.name}\n')
# Existing HTTP server root can be the workspace or artifacts; check the actual bytes.
base='http://192.168.31.124:8080/'
opener=urllib.request.build_opener(urllib.request.ProxyHandler({}))
url=None
for path in ('artifacts/'+artifact.name, artifact.name):
try:
with opener.open(base+path,timeout=15) as response:
downloaded=hashlib.sha256(response.read()).hexdigest()
if downloaded==digest: url=base+path;break
except Exception: pass
assert url is not None, 'APK built, but existing HTTP server did not serve matching bytes'
result=dict(version_name='0.4.0',version_code=7,apk=str(artifact.relative_to(root)),bytes=artifact.stat().st_size,sha256=digest,url=url,signature='apksigner_verified',real_phone_playback='not_tested')
(root/'logs/voice-investigation/release.json').write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps(result,indent=2))
PY