Browse Source

Initial commit

Phyks (Lucas Verney) 4 months ago
commit
bb27dc8dc1
7 changed files with 284 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 6
    0
      README.md
  3. 115
    0
      build_android.sh
  4. 110
    0
      ovh_orchestrator/__init__.py
  5. 18
    0
      ovh_orchestrator/config.example.py
  6. 1
    0
      requirements.txt
  7. 32
    0
      run.sh

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
1
+__pycache__
2
+ovh_orchestrator/config.py

+ 6
- 0
README.md View File

@@ -0,0 +1,6 @@
1
+Building Android (Lineage 17.1 / `/e/`) for LG G6 (h870)
2
+========================================================
3
+
4
+Lots of RAM (12GB is short!) / good CPU required!
5
+
6
+

+ 115
- 0
build_android.sh View File

@@ -0,0 +1,115 @@
1
+#!/bin/bash
2
+# Ubuntu 20.04 base
3
+set -e
4
+set -x
5
+
6
+# Install dependencies
7
+apt-get update
8
+apt-get upgrade -y
9
+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
10
+apt-get install -y default-jdk
11
+apt-get install -y python2
12
+update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1  # Android git repo hooks are python2-only
13
+
14
+# Install repo
15
+mkdir ~/bin
16
+cat >> ~/.profile <<EOF
17
+# set PATH so it includes user's private bin if it exists
18
+if [ -d "$HOME/bin" ] ; then
19
+    PATH="$HOME/bin:$PATH"
20
+fi
21
+EOF
22
+source ~/.profile
23
+curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
24
+chmod a+x ~/bin/repo
25
+
26
+# Git config
27
+git config --global user.email "phyks@phyks.me"
28
+git config --global user.name "Phyks (Lucas Verney)"
29
+
30
+# Use ccache
31
+cat >> ~/.bashrc <<EOF
32
+export USE_CCACHE=1
33
+export CCACHE_EXEC=/usr/bin/ccache
34
+EOF
35
+source ~/.bashrc
36
+ccache -M 50G
37
+ccache -o compression=true
38
+
39
+# Clone Lineage 17.1 or /e/ codebase (takes roughly 1h!)
40
+mkdir -p ~/android/lineage
41
+cd ~/android/lineage
42
+if [[ "${BUILD_FLAVOR}" == "lineage" ]]; then
43
+    repo init -u https://github.com/LineageOS/android.git -b lineage-17.1
44
+elif [[ "$BUILD_FLAVOR" == "e" ]]; then
45
+    repo init -u https://gitlab.e.foundation/e/os/android.git -b v1-q
46
+else
47
+    echo "Unknown build flavor! Exiting."
48
+    exit 1
49
+fi
50
+repo sync
51
+source build/envsetup.sh
52
+
53
+# Get h870-specific repos
54
+mkdir -p ~/android/lineage/.repo/local_manifests/
55
+cat > ~/android/lineage/.repo/local_manifests/roomservice.xml <<EOF
56
+<?xml version="1.0" encoding="UTF-8"?>
57
+<manifest>
58
+  <project name="LG-G6-DEV/android_device_lge_h870" path="device/lge/h870" remote="github" revision="lineage-17.0" />
59
+  <project name="LG-G6-DEV/android_device_lge_msm8996-common" path="device/lge/msm8996-common" remote="github" revision="stagingAU" />
60
+  <project name="LG-G6-DEV/android_kernel_lge_msm8996" path="kernel/lge/msm8996" remote="github" revision="Optimizing" />
61
+  <project name="LG-G6-DEV/proprietary_vendor_lge" path="vendor/lge" remote="github" revision="new_audio" />
62
+</manifest>
63
+EOF
64
+repo sync
65
+
66
+# Some h870 cherry picks
67
+croot
68
+cd frameworks/base/
69
+git remote add fixes https://github.com/BernardoBas/android_frameworks_base.git
70
+git fetch fixes
71
+# Phantom camera fixes
72
+git cherry-pick a904a84ad485d8768c7a523ec380696d573c9a9e 5a02ae0abfb2a341055aecbb46fb6ce3b24070cf
73
+# Sunrise/Sunset hardoded if location is not available
74
+git cherry-pick 2c9baf509fef40586cc07a8b3aed91bb3cc741b3
75
+croot
76
+cd device/lge/msm8996-common/
77
+git remote add brightness https://github.com/BernardoBas/android_device_lge_msm8996-common.git
78
+git fetch brightness
79
+# MIC LEVEL -- TODO
80
+git cherry-pick 9123565f56262e73dc6d613a0efc4bfb5867f5e6
81
+# ROUNDED CORNERS  -- TODO
82
+git cherry-pick 5c490db56b5d2431bc21a35f865511a3ea86ca4a
83
+
84
+
85
+# If you want micro-g on Lineage, uncomment this part
86
+# Note: micro-g is already built-in with /e/
87
+# if [[ "${BUILD_FLAVOR}" == "lineage" ]]; then
88
+#    croot
89
+#    cd frameworks/base
90
+#    curl https://raw.githubusercontent.com/lineageos4microg/docker-lineage-cicd/master/src/signature_spoofing_patches/android_frameworks_base-Q.patch > android_frameworks_base-Q.patch
91
+#    patch -p1 -i android_frameworks_base-Q.patch
92
+# fi
93
+
94
+if [[ "${BUILD_FLAVOR}" == "e" ]]; then
95
+    # Remove some apps built with /e/, comment if you want to keep them
96
+    croot
97
+    # Remove MagicEarth (non-free)
98
+    rm -r prebuilts/prebuiltapks/MagicEarth
99
+    # Remove DemoApp
100
+    rm -r prebuilts/prebuiltapks/DemoApp
101
+    # Remove DroidGuard
102
+    rm -r prebuilts/prebuiltapks/DroidGuard
103
+    # Remove eDrive
104
+    rm -r prebuilts/prebuiltapks/eDrive
105
+    # Remove ESmsSync
106
+    rm -r prebuilts/prebuiltapks/ESmsSync
107
+    # Remove ESmsSync
108
+    rm -r prebuilts/prebuiltapks/ESmsSync
109
+fi
110
+
111
+# Build Lineage or /e/ (takes 2 to 3 hours!)
112
+croot
113
+make clean
114
+date | tee build.log; brunch h870 | tee build.log; date | tee build.log
115
+touch ~/BUILD_DONE

