DivestOS/Container/phase-2.sh

58 lines
1.6 KiB
Bash
Raw Normal View History

Container: Scripted builds I had a hard time following the [Build Guide](https://divestos.org/pages/build) and IMO a script does a much better job of removing the ambiguity and is more likely to be updated if it fails. Per https://github.com/Divested-Mobile/DivestOS-Website/issues/40 I think this script, as documentation, makes it much more clear what it means to "color in the lines" and suggests an efficient way of doing so. I'd like to update the Build Guide too, but I wanted to get your feedback on some of this first. The main thing I'm not thrilled with is that the workspace needs to be patched and reset twice (if I understand correctly). I got this notion from your guidance on a Reddit post a couple months back which I can't find now that Reddit seems to have taken down your content. Unfortunately I don't recall the details but the basic issue is that generating the signing keys was giving an error and the solution was to patch the workspace. But one of the workspace patching "phases" is to copy the keys to the kernel and this fails if the keys don't exist yet. So it's not clear how to get around doing this step twice. A couple notes on future work: - How to do incremental updates? There's no story on this yet and I haven't looked into it. - I found a wealth of information on building android in docker in this repository: https://github.com/lineageos4microg/docker-lineage-cicd. It might be worth considering trying to integrate DivestOS into that project or building on top of their image.
2024-07-26 21:30:33 +00:00
#!/usr/bin/env bash
set -exo pipefail
version="$1" # (e.g. "20.0")
device="$2" # (e.g. "sailfish")
if [ "$2" = "" ]; then
echo "Missing arguments"
exit 1
fi
cd "DivestOS/Build/LineageOS-$version"
# Download
repo init -u https://github.com/LineageOS/android.git -b "lineage-$version" --git-lfs
repo forall --ignore-missing -vc "git reset --hard"
repo sync --fail-fast
# Prepare workspace
if [ "$(echo "$version < 20.0" | bc -l)" = 1 ]; then
virtualenv venv --python=python2
fi
source ../../Scripts/init.sh
# Patch Workspace so keys can be generated.
resetWorkspace
rm -rf packages/apps/Fennec_DOS-Shim/ vendor/divested/ vendor/fdroid_prebuilt/ packages/apps/SupportDivestOS/
rm -rf out
patchWorkspace
# Generate signing keys
if [ "$(echo "$version > 20.0" | bc -l)" = 1 ]; then
awk -i inplace '!/enforce-product-packages-exist-internal/' vendor/lineage/config/common.mk
fi
source build/envsetup.sh
breakfast "lineage_$device-user"
make -j20 generate_verity_key
sh "$DOS_WORKSPACE_ROOT/Scripts/Generate_Signing_Keys.sh" "$device"
mv -nv "$DOS_SIGNING_KEYS/NEW/"* "$DOS_SIGNING_KEYS/"
# Patch Workspace
resetWorkspace
rm -rf packages/apps/Fennec_DOS-Shim/ vendor/divested/ vendor/fdroid_prebuilt/ packages/apps/SupportDivestOS/
rm -rf out
successpattern="\[SCRIPT COMPLETE\]"
successes=$(patchWorkspace |& tee /dev/stderr | grep -c "$successpattern")
# Verify the changes applied
expected=$(grep -c "$successpattern" "$DOS_WORKSPACE_ROOT/Logs/patchWorkspace-LineageOS-$version.log")
if [ "$successes" != "$expected" ]; then
echo "Expected $expected '[SCRIPT COMPLETE]' lines but only found $successes."
exit 1
fi
# Build
buildDevice "$device"