From bb27dc8dc19951389080c498a51bb2c552fc2010 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Thu, 10 Dec 2020 22:59:25 +0100 Subject: [PATCH] Initial commit --- .gitignore | 2 + README.md | 6 ++ build_android.sh | 115 +++++++++++++++++++++++++++++ ovh_orchestrator/__init__.py | 110 +++++++++++++++++++++++++++ ovh_orchestrator/config.example.py | 18 +++++ requirements.txt | 1 + run.sh | 32 ++++++++ 7 files changed, 284 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 build_android.sh create mode 100644 ovh_orchestrator/__init__.py create mode 100644 ovh_orchestrator/config.example.py create mode 100644 requirements.txt create mode 100755 run.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7acdc0a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +ovh_orchestrator/config.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc6e7c2 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +Building Android (Lineage 17.1 / `/e/`) for LG G6 (h870) +======================================================== + +Lots of RAM (12GB is short!) / good CPU required! + + diff --git a/build_android.sh b/build_android.sh new file mode 100755 index 0000000..0f2056e --- /dev/null +++ b/build_android.sh @@ -0,0 +1,115 @@ +#!/bin/bash +# Ubuntu 20.04 base +set -e +set -x + +# Install dependencies +apt-get update +apt-get upgrade -y +apt-get install -y bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev +apt-get install -y default-jdk +apt-get install -y python2 +update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 # Android git repo hooks are python2-only + +# Install repo +mkdir ~/bin +cat >> ~/.profile < ~/bin/repo +chmod a+x ~/bin/repo + +# Git config +git config --global user.email "phyks@phyks.me" +git config --global user.name "Phyks (Lucas Verney)" + +# Use ccache +cat >> ~/.bashrc < ~/android/lineage/.repo/local_manifests/roomservice.xml < + + + + + + +EOF +repo sync + +# Some h870 cherry picks +croot +cd frameworks/base/ +git remote add fixes https://github.com/BernardoBas/android_frameworks_base.git +git fetch fixes +# Phantom camera fixes +git cherry-pick a904a84ad485d8768c7a523ec380696d573c9a9e 5a02ae0abfb2a341055aecbb46fb6ce3b24070cf +# Sunrise/Sunset hardoded if location is not available +git cherry-pick 2c9baf509fef40586cc07a8b3aed91bb3cc741b3 +croot +cd device/lge/msm8996-common/ +git remote add brightness https://github.com/BernardoBas/android_device_lge_msm8996-common.git +git fetch brightness +# MIC LEVEL -- TODO +git cherry-pick 9123565f56262e73dc6d613a0efc4bfb5867f5e6 +# ROUNDED CORNERS -- TODO +git cherry-pick 5c490db56b5d2431bc21a35f865511a3ea86ca4a + + +# If you want micro-g on Lineage, uncomment this part +# Note: micro-g is already built-in with /e/ +# if [[ "${BUILD_FLAVOR}" == "lineage" ]]; then +# croot +# cd frameworks/base +# curl https://raw.githubusercontent.com/lineageos4microg/docker-lineage-cicd/master/src/signature_spoofing_patches/android_frameworks_base-Q.patch > android_frameworks_base-Q.patch +# patch -p1 -i android_frameworks_base-Q.patch +# fi + +if [[ "${BUILD_FLAVOR}" == "e" ]]; then + # Remove some apps built with /e/, comment if you want to keep them + croot + # Remove MagicEarth (non-free) + rm -r prebuilts/prebuiltapks/MagicEarth + # Remove DemoApp + rm -r prebuilts/prebuiltapks/DemoApp + # Remove DroidGuard + rm -r prebuilts/prebuiltapks/DroidGuard + # Remove eDrive + rm -r prebuilts/prebuiltapks/eDrive + # Remove ESmsSync + rm -r prebuilts/prebuiltapks/ESmsSync + # Remove ESmsSync + rm -r prebuilts/prebuiltapks/ESmsSync +fi + +# Build Lineage or /e/ (takes 2 to 3 hours!) +croot +make clean +date | tee build.log; brunch h870 | tee build.log; date | tee build.log +touch ~/BUILD_DONE diff --git a/ovh_orchestrator/__init__.py b/ovh_orchestrator/__init__.py new file mode 100644 index 0000000..3253c32 --- /dev/null +++ b/ovh_orchestrator/__init__.py @@ -0,0 +1,110 @@ +import uuid +import sys +import time + +import ovh + +from . import config + + +if __name__ == '__main__': + client = ovh.Client( + endpoint=config.ovh_endpoint, + application_key=config.ovh_application_key, + application_secret=config.ovh_application_secret, + consumer_key=config.ovh_consumer_key, + ) + + if len(sys.argv) < 2: + sys.exit(1) + + # Create VM + if sys.argv[1] == 'init': + # Get image id + result = client.get( + '/cloud/project/' + config.ovh_public_cloud_project + '/image', + flavorType='s1-2', + osType='linux', + region=config.ovh_public_cloud_region, + ) + image_id = next( + x['id'] + for x in result + if x['name'] == config.ovh_public_cloud_image + ) + + # Get SSH key id + result = client.get( + '/cloud/project/' + config.ovh_public_cloud_project + '/sshkey', + region=config.ovh_public_cloud_region, + ) + ssh_key_id = next( + x['id'] + for x in result + if x['name'] == config.ovh_public_cloud_sshkey_name + ) + + # Get flavor id + result = client.get( + '/cloud/project/' + config.ovh_public_cloud_project + '/flavor', + region=config.ovh_public_cloud_region, + ) + flavor_id = next( + x['id'] + for x in result + if x['name'] == 's1-2' + ) + + # Create instance + name = str(uuid.uuid4()) + result = client.post( + '/cloud/project/' + config.ovh_public_cloud_project + '/instance', + flavorId=flavor_id, + imageId=image_id, + monthlyBilling=False, + name=name, + region=config.ovh_public_cloud_region, + sshKeyId=ssh_key_id + ) + + if 'id' not in result: + sys.exit(1) + + # Wait for IP address + while True: + result = client.get( + '/cloud/project/' + config.ovh_public_cloud_project + '/instance', + region=config.ovh_public_cloud_region, + ) + ipAddresses = next( + x['ipAddresses'] + for x in result + if x['name'] == name + ) + if ipAddresses: + print(ipAddresses[0]) + sys.exit(0) + time.sleep(30) + # Clear VM + elif sys.argv[1] == 'purge': + if len(sys.argv) < 3: + sys.exit(1) + + # Get instance id from its IP address + result = client.get( + '/cloud/project/' + config.ovh_public_cloud_project + '/instance', + region=config.ovh_public_cloud_region, + ) + instance_id = next( + x['id'] + for x in result + if sys.argv[2] in x['ipAddresses'] + ) + + # Delete instance + client.delete( + '/cloud/project/' + config.ovh_public_cloud_project + + '/instance/' + instance_id + ) + else: + sys.exit(1) diff --git a/ovh_orchestrator/config.example.py b/ovh_orchestrator/config.example.py new file mode 100644 index 0000000..497a107 --- /dev/null +++ b/ovh_orchestrator/config.example.py @@ -0,0 +1,18 @@ +# Create API credentials at https://eu.api.ovh.com/createToken/ +# See https://docs.ovh.com/fr/api/api-premiers-pas/#prerequis +ovh_endpoint = 'ovh-eu' +ovh_application_key = 'xxxxxxx' +ovh_application_secret = 'xxxxxxx' +ovh_consumer_key = 'xxxxxxx' + +# Fill with ID of your public cloud project, found in the manager URI +ovh_public_cloud_project = 'xxxxxxx' + +ovh_public_cloud_region = 'SBG5' + +# Fill with the name of your SSH key +ovh_public_cloud_sshkey_name = 'xxx' + +# These are tailored for Android builds at reasonable speed / cost +ovh_public_cloud_image = 'Ubuntu 20.04' +ovh_public_cloud_flavor = 'b2-30' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8f1a72d --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +ovh diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..6c9b8db --- /dev/null +++ b/run.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -e + +# Install OVH orchestrator dependencies +python3 -m venv .venv +./.venv/bin/pip install -r requirements.txt + +# Set up an OVH instance to run the build +printf "%s" "Waiting for OVH instance ..." +IP_ADDRESS=$(./.venv/bin/python3 -m ovh_orchestrator init) +while ! timeout 0.2 ping -c 1 -n ${IP_ADDRESS} &> /dev/null +do + printf "%c" "." +done + +# Run the build on the OVH instance +scp ./build_android.sh ubuntu@${IP_ADDRESS}:~ +ssh -f ubuntu@${IP_ADDRESS} 'screen -S build -dm bash ./build_android.sh' + +# Wait for build to complete +set +e +printf "%s" "Building ..." +until ssh ubuntu@${IP_ADDRESS} 'ls ~/BUILD_DONE'; do + printf "%c" "." +done +set -e + +# Fetch back the built images +rsync -azr --progress ubuntu@${IP_ADDRESS}:~/android/lineage/out/target/product/h870/\*.{zip,md5sum,img} . + +# Purge the OVH instance +./.venv/bin/python3 -m ovh_orchestrator purge ${IP_ADDRESS}