Minor fixes

This commit is contained in:
Lucas Verney 2020-12-26 11:52:06 +01:00
parent 841c2d17d7
commit de61a6d3ad
4 changed files with 166 additions and 132 deletions

View File

@ -4,15 +4,15 @@ 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
sudo apt-get update
sudo apt-get upgrade -y
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
sudo apt-get install -y default-jdk
sudo apt-get install -y python2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 # Android git repo hooks are python2-only
# Install repo
mkdir ~/bin
mkdir -p ~/bin
cat >> ~/.profile <<EOF
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
@ -36,13 +36,16 @@ source ~/.bashrc
ccache -M 50G
ccache -o compression=true
# Prevent repo prompt about using colors
git config --global color.ui false
# Clone Lineage 17.1 or /e/ codebase (takes roughly 1h!)
mkdir -p ~/android/lineage
cd ~/android/lineage
if [[ "${BUILD_FLAVOR}" == "lineage" ]]; then
repo init -u https://github.com/LineageOS/android.git -b lineage-17.1
repo init -q -u https://github.com/LineageOS/android.git -b lineage-17.1
elif [[ "$BUILD_FLAVOR" == "e" ]]; then
repo init -u https://gitlab.e.foundation/e/os/android.git -b v1-q
repo init -q -u https://gitlab.e.foundation/e/os/android.git -b v1-q
else
echo "Unknown build flavor! Exiting."
exit 1
@ -104,8 +107,27 @@ if [[ "${BUILD_FLAVOR}" == "e" ]]; then
rm -r prebuilts/prebuiltapks/eDrive
# Remove ESmsSync
rm -r prebuilts/prebuiltapks/ESmsSync
# Remove ESmsSync
rm -r prebuilts/prebuiltapks/ESmsSync
# Remove Notes
rm -r prebuilts/prebuiltapks/Notes
# Remove Camera
rm -r prebuilts/prebuiltapks/Camera
# Remove Browser
rm -r prebuilts/prebuiltapks/Browser
# Remove Weather
rm -r prebuilts/prebuiltapks/Weather
# Remove Tasks
rm -r prebuilts/prebuiltapks/Tasks
# Remove PdfViewer
rm -r prebuilts/prebuiltapks/PdfViewer
# Remove BrowserWebView
rm -r prebuilts/prebuiltapks/BrowserWebView
# Remove eSpeakTTS
rm -r prebuilts/prebuiltapks/eSpeakTTS
# Remove LibreOfficeViewer
rm -r prebuilts/prebuiltapks/LibreOfficeViewer
# Remove OpenWeatherMapWeatherProvider
rm -r prebuilts/prebuiltapks/OpenWeatherMapWeatherProvider
# TODO
fi
# Build Lineage or /e/ (takes 2 to 3 hours!)

View File

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

View File

@ -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]['ip'])
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)

32
run.sh
View File

@ -1,32 +1,44 @@
#!/bin/bash
set -e
set -v
# 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
if [ "$1" == "" ] || [ $# -gt 1 ]; then
printf "%s" "Waiting for OVH instance ..."
IP_ADDRESS=$(./.venv/bin/python3 -m ovh_orchestrator init)
echo " (IP: ${IP_ADDRESS}) "
while ! timeout 0.2 ping -c 1 -n ${IP_ADDRESS} &> /dev/null
do
printf "%c" "."
done
sleep 3
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 a bit to ensure SSH is up
sleep 10
# Run the build on the OVH instance
scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" ./build_android.sh ubuntu@${IP_ADDRESS}:~
# Build /e/ (or edit the BUILD_FLAVOR environment variable)
ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" -f ubuntu@${IP_ADDRESS} 'screen -S build -dm bash BUILD_FLAVOR=e ./build_android.sh'
else
IP_ADDRESS="$1"
fi
# Wait for build to complete
set +e
printf "%s" "Building ..."
until ssh ubuntu@${IP_ADDRESS} 'ls ~/BUILD_DONE'; do
until ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" ubuntu@${IP_ADDRESS} 'ls ~/BUILD_DONE'; do
printf "%c" "."
sleep 30
done
set -e
# Fetch back the built images
rsync -azr --progress ubuntu@${IP_ADDRESS}:~/android/lineage/out/target/product/h870/\*.{zip,md5sum,img} .
rsync -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" -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}