Skip to content

Commit 3844106

Browse files
committed
Merge branch 'dev'
2 parents 8757ffe + aa9b98c commit 3844106

File tree

14 files changed

+185
-97
lines changed

14 files changed

+185
-97
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM docker.io/bitnami/minideb:bookworm
44
ARG userid=1000
55
ARG groupid=1000
66
ARG username=droid
7-
ARG USER="${username}"
7+
ENV USER "${username}"
88

99
# Dirs
1010
ARG ROOT_DIR=/droid_workdir
@@ -103,16 +103,18 @@ ENV DEVICE ""
103103
ENV BUILD_TYPE ""
104104
ENV ROM_MANIFEST ""
105105
ENV ROM_BRANCH ""
106+
ENV ROM_BUILD_FLAGS ""
106107

107108
ENV LUNCH_PREFIX_FALLBACK ""
108109
ENV ROM_PREFIX_FALLBACK ""
109110
ENV ROM_VERSION_FALLBACK ""
111+
ENV ROM_OTA_BRANCH_FALLBACK ""
110112

111113
# Extra
112114
ENV CCACHE_SIZE 40
113115
ENV OTA_REPO_URL ""
114116
ENV KEYS_SUBJECT '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/[email protected]'
115-
ENV TIME_ZONE UTC
117+
ENV TIME_ZONE "UTC"
116118

117119
# Auth
118120
ENV TELEGRAM_TOKEN ""

README.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ The goal is to make building properly with ota and signing easy for everyone.
66

77
<details>
88
<summary>Initial Setup</summary>
9-
<br>
109

1110
## Prerequisites
1211

@@ -86,17 +85,16 @@ sudo rm -rf ~/docker_droid/src/Los15/
8685

8786
<details>
8887
<summary>Variables</summary>
89-
<br>
9088

9189
### required
9290

93-
- DEVICE: Codename(s) of your device(s)
94-
- ROM_DIR: Only change the last part after src/. Defines the source path within the container
95-
- ROM_MANIFEST: URL of the rom manifest you want to sync
96-
- ROM_BRANCH: Branch of the rom you want to sync
97-
- LOCAL_MANIFEST: Direct link to the local manifest(s)
91+
- ```DEVICE```: Codename(s) of your device(s)
92+
- ```ROM_DIR```: Only change the last part after src/. Defines the source path within the container
93+
- ```ROM_MANIFEST```: URL of the rom manifest you want to sync
94+
- ```ROM_BRANCH```: Branch of the rom you want to sync
95+
- ```LOCAL_MANIFEST```: Direct link to the local manifest(s)
9896
or
99-
- CLONE_REPOS: Links to the repo(s) to clone. Repo name MUST have the following pattern https://github.com/user/android_dir1_dir2_dir3/tree/branch or https://github.com/user/dir1_dir2_dir3/tree/branch. Not recommended.
97+
- ```CLONE_REPOS```: Links to the repo(s) to clone. Repo name MUST have the following pattern https://github.com/user/android_dir1_dir2_dir3/tree/branch, https://github.com/user/dir1_dir2_dir3/tree/branch or https://github.com/user/proprietary_dir1_dir2_dir3/tree/branch. Not recommended.
10098

10199
These variables should be defined in the target.env.
102100

@@ -115,17 +113,21 @@ LOCAL_MANIFEST=https://raw.githubusercontent.com/SirRGB/local_manifests/refs/hea
115113
### optional
116114