+ 110
- 0
ovh_orchestrator/__init__.py View File

@@ -0,0 +1,110 @@
1
+import uuid
2
+import sys
3
+import time
4
+
5
+import ovh
6
+
7
+from . import config
8
+
9
+
10
+if __name__ == '__main__':
11
+    client = ovh.Client(
12
+        endpoint=config.ovh_endpoint,
13
+        application_key=config.ovh_application_key,
14
+        application_secret=config.ovh_application_secret,
15
+        consumer_key=config.ovh_consumer_key,
16
+    )
17
+
18
+    if len(sys.argv) < 2:
19
+        sys.exit(1)
20
+
21
+    # Create VM
22
+    if sys.argv[1] == 'init':
23
+        # Get image id
24
+        result = client.get(
25
+            '/cloud/project/' + config.ovh_public_cloud_project + '/image',
26
+            flavorType='s1-2',
27
+            osType='linux',
28
+            region=config.ovh_public_cloud_region,
29
+        )
30
+        image_id = next(
31
+            x['id']
32
+            for x in result
33
+            if x['name'] == config.ovh_public_cloud_image
34
+        )
35
+
36
+        # Get SSH key id
37
+        result = client.get(
38
+            '/cloud/project/' + config.ovh_public_cloud_project + '/sshkey',
39
+            region=config.ovh_public_cloud_region,
40
+        )
41
+        ssh_key_id = next(
42
+            x['id']
43
+            for x in result
44
+            if x['name'] == config.ovh_public_cloud_sshkey_name
45
+        )
46
+
47
+        # Get flavor id
48
+        result = client.get(
49
+            '/cloud/project/' + config.ovh_public_cloud_project + '/flavor',
50
+            region=config.ovh_public_cloud_region,
51
+        )
52
+        flavor_id = next(
53
+            x['id']
54
+            for x in result
55
+            if x['name'] == 's1-2'
56
+        )
57
+
58
+        # Create instance
59
+        name = str(uuid.uuid4())
60
+        result = client.post(
61
+            '/cloud/project/' + config.ovh_public_cloud_project + '/instance',
62
+            flavorId=flavor_id,
63
+            imageId=image_id,
64
+            monthlyBilling=False,
65
+            name=name,
66
+            region=config.ovh_public_cloud_region,
67
+            sshKeyId=ssh_key_id
68
+        )
69
+
70
+        if 'id' not in result:
71
+            sys.exit(1)
72
+
73
+        # Wait for IP address
74
+        while True:
75
+            result = client.get(
76
+                '/cloud/project/' + config.ovh_public_cloud_project + '/instance',
77
+                region=config.ovh_public_cloud_region,
78
+            )
79
+            ipAddresses = next(
80
+                x['ipAddresses']
81
+                for x in result
82
+                if x['name'] == name
83
+            )
84
+            if ipAddresses:
85
+                print(ipAddresses[0])
86
+                sys.exit(0)
87
+            time.sleep(30)
88
+    # Clear VM
89
+    elif sys.argv[1] == 'purge':
90
+        if len(sys.argv) < 3:
91
+            sys.exit(1)
92
+
93
+        # Get instance id from its IP address
94
+        result = client.get(
95
+            '/cloud/project/' + config.ovh_public_cloud_project + '/instance',
96
+            region=config.ovh_public_cloud_region,
97
+        )
98
+        instance_id = next(
99
+            x['id']
100
+            for x in result
101
+            if sys.argv[2] in x['ipAddresses']
102
+        )
103
+
104
+        # Delete instance
105
+        client.delete(
106
+            '/cloud/project/' + config.ovh_public_cloud_project +
107
+            '/instance/' + instance_id
108
+        )
109
+    else:
110
+        sys.exit(1)

