Browse Source

Minor fixes

Phyks (Lucas Verney) 5 months ago
parent
commit
de61a6d3ad
4 changed files with 166 additions and 132 deletions
  1. 33
    11
      build_android.sh
  2. 0
    110
      ovh_orchestrator/__init__.py
  3. 110
    0
      ovh_orchestrator/__main__.py
  4. 23
    11
      run.sh

+ 33
- 11
build_android.sh View File

@@ -4,15 +4,15 @@ set -e
4 4
 set -x
5 5
 
6 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
7
+sudo apt-get update
8
+sudo apt-get upgrade -y
9
+sudo 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
+sudo apt-get install -y default-jdk
11
+sudo apt-get install -y python2
12
+sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1  # Android git repo hooks are python2-only
13 13
 
14 14
 # Install repo
15
-mkdir ~/bin
15
+mkdir -p ~/bin
16 16
 cat >> ~/.profile <<EOF
17 17
 # set PATH so it includes user's private bin if it exists
18 18
 if [ -d "$HOME/bin" ] ; then
@@ -36,13 +36,16 @@ source ~/.bashrc
36 36
 ccache -M 50G
37 37
 ccache -o compression=true
38 38
 
39
+# Prevent repo prompt about using colors
40
+git config --global color.ui false
41
+
39 42
 # Clone Lineage 17.1 or /e/ codebase (takes roughly 1h!)
40 43
 mkdir -p ~/android/lineage
41 44
 cd ~/android/lineage
42 45
 if [[ "${BUILD_FLAVOR}" == "lineage" ]]; then
43
-    repo init -u https://github.com/LineageOS/android.git -b lineage-17.1
46
+    repo init -q -u https://github.com/LineageOS/android.git -b lineage-17.1
44 47
 elif [[ "$BUILD_FLAVOR" == "e" ]]; then
45
-    repo init -u https://gitlab.e.foundation/e/os/android.git -b v1-q
48
+    repo init -q -u https://gitlab.e.foundation/e/os/android.git -b v1-q
46 49
 else
47 50
     echo "Unknown build flavor! Exiting."
48 51
     exit 1
@@ -104,8 +107,27 @@ if [[ "${BUILD_FLAVOR}" == "e" ]]; then
104 107
     rm -r prebuilts/prebuiltapks/eDrive
105 108
     # Remove ESmsSync
106 109
     rm -r prebuilts/prebuiltapks/ESmsSync
107
-    # Remove ESmsSync
108
-    rm -r prebuilts/prebuiltapks/ESmsSync
110
+    # Remove Notes
111
+    rm -r prebuilts/prebuiltapks/Notes
112
+    # Remove Camera
113
+    rm -r prebuilts/prebuiltapks/Camera
114
+    # Remove Browser
115
+    rm -r prebuilts/prebuiltapks/Browser
116
+    # Remove Weather
117
+    rm -r prebuilts/prebuiltapks/Weather
118
+    # Remove Tasks
119
+    rm -r prebuilts/prebuiltapks/Tasks
120
+    # Remove PdfViewer
121
+    rm -r prebuilts/prebuiltapks/PdfViewer
122
+    # Remove BrowserWebView
123
+    rm -r prebuilts/prebuiltapks/BrowserWebView
124
+    # Remove eSpeakTTS
125
+    rm -r prebuilts/prebuiltapks/eSpeakTTS
126
+    # Remove LibreOfficeViewer
127
+    rm -r prebuilts/prebuiltapks/LibreOfficeViewer
128
+    # Remove OpenWeatherMapWeatherProvider
129
+    rm -r prebuilts/prebuiltapks/OpenWeatherMapWeatherProvider
130
+    # TODO
109 131
 fi
110 132
 
111 133
 # Build Lineage or /e/ (takes 2 to 3 hours!)

+ 0
- 110
ovh_orchestrator/__init__.py View File

@@ -1,110 +0,0 @@
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)

+ 110
- 0
ovh_orchestrator/__main__.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]['ip'])
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)

+ 23
- 11
run.sh View File

@@ -1,32 +1,44 @@
1 1
 #!/bin/bash
2 2
 set -e
3
+set -v
3 4
 
4 5
 # Install OVH orchestrator dependencies
5 6
 python3 -m venv .venv
6 7
 ./.venv/bin/pip install -r requirements.txt
7 8
 
8 9
 # 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
10
+if [ "$1" == "" ] || [ $# -gt 1 ]; then
11
+    printf "%s" "Waiting for OVH instance ..."
12
+    IP_ADDRESS=$(./.venv/bin/python3 -m ovh_orchestrator init)
13
+    echo " (IP: ${IP_ADDRESS}) "
14
+    while ! timeout 0.2 ping -c 1 -n ${IP_ADDRESS} &> /dev/null
15
+    do
16
+        printf "%c" "."
17
+        sleep 3
18
+    done
19
+
20
+    # Wait a bit to ensure SSH is up
21
+    sleep 10
15 22
 
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'
23
+    # Run the build on the OVH instance
24
+    scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" ./build_android.sh ubuntu@${IP_ADDRESS}:~
25
+    # Build /e/ (or edit the BUILD_FLAVOR environment variable)
26
+    ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" -f ubuntu@${IP_ADDRESS} 'screen -S build -dm bash BUILD_FLAVOR=e ./build_android.sh'
27
+else
28
+    IP_ADDRESS="$1"
29
+fi
19 30
 
20 31
 # Wait for build to complete
21 32
 set +e
22 33
 printf "%s" "Building ..."
23
-until ssh ubuntu@${IP_ADDRESS} 'ls ~/BUILD_DONE'; do
34
+until ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" ubuntu@${IP_ADDRESS} 'ls ~/BUILD_DONE'; do
24 35
     printf "%c" "."
36
+    sleep 30
25 37
 done
26 38
 set -e
27 39
 
28 40
 # Fetch back the built images
29
-rsync -azr --progress ubuntu@${IP_ADDRESS}:~/android/lineage/out/target/product/h870/\*.{zip,md5sum,img} .
41
+rsync -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" -azr --progress ubuntu@${IP_ADDRESS}:~/android/lineage/out/target/product/h870/\*.{zip,md5sum,img} .
30 42
 
31 43
 # Purge the OVH instance
32 44
 ./.venv/bin/python3 -m ovh_orchestrator purge ${IP_ADDRESS}