117115
- GitHub Upload
118-
- [GITHUB_TOKEN](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
119-
- OTA_REPO_URL: for example [email protected]:user/ota_config, will also be used for uploading
120-
- Requires GITHUB_TOKEN or passwordless ssh keys [added to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)
116+
- ```[GITHUB_TOKEN](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)```
117+
- ```OTA_REPO_URL```: for example [email protected]:user/ota_config, will also be used for uploading
118+
- Requires ```GITHUB_TOKEN``` or passwordless ssh keys [added to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)
121119
- SourceForge Upload
122-
- SF_USER: Username of your account
123-
- SF_RELEASES_REPO: Project name
120+
- ```SF_USER```: Username of your account
121+
- ```SF_RELEASES_REPO```: Project name
124122
- Requires passwordless ssh keys added to your [SourceForge account](https://sourceforge.net/p/forge/documentation/SSH%20Keys)
125123
- Telegram logging
126-
- [TELEGRAM_TOKEN](https://core.telegram.org/bots/features#botfather)
127-
- TELEGRAM_CHAT: either as @xyz or the id
128-
- TIME_ZONE: either as in the format UTC+2 or CET
124+
- ```[TELEGRAM_TOKEN](https://core.telegram.org/bots/features#botfather)```
125+
- ```TELEGRAM_CHAT```: either as @xyz or the id
126+
- ```TIME_ZONE```: either as in the format UTC+2 or CET
127+
- ```ROM_BUILD_FLAGS```: if you want to define values like ```WITH_GMS=true``` you can do this in here, even with multiple of them separated by comma for separate builds or space for the same build
128+
- OTA Updates
129+
- At least one file provider mentioned above
130+
- ```OTA_REPO_URL```: Any git hoster using ssh authentification i.e. GitHub, GitLab, CodeBerg,...
129131

130132
These variables should be defined in config.env.
131133

@@ -138,10 +140,10 @@ [email protected]:user/ota_config
138140

139141
## Directories
140142

141-
- dotfiles: .gitconfig for syncing and .ssh for authentification. Needs to be copied from the host manually.
142-
- keys: Contains keys for signing the build. Will be generated automatically if not provided.
143-
- logs: Contains logs and error messages. Logs older than a day will be deleted on a rerun.
144-
- ccache: Used for build caching to speed up compilation. Set to 40GB by default. Can be disabled by overwriting the value with 0 for space-saving.
143+
- ```dotfiles```: .gitconfig for syncing and .ssh for authentification. Needs to be copied from the host manually.
144+
- ```keys```: Contains keys for signing the build. Will be generated automatically if not provided.
145+
- ```logs```: Contains logs and error messages. Logs older than a day will be deleted on a rerun.
146+
- ```ccache```: Used for build caching to speed up compilation. Set to 40GB by default. Can be disabled by overwriting the value with 0 for space-saving.
145147

146148

147149
## Run the build
@@ -171,6 +173,7 @@ You can further speed up build times by using tmpfs as described [here](https://
171173
- GitHub releases enforces a maximum file size of [2 GiB](https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-large-files-on-github#distributing-large-binaries) in their releases
172174
- SourceForge restricts project size to [5-30 GiB](https://sourceforge.net/p/forge/documentation/Disk%20Quotas) depending on the download throughput
173175
- GitLab releases are not feasible due to their [100 MiB](https://docs.gitlab.com/user/gitlab_com/#gitlab-cicd) attachment size limit
176+
- CodeBerg releases are not feasible due to their [100 MiB](https://codeberg.org/Codeberg-e.V./requests/issues/129) size limit as well
174177
175178
176179
## Credits/Reference

TODO.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
## ToDo
2-
- build flag list, for loop
3-
- 7a175f9c808d28788fddc525fe17287655806520
42
- move printing to printf
53
- 94fa96faf062de55062bb79909548e778b692bfb
6-
- more verbose errors, error reporting curl

compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
# CCache to speed up builds
1111
- ~/docker_droid/ccache:/mnt/ccache
1212
# Keys for signing
13-
- ~/docker_droid/keys:/droid_workdir/keys # aosp does weird chmod stuff in here
13+
- ~/docker_droid/keys:/droid_workdir/keys
1414
#RO
1515
# Gitconfig for repo
1616
- ~/docker_droid/dotfiles/.gitconfig:/droid_workdir/.gitconfig:ro

scripts/compat.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ _setup_py2() {
1414

1515
# Set up JDK8 and re-enable TLS 1/1.1
1616
_setup_jdk8() {
17-
local jdk_dir jdk_name
17+
local jdk_dir jdk_tag jdk_name
1818
jdk_dir="${HOME}"/java/jdk
19-
jdk_name=OpenJDK8U-jdk_x64_linux_hotspot_8u452b09.tar.gz
19+
jdk_tag=jdk8u462-b08
20+
jdk_name=OpenJDK8U-jdk_x64_linux_hotspot_"$(echo ${jdk_tag//jdk/} | tr -d -)".tar.gz
2021
mkdir -p "${jdk_dir}"
21-
curl -fsSOL https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u452-b09/OpenJDK8U-jdk_x64_linux_hotspot_8u452b09.tar.gz --output-dir "${jdk_dir}"
22-
echo 9448308a21841960a591b47927cf2d44fdc4c0533a5f8111a4b243a6bafb5d27 "${jdk_dir}"/"${jdk_name}" | sha256sum --check
22+
curl -fsSOL https://github.com/adoptium/temurin8-binaries/releases/download/"${jdk_tag}"/"${jdk_name}" --output-dir "${jdk_dir}"
23+
echo 5d64ae542b59a962b3caadadd346f4b1c3010879a28bb02d928326993de16e79 "${jdk_dir}"/"${jdk_name}" | sha256sum --check
2324
tar xvf "${jdk_dir}"/"${jdk_name}" --directory="${jdk_dir}"
2425
rm "${jdk_dir}"/"${jdk_name}"
2526

26-
export JAVA_HOME="${jdk_dir}"/jdk8u452-b09
27+
export JAVA_HOME="${jdk_dir}"/"${jdk_tag}"
2728
export PATH="${JAVA_HOME}"/bin:"${PATH}"
2829

2930
sed -i 's/TLSv1, TLSv1.1, //g' "${JAVA_HOME}"/jre/lib/security/java.security

scripts/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ find "${LOGS_DIR}"/ -type d -ctime +1 -exec rm -r {} \; || true
1010
BUILD_DATE_UNIX=$(date "+%s")
1111
BUILD_DATE=$(env TZ="${TIME_ZONE}" date -d @"${BUILD_DATE_UNIX}" "+%Y%m%d-%H%M%S")
1212
mkdir "${LOGS_DIR}"/"${BUILD_DATE}"
13-
1413
unset BIN_DIR
14+
1515
# shellcheck source=scripts/sync.sh
1616
source "${SCRIPT_DIR}"/sync.sh

scripts/lunch.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# shellcheck source=scripts/print.sh
44
source "${SCRIPT_DIR}"/print.sh
55

6+
# Define build target
67
_lunch() {
78
cd "${ROM_DIR}" || exit
89

@@ -23,13 +24,17 @@ _lunch() {
2324

2425
# It's all coming together
2526
set +eu
26-
lunch "${product}""${release_codename}"-"${BUILD_TYPE}" || true
27+
if ! lunch "${product}""${release_codename}"-"${BUILD_TYPE}"
28+
then
29+
exit 1
30+
fi
2731
set -eu
2832
}
2933

34+
# Iterate over device array
3035
IFS=',' read -r -a "DEVICE" <<< "${DEVICE}"
3136
for device in "${DEVICE[@]}"; do
32-
export TARGET_DEVICE="${device}"
37+
TARGET_DEVICE="${device}"
3338
_lunch
3439
_print_build_start
3540

scripts/ota.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
# shellcheck source=scripts/print.sh
4+
source "${SCRIPT_DIR}"/print.sh
5+
6+
# Create/print ota json
7+
_ota_info() {
8+
local file_size id datetime custom_build_type
9+
file_size=$(stat -c%s "${OUT}"/"${PACKAGE_NAME}")
10+
id=$(sha256sum "${OUT}"/"${PACKAGE_NAME}" | cut -d" " -f1)
11+
datetime=$(grep ro\.build\.date\.utc "${OUT}"/system/build.prop | cut -d"=" -f2)
12+
custom_build_type="UNOFFICIAL"
13+
jq -n "{\"response\": [{\"datetime\": ${datetime},\"filename\": \"${PACKAGE_NAME}\",\"id\": \"${id}\",\"romtype\": \"${custom_build_type}\", \"size\": ${file_size}, \"url\": \"${DL_OTA_URL}\", \"version\": \"${ROM_VERSION}\"}]}" > "${OUT}"/"${PACKAGE_NAME}".json
14+
}
15+
16+
# Push OTA info
17+
_push_ota_info() {
18+
local target_ota_repo_url target_ota_branch
19+
if [[ ! -d "${ROM_DIR}"_ota ]]; then
20+
mkdir "${ROM_DIR}"_ota
21+
fi
22+
cd "${ROM_DIR}"_ota || exit
23+
git init
24+
git pull "${OTA_REPO_URL}" "${ROM_BRANCH}"
25+
26+
cp "${OUT}"/"${PACKAGE_NAME}".json "${ROM_DIR}"_ota/"${TARGET_DEVICE}".json
27+
git add "${ROM_DIR}"_ota/"${TARGET_DEVICE}".json
28+
git commit -m "${TARGET_DEVICE}: ${BUILD_DATE} update"
29+
30+
# Use ssh primarely, fallback to github tokens
31+
if [[ -n $(find "${HOME}"/.ssh -name "id_*") ]]; then
32+
target_ota_repo_url="${OTA_REPO_URL}"
33+
elif [[ -n "${GITHUB_TOKEN}" ]]; then
34+
target_ota_repo_url="${OTA_REPO_URL//git@github.com:/https://${GITHUB_TOKEN}@github.com/}"
35+
fi
36+
37+
# Append extraversion to avoid collision of different flavours
38+
if [[ -n "${ROM_OTA_BRANCH_FALLBACK}" ]]; then
39+
target_ota_branch="${ROM_OTA_BRANCH_FALLBACK}"
40+
else
41+
target_ota_branch="${ROM_BRANCH}"
42+
fi
43+
44+
if [[ -n "${ROM_EXTRAVERSION}" ]]; then
45+
target_ota_branch="${target_ota_branch}"-"$(tr -d - <<< "${ROM_EXTRAVERSION,,}")"
46+
fi
47+
48+
if [[ -n "${target_ota_repo_url}" ]]; then
49+
git push "${target_ota_repo_url}" HEAD:"${target_ota_branch}"
50+
fi
51+
}
52+
53+
_cleanup_fail() {
54+
_print_ota_fail
55+
exit 1
56+
}
57+
58+
trap _cleanup_fail ERR
59+
60+
_ota_info
61+
if [[ -n "${OTA_REPO_URL}" ]]; then
62+
_push_ota_info
63+
fi
64+
_print_done

scripts/packaging.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ source "${SCRIPT_DIR}"/print.sh
66
# Only works for PRODUCT_VERSION_MAJOR|MINOR
77
# Planned to work on Leaf OS/Lineage OS/CyanogenMOD/amyROM
88
_version() {
9-
local major_version_regex minor_version_regex rom_extraversion
9+
local major_version_regex minor_version_regex
1010
major_version_regex='^PRODUCT_VERSION_MAJOR[[:space:]]:?=[[:space:]][[:digit:]]{1,2}'
1111
minor_version_regex='^PRODUCT_VERSION_MINOR[[:space:]]:?=[[:space:]][[:digit:]]{1,2}'
1212
readonly major_version_regex minor_version_regex
@@ -23,13 +23,13 @@ $(find "${ANDROID_BUILD_TOP}"/vendor/*/config/ \( -name "*[vV]ersion.mk" -o -nam
2323
else
2424
ROM_VERSION="${ROM_VERSION_FALLBACK}"
2525
fi
26-
rom_extraversion=""
26+
ROM_EXTRAVERSION=""
2727
if [[ -n $(find "${OUT}" -mindepth 2 -name "FakeStore.apk" -print -quit) ]]; then
28-
rom_extraversion="MICROG-"
28+
ROM_EXTRAVERSION="MICROG-"
2929
elif [[ -n $(find "${OUT}" -mindepth 2 -name "GmsCore.apk" -print -quit) ]]; then
30-
rom_extraversion="GMS-"
30+
ROM_EXTRAVERSION="GMS-"
3131
fi
32-
PACKAGE_NAME="${ROM_PREFIX}""${ROM_VERSION}"-"${rom_extraversion}"$(env TZ="${TIME_ZONE}" date -d @"${BUILD_DATE_UNIX}" +%Y%m%d)-"${TARGET_DEVICE}"-signed.zip
32+
PACKAGE_NAME="${ROM_PREFIX}""${ROM_VERSION}"-"${ROM_EXTRAVERSION}"$(env TZ="${TIME_ZONE}" date -d @"${BUILD_DATE_UNIX}" +%Y%m%d)-"${TARGET_DEVICE}"-signed.zip
3333
}
3434

3535
# Create flashable zip from target files
@@ -41,9 +41,12 @@ _packaging() {
4141
releasetools_prefix="${ANDROID_BUILD_TOP}"/build/tools/releasetools/
4242
fi
4343
set +eu
44-
"${releasetools_prefix}"ota_from_target_files -k "${KEYS_DIR}"/releasekey \
44+
if ! "${releasetools_prefix}"ota_from_target_files -k "${KEYS_DIR}"/releasekey \
4545
"${OUT}"/signed-target_files.zip \
4646
"${OUT}"/"${PACKAGE_NAME}" 2>&1 | tee -a "${LOGS_DIR}"/"${BUILD_DATE}"/packaging.txt
47+
then
48+
_cleanup_fail
49+
fi
4750
set -eu
4851
}
4952

@@ -54,12 +57,13 @@ _extract_recovery() {
5457
}
5558

5659
_cleanup_fail() {
57-
# shellcheck disable=SC2317
5860
_print_build_fail
61+
exit 1
5962
}
63+
6064
trap _cleanup_fail ERR
6165

62-
_packaging # _version
66+
_packaging
6367
_extract_recovery
6468
_print_build_success
6569

scripts/print.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ NC='\033[0m'
77
# Skelleton for posting to telegram
88
_telegram() {
99
if [[ -n "${TELEGRAM_TOKEN}" ]]; then
10-
curl --request POST https://api.telegram.org/bot"${TELEGRAM_TOKEN}"/sendMessage \
10+
curl -fsSL \
11+
--request POST https://api.telegram.org/bot"${TELEGRAM_TOKEN}"/sendMessage \
1112
--data chat_id="${TELEGRAM_CHAT}" \
1213
--data parse_mode="Markdown" \
1314
--data text="$1"
@@ -16,7 +17,8 @@ _telegram() {
1617

1718
_telegram_separator() {
1819
if [[ -n "${TELEGRAM_TOKEN}" ]]; then
19-
curl --request POST https://api.telegram.org/bot"${TELEGRAM_TOKEN}"/sendSticker \
20+
curl -fsSL \
21+
--request POST https://api.telegram.org/bot"${TELEGRAM_TOKEN}"/sendSticker \
2022
--data chat_id="${TELEGRAM_CHAT}" \
2123
--data parse_mode=HTML \
2224
--data sticker=CAADBQADGgEAAixuhBPbSa3YLUZ8DBYE
@@ -54,6 +56,7 @@ _print_sync_fail() {
5456
_print_error "Sync failed in $((SYNC_DIFF / 60)) minute(s) and $((SYNC_DIFF % 60)) seconds"
5557
}
5658

59+
5760
# Building
5861
_print_build_start() {
5962
BUILD_START=$(date +"%s")
@@ -76,9 +79,10 @@ _print_signing_method() {
7679
_print_success "$* Signing"
7780
}
7881

82+
7983
# Uploading
8084
_print_upload_start() {
81-
_print_success "Upload started to $*"
85+
_print_success "$* Upload started"
8286
}
8387

8488
_print_upload_success() {
@@ -91,6 +95,12 @@ _print_upload_fail() {
9195
_print_error "Upload failed"
9296
}
9397

98+
# Ota
99+
_print_ota_fail() {
100+
_print_error "Ota info failed"
101+
}
102+
103+
94104
_print_done() {
95105
_print_success "Completed successfully"
96106
_telegram_separator

0 commit comments

Comments
 (0)