+ 18
- 0
ovh_orchestrator/config.example.py View File

@@ -0,0 +1,18 @@
1
+# Create API credentials at https://eu.api.ovh.com/createToken/
2
+# See https://docs.ovh.com/fr/api/api-premiers-pas/#prerequis
3
+ovh_endpoint = 'ovh-eu'
4
+ovh_application_key = 'xxxxxxx'
5
+ovh_application_secret = 'xxxxxxx'
6
+ovh_consumer_key = 'xxxxxxx'
7
+
8
+# Fill with ID of your public cloud project, found in the manager URI
9
+ovh_public_cloud_project = 'xxxxxxx'
10
+
11
+ovh_public_cloud_region = 'SBG5'
12
+
13
+# Fill with the name of your SSH key
14
+ovh_public_cloud_sshkey_name = 'xxx'
15
+
16
+# These are tailored for Android builds at reasonable speed / cost
17
+ovh_public_cloud_image = 'Ubuntu 20.04'
18
+ovh_public_cloud_flavor = 'b2-30'

+ 1
- 0
requirements.txt View File

@@ -0,0 +1 @@
1
+ovh

+ 32
- 0
run.sh View File

@@ -0,0 +1,32 @@
1
+#!/bin/bash
2
+set -e
3
+
4
+# Install OVH orchestrator dependencies
5
+python3 -m venv .venv
6
+./.venv/bin/pip install -r requirements.txt
7
+
8
+# Set up an OVH instance to run the build
9
+printf "%s" "Waiting for OVH instance ..."
10
+IP_ADDRESS=$(./.venv/bin/python3 -m ovh_orchestrator init)
11
+while ! timeout 0.2 ping -c 1 -n ${IP_ADDRESS} &> /dev/null
12
+do
13
+    printf "%c" "."
14
+done
15
+
16
+# Run the build on the OVH instance
17
+scp ./build_android.sh ubuntu@${IP_ADDRESS}:~
18
+ssh -f ubuntu@${IP_ADDRESS} 'screen -S build -dm bash ./build_android.sh'
19
+
20
+# Wait for build to complete
21
+set +e
22
+printf "%s" "Building ..."
23
+until ssh ubuntu@${IP_ADDRESS} 'ls ~/BUILD_DONE'; do
24
+    printf "%c" "."
25
+done
26
+set -e
27
+
28
+# Fetch back the built images
29
+rsync -azr --progress ubuntu@${IP_ADDRESS}:~/android/lineage/out/target/product/h870/\*.{zip,md5sum,img} .
30
+
31
+# Purge the OVH instance
32
+./.venv/bin/python3 -m ovh_orchestrator purge ${IP_ADDRESS}