diff --git a/build-community.sh b/build-community.sh index 3a28c3d6b2a7da18722d85f5700a925c94184666..7d30574657cbb6348e36e89cbf60a01fa198f3ba 100755 --- a/build-community.sh +++ b/build-community.sh @@ -35,11 +35,11 @@ if [ "$CLEAN_OUTDIR" = true ]; then fi # Treat DEVICE_LIST as DEVICE_LIST_ -first_branch=$(cut -d ',' -f 1 <<< "$BRANCH_NAME") +first_branch=$(cut -d ',' -f 1 <<<"$BRANCH_NAME") if [ -n "$DEVICE_LIST" ]; then - device_list_first_branch="DEVICE_LIST_$(sed 's/.*-\([a-zA-Z]*\)$/\1/' <<< $first_branch)" + device_list_first_branch="DEVICE_LIST_$(sed 's/.*-\([a-zA-Z]*\)$/\1/' <<<$first_branch)" device_list_first_branch=${device_list_first_branch^^} - read $device_list_first_branch <<< "$DEVICE_LIST,${!device_list_first_branch}" + read $device_list_first_branch <<<"$DEVICE_LIST,${!device_list_first_branch}" fi sync_successful=true @@ -50,7 +50,7 @@ if [ "$LOCAL_MIRROR" = true ]; then if [ ! -d .repo ]; then echo ">> [$(date)] Initializing mirror repository" | tee -a "$repo_log" - yes | repo init -u "$MIRROR" --mirror --no-clone-bundle -p linux &>> "$repo_log" + yes | repo init -u "$MIRROR" --mirror --no-clone-bundle -p linux &>>"$repo_log" fi # Copy local manifests to the appropriate folder in order take them into consideration @@ -66,7 +66,7 @@ if [ "$LOCAL_MIRROR" = true ]; then fi echo ">> [$(date)] Syncing mirror repository" | tee -a "$repo_log" - repo sync -j$(nproc --all) --force-sync --no-clone-bundle &>> "$repo_log" + repo sync -j$(nproc --all) --force-sync --no-clone-bundle &>>"$repo_log" if [ $? != 0 ]; then sync_successful=false @@ -76,7 +76,7 @@ if [ "$LOCAL_MIRROR" = true ]; then fi for branch in ${BRANCH_NAME//,/ }; do - branch_dir=$(sed 's/.*-\([a-zA-Z]*\)$/\1/' <<< $branch) + branch_dir=$(sed 's/.*-\([a-zA-Z]*\)$/\1/' <<<$branch) branch_dir=${branch_dir^^} device_list_cur_branch="DEVICE_LIST_$branch_dir" devices=${!device_list_cur_branch} @@ -85,38 +85,37 @@ for branch in ${BRANCH_NAME//,/ }; do vendor=lineage regex_part1="^v[0-9](\.[0-9]*){0,2}(-(beta|alpha|rc)(\.[0-9]*){0,1}){0,1}-(" regex_part2=")(-[a-zA-Z0-9_]*)*$" - + if [[ "${BRANCH_NAME}" =~ $regex_part1"nougat"$regex_part2 ]]; then vendor="cm" - themuppets_branch="cm-14.1" - android_version="7.1.2" - use_openjdk_from_ubuntu=true + themuppets_branch="cm-14.1" + android_version="7.1.2" + use_openjdk_from_ubuntu=true elif [[ "${BRANCH_NAME}" =~ $regex_part1"oreo"$regex_part2 ]]; then - themuppets_branch="lineage-15.1" - android_version="8.1" - use_openjdk_from_ubuntu=true + themuppets_branch="lineage-15.1" + android_version="8.1" + use_openjdk_from_ubuntu=true elif [[ "${BRANCH_NAME}" =~ $regex_part1"pie"$regex_part2 ]]; then - themuppets_branch="lineage-16.0" - android_version="9" + themuppets_branch="lineage-16.0" + android_version="9" elif [[ "${BRANCH_NAME}" =~ $regex_part1"q"$regex_part2 ]]; then - themuppets_branch="lineage-17.1" - android_version="10" + themuppets_branch="lineage-17.1" + android_version="10" elif [[ "${BRANCH_NAME}" =~ $regex_part1"r"$regex_part2 ]]; then - themuppets_branch="lineage-18.1" - android_version="11" + themuppets_branch="lineage-18.1" + android_version="11" elif [[ "${BRANCH_NAME}" =~ $regex_part1"s"$regex_part2 ]]; then - themuppets_branch="lineage-19.1" - android_version="12" + themuppets_branch="lineage-19.1" + android_version="12" elif [[ "${BRANCH_NAME}" =~ $regex_part1"t"$regex_part2 ]]; then - themuppets_branch="lineage-20.0" - android_version="13" + themuppets_branch="lineage-20.0" + android_version="13" else - echo ">> [$(date)] Building branch $branch is not (yet) suppported" - exit 1 + echo ">> [$(date)] Building branch $branch is not (yet) suppported" + exit 1 fi - android_version_major=$(cut -d '.' -f 1 <<< $android_version) - + android_version_major=$(cut -d '.' -f 1 <<<$android_version) mkdir -p "$SRC_DIR/$branch_dir" cd "$SRC_DIR/$branch_dir" @@ -136,16 +135,15 @@ for branch in ${BRANCH_NAME//,/ }; do echo ">> [$(date)] (Re)initializing branch repository" | tee -a "$repo_log" if [ "$LOCAL_MIRROR" = true ]; then - yes | repo init -u "$REPO" --reference "$MIRROR_DIR" -b "$branch" &>> "$repo_log" + yes | repo init -u "$REPO" --reference "$MIRROR_DIR" -b "$branch" &>>"$repo_log" else TAG_PREFIX="" - if curl -s https://gitlab.e.foundation/api/v4/projects/659/repository/tags?search=${BRANCH_NAME} | jq -r ".[].name" | grep -q "${BRANCH_NAME}" - then + if curl -s https://gitlab.e.foundation/api/v4/projects/659/repository/tags?search=${BRANCH_NAME} | jq -r ".[].name" | grep -q "${BRANCH_NAME}"; then echo ">> [$(date)] Branch name $branch is a tag on e/os/releases, prefix with refs/tags/ for 'repo init'" TAG_PREFIX="refs/tags/" fi - yes | repo init -u "$REPO" -b "${TAG_PREFIX}$branch" &>> "$repo_log" + yes | repo init -u "$REPO" -b "${TAG_PREFIX}$branch" &>>"$repo_log" fi # Copy local manifests to the appropriate folder in order take them into consideration @@ -162,11 +160,11 @@ for branch in ${BRANCH_NAME//,/ }; do echo ">> [$(date)] Syncing branch repository" | tee -a "$repo_log" builddate=$(date +%Y%m%d) - repo sync -c -j$(nproc --all) --force-sync &>> "$repo_log" + repo sync -c -j$(nproc --all) --force-sync &>>"$repo_log" if [ $? != 0 ]; then sync_successful=false - else + else repo forall -c 'git lfs pull' fi @@ -175,9 +173,22 @@ for branch in ${BRANCH_NAME//,/ }; do exit 1 fi - los_ver_major=$(sed -n -e 's/^\s*PRODUCT_VERSION_MAJOR = //p' "vendor/$vendor/config/common.mk") - los_ver_minor=$(sed -n -e 's/^\s*PRODUCT_VERSION_MINOR = //p' "vendor/$vendor/config/common.mk") - los_ver="$los_ver_major.$los_ver_minor" + config_file="vendor/$vendor/config/version.mk" + if [ ! -f "$config_file" ]; then + # If version.mk doesn't exist, use common.mk + config_file="vendor/$vendor/config/common.mk" + fi + + # Extract version information + PRODUCT_VERSION_MAJOR=$(grep -oP 'PRODUCT_VERSION_MAJOR = \K.*' "$config_file") + PRODUCT_VERSION_MINOR=$(grep -oP 'PRODUCT_VERSION_MINOR = \K.*' "$config_file") + PRODUCT_VERSION_MAINTENANCE=$(grep -oP 'PRODUCT_VERSION_MAINTENANCE := \K.*' "$config_file") + + # Check if PRODUCT_VERSION_MAINTENANCE is not equal to 0 + e_ver="$PRODUCT_VERSION_MAJOR.$PRODUCT_VERSION_MINOR" + if [ "$PRODUCT_VERSION_MAINTENANCE" != "0" ]; then + e_ver="$PRODUCT_VERSION_MAJOR.$PRODUCT_VERSION_MINOR.$PRODUCT_VERSION_MAINTENANCE" + fi echo ">> [$(date)] Setting \"$RELEASE_TYPE\" as release type" sed -i "/\$(filter .*\$(${vendor^^}_BUILDTYPE)/,+2d" "vendor/$vendor/config/common.mk" @@ -190,10 +201,10 @@ for branch in ${BRANCH_NAME//,/ }; do if [ -n "$(grep updater_server_url packages/apps/Updater/res/values/strings.xml)" ]; then # "New" updater configuration: full URL (with placeholders {device}, {type} and {incr}) - sed "s|{name}|updater_server_url|g; s|{url}|$OTA_URL/v1/{device}/{type}/{incr}|g" /root/packages_updater_strings.xml > "$updater_url_overlay_dir/strings.xml" + sed "s|{name}|updater_server_url|g; s|{url}|$OTA_URL/v1/{device}/{type}/{incr}|g" /root/packages_updater_strings.xml >"$updater_url_overlay_dir/strings.xml" elif [ -n "$(grep conf_update_server_url_def packages/apps/Updater/res/values/strings.xml)" ]; then # "Old" updater configuration: just the URL - sed "s|{name}|conf_update_server_url_def|g; s|{url}|$OTA_URL|g" /root/packages_updater_strings.xml > "$updater_url_overlay_dir/strings.xml" + sed "s|{name}|conf_update_server_url_def|g; s|{url}|$OTA_URL|g" /root/packages_updater_strings.xml >"$updater_url_overlay_dir/strings.xml" else echo ">> [$(date)] ERROR: no known Updater URL property found" exit 1 @@ -204,18 +215,22 @@ for branch in ${BRANCH_NAME//,/ }; do echo ">> [$(date)] Adding keys path ($KEYS_DIR)" # Soong (Android 9+) complains if the signing keys are outside the build path ln -sf "$KEYS_DIR" user-keys - if [ "$android_version_major" -lt "10" ]; then - sed -i "1s;^;PRODUCT_DEFAULT_DEV_CERTIFICATE := user-keys/releasekey\nPRODUCT_OTA_PUBLIC_KEYS := user-keys/releasekey\nPRODUCT_EXTRA_RECOVERY_KEYS := user-keys/releasekey\n\n;" "vendor/$vendor/config/common.mk" - fi + fi - if [ "$android_version_major" -ge "10" ]; then - sed -i "1s;^;PRODUCT_DEFAULT_DEV_CERTIFICATE := user-keys/releasekey\nPRODUCT_OTA_PUBLIC_KEYS := user-keys/releasekey\n\n;" "vendor/$vendor/config/common.mk" - fi + # Remove build number and date on builds. + if [ -f out/build_date.txt ]; then + rm out/build_date.txt + fi + if [ -f out/soong/build_number.txt ]; then + rm out/soong/build_number.txt fi # Prepare the environment echo ">> [$(date)] Preparing build environment" - source build/envsetup.sh > /dev/null + source build/envsetup.sh >/dev/null + + ANDROID_BUILD_ID=$(grep -o 'BUILD_ID=.*' "build/make/core/build_id.mk" | cut -d "=" -f 2 | cut -c 1 | tr '[:upper:]' '[:lower:]') + APEX_PACKAGE_LIST=$(cat "/root/apex.list") if [ -f /root/userscripts/before.sh ]; then echo ">> [$(date)] Running before.sh" @@ -234,7 +249,7 @@ for branch in ${BRANCH_NAME//,/ }; do if [ "$LOCAL_MIRROR" = true ]; then echo ">> [$(date)] Syncing mirror repository" | tee -a "$repo_log" cd "$MIRROR_DIR" - repo sync -j$(nproc --all) --force-sync --no-clone-bundle &>> "$repo_log" + repo sync -j$(nproc --all) --force-sync --no-clone-bundle &>>"$repo_log" if [ $? != 0 ]; then sync_successful=false @@ -246,7 +261,7 @@ for branch in ${BRANCH_NAME//,/ }; do echo ">> [$(date)] Syncing branch repository" | tee -a "$repo_log" cd "$SRC_DIR/$branch_dir" - repo sync -c --force-sync &>> "$repo_log" + repo sync -c --force-sync &>>"$repo_log" if [ $? != 0 ]; then sync_successful=false @@ -278,11 +293,11 @@ for branch in ${BRANCH_NAME//,/ }; do logsubdir= fi - DEBUG_LOG="$LOGS_DIR/$logsubdir/eos-$los_ver-$builddate-$RELEASE_TYPE-$codename.log" + DEBUG_LOG="$LOGS_DIR/$logsubdir/eos-$e_ver-$builddate-$RELEASE_TYPE-$codename.log" if [ -f /root/userscripts/pre-build.sh ]; then - echo ">> [$(date)] Running pre-build.sh for $codename" >> "$DEBUG_LOG" - /root/userscripts/pre-build.sh $codename &>> "$DEBUG_LOG" + echo ">> [$(date)] Running pre-build.sh for $codename" >>"$DEBUG_LOG" + /root/userscripts/pre-build.sh $codename &>>"$DEBUG_LOG" if [ $? != 0 ]; then build_device=false @@ -290,7 +305,7 @@ for branch in ${BRANCH_NAME//,/ }; do fi if [ "$build_device" = false ]; then - echo ">> [$(date)] No build for $codename" >> "$DEBUG_LOG" + echo ">> [$(date)] No build for $codename" >>"$DEBUG_LOG" continue fi @@ -301,6 +316,15 @@ for branch in ${BRANCH_NAME//,/ }; do echo ">> [$(date)] Switch to Python2" ln -fs /usr/bin/python2 /usr/bin/python + export BUILD_DATETIME=$(date -u +%s) + export BUILD_NUMBER=$(date -u -d @$BUILD_DATETIME +%Y%m%d00) + + export BUILD_USERNAME=eos + export BUILD_HOSTNAME=eos + export DISPLAY_BUILD_NUMBER=true + + echo ">> [$(date)] BUILD_DATETIME=$BUILD_DATETIME" + echo ">> [$(date)] BUILD_NUMBER=$BUILD_NUMBER" BRUNCH_DEVICE=${codename} @@ -308,21 +332,60 @@ for branch in ${BRANCH_NAME//,/ }; do BRUNCH_DEVICE=lineage_${codename}-eng fi - if brunch ${BRUNCH_DEVICE} &>> "$DEBUG_LOG"; then - currentdate=$(date +%Y%m%d) - if [ "$builddate" != "$currentdate" ]; then - find out/target/product/$codename -maxdepth 1 -name "e-*-$currentdate-*.zip*" -type f -exec sh /root/fix_build_date.sh {} $currentdate $builddate \; &>> "$DEBUG_LOG" + if breakfast ${BRUNCH_DEVICE} &>>"$DEBUG_LOG"; then + mka target-files-package otatools + echo ">> [$(date)] Starting signing target-files-package" + + # Set the target files name + TARGET_FILES=lineage_$DEVICE-target_files-$BUILD_NUMBER.zip + E_VERSION=e-$e_ver-$ANDROID_BUILD_ID-$(date -u +%Y%m%d%H%M%S)-$RELEASE_TYPE-${DEVICE}.zip + + # Remove release-keys from build as its still using test-keys. + if [ "$SIGN_BUILDS" != true ]; then + SIGN_TARGETS=(-t "+test-keys,-release-keys") + else + SIGN_TARGETS=(-o -d "user-keys") fi - # Move produced ZIP files to the main OUT directory - echo ">> [$(date)] Moving build artifacts for $codename to '$ZIP_DIR/$zipsubdir'" | tee -a "$DEBUG_LOG" - cd out/target/product/$codename - for build in e-*.zip; do - sha256sum "$build" > "$ZIP_DIR/$zipsubdir/$build.sha256sum" - done - find . -maxdepth 1 -name 'e-*.zip*' -type f -exec mv {} "$ZIP_DIR/$zipsubdir/" \; &>> "$DEBUG_LOG" - cd "$source_dir" - build_successful=true + if [[ "$ANDROID_BUILD_ID" == [st] ]]; then + for PACKAGE in $APEX_PACKAGE_LIST; do + if [ -f "user-keys/$PACKAGE.pem" ] && + [ -f "user-keys/$PACKAGE.x509.pem" ] && + [ -f "user-keys/$PACKAGE.pk8" ]; then + SIGN_TARGETS+=(--extra_apks "$PACKAGE.apex=user-keys/$PACKAGE" + --extra_apex_payload_key "$PACKAGE.apex=user-keys/$PACKAGE.pem") + fi + done + fi + + if [ -f "$OUT/obj/PACKAGING/target_files_intermediates/$TARGET_FILES" ]; then + sign_target_files_apks "${SIGN_TARGETS[@]}" \ + "$OUT/obj/PACKAGING/target_files_intermediates/$TARGET_FILES" "$OUT/$TARGET_FILES" + + if [ "$SIGN_BUILDS" = true ]; then + SIGN_KEY=(-k "user-keys/releasekey") + fi + + ota_from_target_files "${SIGN_KEY[@]}" "$OUT/$TARGET_FILES" \ + "$OUT/$E_VERSION" + + currentdate=$(date +%Y%m%d) + if [ "$builddate" != "$currentdate" ]; then + find out/target/product/$codename -maxdepth 1 -name "e-*-$currentdate-*.zip*" -type f -exec sh /root/fix_build_date.sh {} $currentdate $builddate \; &>>"$DEBUG_LOG" + fi + + # Move produced ZIP files to the main OUT directory + echo ">> [$(date)] Moving build artifacts for $codename to '$ZIP_DIR/$zipsubdir'" | tee -a "$DEBUG_LOG" + cd out/target/product/$codename + for build in e-*.zip; do + sha256sum "$build" >"$ZIP_DIR/$zipsubdir/$build.sha256sum" + done + find . -maxdepth 1 -name 'e-*.zip*' -type f -exec mv {} "$ZIP_DIR/$zipsubdir/" \; &>>"$DEBUG_LOG" + cd "$source_dir" + build_successful=true + else + echo ">> [$(date)] Unable to find $TARGET_FILES" | tee -a "$DEBUG_LOG" + fi else echo ">> [$(date)] Failed build for $codename" | tee -a "$DEBUG_LOG" fi @@ -330,21 +393,21 @@ for branch in ${BRANCH_NAME//,/ }; do # Remove old zips and logs if [ "$DELETE_OLD_ZIPS" -gt "0" ]; then if [ "$ZIP_SUBDIR" = true ]; then - /usr/bin/python /root/clean_up.py -n $DELETE_OLD_ZIPS -V $los_ver -N 1 "$ZIP_DIR/$zipsubdir" + /usr/bin/python /root/clean_up.py -n $DELETE_OLD_ZIPS -V $e_ver -N 1 "$ZIP_DIR/$zipsubdir" else - /usr/bin/python /root/clean_up.py -n $DELETE_OLD_ZIPS -V $los_ver -N 1 -c $codename "$ZIP_DIR" + /usr/bin/python /root/clean_up.py -n $DELETE_OLD_ZIPS -V $e_ver -N 1 -c $codename "$ZIP_DIR" fi fi if [ "$DELETE_OLD_LOGS" -gt "0" ]; then if [ "$LOGS_SUBDIR" = true ]; then - /usr/bin/python /root/clean_up.py -n $DELETE_OLD_LOGS -V $los_ver -N 1 "$LOGS_DIR/$logsubdir" + /usr/bin/python /root/clean_up.py -n $DELETE_OLD_LOGS -V $e_ver -N 1 "$LOGS_DIR/$logsubdir" else - /usr/bin/python /root/clean_up.py -n $DELETE_OLD_LOGS -V $los_ver -N 1 -c $codename "$LOGS_DIR" + /usr/bin/python /root/clean_up.py -n $DELETE_OLD_LOGS -V $e_ver -N 1 -c $codename "$LOGS_DIR" fi fi if [ -f /root/userscripts/post-build.sh ]; then - echo ">> [$(date)] Running post-build.sh for $codename" >> "$DEBUG_LOG" - /root/userscripts/post-build.sh $codename $build_successful &>> "$DEBUG_LOG" + echo ">> [$(date)] Running post-build.sh for $codename" >>"$DEBUG_LOG" + /root/userscripts/post-build.sh $codename $build_successful &>>"$DEBUG_LOG" fi echo ">> [$(date)] Finishing build for $codename" | tee -a "$DEBUG_LOG" @@ -352,9 +415,9 @@ for branch in ${BRANCH_NAME//,/ }; do # The Jack server must be stopped manually, as we want to unmount $TMP_DIR/merged cd "$TMP_DIR" if [ -f "$TMP_DIR/merged/prebuilts/sdk/tools/jack-admin" ]; then - "$TMP_DIR/merged/prebuilts/sdk/tools/jack-admin kill-server" &> /dev/null || true + "$TMP_DIR/merged/prebuilts/sdk/tools/jack-admin kill-server" &>/dev/null || true fi - lsof | grep "$TMP_DIR/merged" | awk '{ print $2 }' | sort -u | xargs -r kill &> /dev/null + lsof | grep "$TMP_DIR/merged" | awk '{ print $2 }' | sort -u | xargs -r kill &>/dev/null while [ -n "$(lsof | grep $TMP_DIR/merged)" ]; do sleep 1 @@ -370,7 +433,7 @@ for branch in ${BRANCH_NAME//,/ }; do rm -rf ./* else cd "$source_dir" - mka clean &>> "$DEBUG_LOG" + mka clean &>>"$DEBUG_LOG" fi fi @@ -381,7 +444,6 @@ for branch in ${BRANCH_NAME//,/ }; do fi done - if [ "$DELETE_OLD_LOGS" -gt "0" ]; then find "$LOGS_DIR" -maxdepth 1 -name repo-*.log | sort | head -n -$DELETE_OLD_LOGS | xargs -r rm fi diff --git a/format_script.sh b/format_script.sh new file mode 100755 index 0000000000000000000000000000000000000000..b0a718bf5cb2034f0a206ad77bd4a4db8083c8ba --- /dev/null +++ b/format_script.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Check if shfmt is installed +if ! command -v shfmt &>/dev/null; then + echo "shfmt is not installed. Please install shfmt (curl -sS https://webi.sh/shfmt | sh) to fix formatting." + exit 0 +fi + +# Get the directory of the script +SCRIPT_DIR="$(cd "$(dirname "$0")"/ && pwd)" + +# Define a function to format shell scripts +format_scripts() { + local dir="$1" + # Iterate over each shell script file in the directory + while IFS= read -r -d '' script_file; do + echo "Formatting $script_file ..." + shfmt -w -i 2 "$script_file" + git add "$script_file" + done < <(find "$dir" -type f -name '*.sh' -print0) +} + +# Format scripts in the current directory +format_scripts "$SCRIPT_DIR" + +# Recursively format scripts in subdirectories +while IFS= read -r -d '' subdir; do + format_scripts "$subdir" +done < <(find "$SCRIPT_DIR" -type d -print0) + +echo "Formatting complete!" diff --git a/src/apex.list b/src/apex.list new file mode 100644 index 0000000000000000000000000000000000000000..fa6cdb0f96c5e977b22b75a8382c1156db006308 --- /dev/null +++ b/src/apex.list @@ -0,0 +1,50 @@ +com.android.adbd +com.android.adservices +com.android.adservices.api +com.android.appsearch +com.android.art +com.android.bluetooth +com.android.btservices +com.android.cellbroadcast +com.android.compos +com.android.configinfrastructure +com.android.connectivity.resources +com.android.conscrypt +com.android.devicelock +com.android.extservices +com.android.hardware.wifi +com.android.healthfitness +com.android.hotspot2.osulogin +com.android.i18n +com.android.ipsec +com.android.media +com.android.media.swcodec +com.android.mediaprovider +com.android.nearby.halfsheet +com.android.networkstack.tethering +com.android.neuralnetworks +com.android.ondevicepersonalization +com.android.os.statsd +com.android.permission +com.android.resolv +com.android.rkpd +com.android.runtime +com.android.safetycenter.resources +com.android.scheduling +com.android.sdkext +com.android.support.apexer +com.android.telephony +com.android.telephonymodules +com.android.tethering +com.android.tzdata +com.android.uwb +com.android.uwb.resources +com.android.virt +com.android.vndk.current +com.android.vndk.current.on_vendor +com.android.wifi +com.android.wifi.dialog +com.android.wifi.resources +com.google.pixel.camera.hal +com.google.pixel.vibrator.hal +com.qorvo.uwb diff --git a/src/build.sh b/src/build.sh index dd3ebc71739a5de3bdf2984caac0a2595b4dc633..a35ddf88621a054bc933806891255e993b17c0b2 100755 --- a/src/build.sh +++ b/src/build.sh @@ -31,50 +31,59 @@ if [ "$CLEAN_OUTDIR" = true ]; then rm -rf "${ZIP_DIR:?}/*" fi +# Define a function to extract images based on the provided header and config file +extract_images() { + local header="$1" + local config_file="$2" + if [ -f "$config_file" ]; then + awk -v header="$header" '$0 ~ header {flag=1; print; next} /^$/{flag=0}flag' "$config_file" | tr -d '\r\n' | sed 's/\\//g' | grep -oP "(?<=${header} ).*" + fi +} + sync_successful=true use_openjdk_from_ubuntu=false -branch_dir=$(sed -E 's/^v[0-9](\.[0-9]*){0,2}(-(beta|alpha|rc)(\.[0-9]*){0,1}){0,1}-(nougat|oreo|pie|q|r|s|t)(-[a-zA-Z0-9_]*)*$/\5/' <<< "${BRANCH_NAME}") +branch_dir=$(sed -E 's/^v[0-9](\.[0-9]*){0,2}(-(beta|alpha|rc)(\.[0-9]*){0,1}){0,1}-(nougat|oreo|pie|q|r|s|t)(-[a-zA-Z0-9_]*)*$/\5/' <<<"${BRANCH_NAME}") branch_dir=${branch_dir^^} if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then - vendor=lineage - regex_part1="^v[0-9](\.[0-9]*){0,2}(-(beta|alpha|rc)(\.[0-9]*){0,1}){0,1}-(" - regex_part2=")(-[a-zA-Z0-9_]*)*$" - if [[ "${BRANCH_NAME}" =~ $regex_part1"nougat"$regex_part2 ]]; then - vendor="cm" - themuppets_branch="cm-14.1" - android_version="7.1.2" - use_openjdk_from_ubuntu=true - elif [[ "${BRANCH_NAME}" =~ $regex_part1"oreo"$regex_part2 ]]; then - themuppets_branch="lineage-15.1" - android_version="8.1" - use_openjdk_from_ubuntu=true - elif [[ "${BRANCH_NAME}" =~ $regex_part1"pie"$regex_part2 ]]; then - themuppets_branch="lineage-16.0" - android_version="9" - elif [[ "${BRANCH_NAME}" =~ $regex_part1"q"$regex_part2 ]]; then - themuppets_branch="lineage-17.1" - android_version="10" - elif [[ "${BRANCH_NAME}" =~ $regex_part1"r"$regex_part2 ]]; then - themuppets_branch="lineage-18.1" - android_version="11" - elif [[ "${BRANCH_NAME}" =~ $regex_part1"s"$regex_part2 ]]; then - themuppets_branch="lineage-19.1" - android_version="12" - elif [[ "${BRANCH_NAME}" =~ $regex_part1"t"$regex_part2 ]]; then - themuppets_branch="lineage-20.0" - android_version="13" - else - echo ">> [$(date)] Building branch $branch is not (yet) suppported" - exit 1 - fi + vendor=lineage + regex_part1="^v[0-9](\.[0-9]*){0,2}(-(beta|alpha|rc)(\.[0-9]*){0,1}){0,1}-(" + regex_part2=")(-[a-zA-Z0-9_]*)*$" + if [[ "${BRANCH_NAME}" =~ $regex_part1"nougat"$regex_part2 ]]; then + vendor="cm" + themuppets_branch="cm-14.1" + android_version="7.1.2" + use_openjdk_from_ubuntu=true + elif [[ "${BRANCH_NAME}" =~ $regex_part1"oreo"$regex_part2 ]]; then + themuppets_branch="lineage-15.1" + android_version="8.1" + use_openjdk_from_ubuntu=true + elif [[ "${BRANCH_NAME}" =~ $regex_part1"pie"$regex_part2 ]]; then + themuppets_branch="lineage-16.0" + android_version="9" + elif [[ "${BRANCH_NAME}" =~ $regex_part1"q"$regex_part2 ]]; then + themuppets_branch="lineage-17.1" + android_version="10" + elif [[ "${BRANCH_NAME}" =~ $regex_part1"r"$regex_part2 ]]; then + themuppets_branch="lineage-18.1" + android_version="11" + elif [[ "${BRANCH_NAME}" =~ $regex_part1"s"$regex_part2 ]]; then + themuppets_branch="lineage-19.1" + android_version="12" + elif [[ "${BRANCH_NAME}" =~ $regex_part1"t"$regex_part2 ]]; then + themuppets_branch="lineage-20.0" + android_version="13" + else + echo ">> [$(date)] Building branch $branch is not (yet) suppported" + exit 1 + fi - if [[ "${KEEP_LOCAL_MANIFEST_BRANCH}" = true ]]; then - themuppets_branch=$BRANCH_NAME - fi + if [[ "${KEEP_LOCAL_MANIFEST_BRANCH}" = true ]]; then + themuppets_branch=$BRANCH_NAME + fi - android_version_major=$(cut -d '.' -f 1 <<< $android_version) + android_version_major=$(cut -d '.' -f 1 <<<$android_version) mkdir -p "$SRC_DIR/$branch_dir" cd "$SRC_DIR/$branch_dir" || return 1 @@ -95,8 +104,7 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then echo ">> [$(date)] (Re)initializing branch repository" TAG_PREFIX="" - if curl -s https://gitlab.e.foundation/api/v4/projects/659/repository/tags?search=${BRANCH_NAME} | jq -r ".[].name" | grep -q ${BRANCH_NAME} - then + if curl -s https://gitlab.e.foundation/api/v4/projects/659/repository/tags?search=${BRANCH_NAME} | jq -r ".[].name" | grep -q ${BRANCH_NAME}; then echo ">> [$(date)] Branch name ${BRANCH_NAME} is a tag on e/os/releases, prefix with refs/tags/ for 'repo init'" TAG_PREFIX="refs/tags/" fi @@ -123,27 +131,27 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then if [ "$INCLUDE_PROPRIETARY" = true ]; then wget -q -O .repo/local_manifests/proprietary.xml "https://raw.githubusercontent.com/TheMuppets/manifests/$themuppets_branch/muppets.xml" /root/build_manifest.py --remote "https://gitlab.com" --remotename "gitlab_https" \ - "https://gitlab.com/the-muppets/manifest/raw/$themuppets_branch/muppets.xml" .repo/local_manifests/proprietary_gitlab.xml + "https://gitlab.com/the-muppets/manifest/raw/$themuppets_branch/muppets.xml" .repo/local_manifests/proprietary_gitlab.xml fi echo ">> [$(date)] Syncing branch repository" builddate=$(date +%Y%m%d) - repo_out=$(repo sync -c -j$(nproc --all) --force-sync 2>&1 > /dev/null) + repo_out=$(repo sync -c -j$(nproc --all) --force-sync 2>&1 >/dev/null) repo_status=$? echo -e $repo_out - if [ "$repo_status" != "0" ]; then + if [ "$repo_status" != "0" ]; then if [ -f /root/userscripts/clean.sh ]; then if [[ "$repo_out" == *"Failing repos:"* ]]; then - list_line=`echo -e $repo_out | sed 's/.*Failing repos: //'` + list_line=$(echo -e $repo_out | sed 's/.*Failing repos: //') fi if [[ "$repo_out" == *"Cannot remove project"* ]]; then - list_line=`echo -e $repo_out | grep "Cannot remove project" | sed -e 's/.*error: \(.*\): Cannot.*/\1/'` + list_line=$(echo -e $repo_out | grep "Cannot remove project" | sed -e 's/.*error: \(.*\): Cannot.*/\1/') fi echo ">> [$(date)] Running clean.sh" /root/userscripts/clean.sh $list_line - if ! repo sync -c --force-sync ; then + if ! repo sync -c --force-sync; then sync_successful=false fi else @@ -155,32 +163,48 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then repo forall -c 'git lfs pull' fi - if [ ! -d "vendor/$vendor" ]; then echo ">> [$(date)] Missing \"vendor/$vendor\", aborting" exit 1 fi - los_ver_major=$(sed -n -e 's/^\s*PRODUCT_VERSION_MAJOR = //p' "vendor/$vendor/config/common.mk") - los_ver_minor=$(sed -n -e 's/^\s*PRODUCT_VERSION_MINOR = //p' "vendor/$vendor/config/common.mk") - los_ver="$los_ver_major.$los_ver_minor" + config_file="vendor/lineage/config/version.mk" + if [ ! -f "$config_file" ]; then + # If version.mk doesn't exist, use common.mk + config_file="vendor/lineage/config/common.mk" + fi + + # Extract version information + PRODUCT_VERSION_MAJOR=$(grep -oP 'PRODUCT_VERSION_MAJOR = \K.*' "$config_file") + PRODUCT_VERSION_MINOR=$(grep -oP 'PRODUCT_VERSION_MINOR = \K.*' "$config_file") + PRODUCT_VERSION_MAINTENANCE=$(grep -oP 'PRODUCT_VERSION_MAINTENANCE := \K.*' "$config_file") + + # Check if PRODUCT_VERSION_MAINTENANCE is not equal to 0 + e_ver="$PRODUCT_VERSION_MAJOR.$PRODUCT_VERSION_MINOR" + if [ "$PRODUCT_VERSION_MAINTENANCE" != "0" ]; then + e_ver="$PRODUCT_VERSION_MAJOR.$PRODUCT_VERSION_MINOR.$PRODUCT_VERSION_MAINTENANCE" + fi if [ "$SIGN_BUILDS" = true ]; then echo ">> [$(date)] Adding keys path ($KEYS_DIR)" # Soong (Android 9+) complains if the signing keys are outside the build path ln -sf "$KEYS_DIR" user-keys - if [ "$android_version_major" -lt "10" ]; then - sed -i "1s;^;PRODUCT_DEFAULT_DEV_CERTIFICATE := user-keys/releasekey\nPRODUCT_OTA_PUBLIC_KEYS := user-keys/releasekey\nPRODUCT_EXTRA_RECOVERY_KEYS := user-keys/releasekey\n\n;" "vendor/$vendor/config/common.mk" - fi + fi - if [ "$android_version_major" -ge "10" ]; then - sed -i "1s;^;PRODUCT_DEFAULT_DEV_CERTIFICATE := user-keys/releasekey\nPRODUCT_OTA_PUBLIC_KEYS := user-keys/releasekey\n\n;" "vendor/$vendor/config/common.mk" - fi + # Remove build number and date on builds. + if [ -f out/build_date.txt ]; then + rm out/build_date.txt + fi + if [ -f out/soong/build_number.txt ]; then + rm out/soong/build_number.txt fi # Prepare the environment echo ">> [$(date)] Preparing build environment" - source build/envsetup.sh > /dev/null + source build/envsetup.sh >/dev/null + + ANDROID_BUILD_ID=$(grep -o 'BUILD_ID=.*' "build/make/core/build_id.mk" | cut -d "=" -f 2 | cut -c 1 | tr '[:upper:]' '[:lower:]') + APEX_PACKAGE_LIST=$(cat "/root/apex.list") if [ -f /root/userscripts/before.sh ]; then echo ">> [$(date)] Running before.sh" @@ -198,7 +222,6 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then echo ">> [$(date)] Syncing branch repository" cd "$SRC_DIR/$branch_dir" || return 1 - if ! repo sync -c -j$(nproc --all) --force-sync; then sync_successful=false build_device=false @@ -224,7 +247,6 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then if [ -f /root/userscripts/pre-build.sh ]; then echo ">> [$(date)] Running pre-build.sh for ${DEVICE}" - if ! /root/userscripts/pre-build.sh "${DEVICE}"; then build_device=false fi @@ -253,6 +275,16 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then BRUNCH_DEVICE=lineage_${DEVICE}-userdebug fi + export BUILD_DATETIME=$(date -u +%s) + export BUILD_NUMBER=$(date -u -d @$BUILD_DATETIME +%Y%m%d00) + + export BUILD_USERNAME=eos + export BUILD_HOSTNAME=eos + export DISPLAY_BUILD_NUMBER=true + + echo ">> [$(date)] BUILD_DATETIME=$BUILD_DATETIME" + echo ">> [$(date)] BUILD_NUMBER=$BUILD_NUMBER" + build_success=false if [ "${BUILD_ONLY_SYSTEMIMAGE}" = true ]; then breakfast "${BRUNCH_DEVICE}" @@ -260,15 +292,141 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then build_success=true fi elif [ "${IS_EMULATOR}" = true ]; then - if lunch "${BRUNCH_DEVICE}" && mka sdk_addon ; then + if lunch "${BRUNCH_DEVICE}" && mka sdk_addon; then build_success=true fi - elif [ "${BUILD_SUPER_IMAGE}" = true ]; then - if breakfast "${BRUNCH_DEVICE}" && mka bacon superimage; then - build_success=true + elif breakfast "${BRUNCH_DEVICE}"; then + mka target-files-package otatools + echo ">> [$(date)] Starting signing target-files-package" + + # Set the target files name + TARGET_FILES=lineage_$DEVICE-target_files-$BUILD_NUMBER.zip + E_VERSION=e-$e_ver-$ANDROID_BUILD_ID-$(date -u +%Y%m%d%H%M%S)-$RELEASE_TYPE-${DEVICE}.zip + + # Remove release-keys from build as its still using test-keys. + if [ "$SIGN_BUILDS" != true ]; then + SIGN_TARGETS=(-t "+test-keys,-release-keys") + else + SIGN_TARGETS=(-o -d "user-keys") fi - elif brunch "${BRUNCH_DEVICE}"; then + + if [ "$android_version_major" -ge 12 ]; then + for PACKAGE in $APEX_PACKAGE_LIST; do + if [ -f "user-keys/$PACKAGE.pem" ] && + [ -f "user-keys/$PACKAGE.x509.pem" ] && + [ -f "user-keys/$PACKAGE.pk8" ]; then + SIGN_TARGETS+=(--extra_apks "$PACKAGE.apex=user-keys/$PACKAGE" + --extra_apex_payload_key "$PACKAGE.apex=user-keys/$PACKAGE.pem") + fi + done + fi + + if [ -f "$OUT/obj/PACKAGING/target_files_intermediates/$TARGET_FILES" ]; then + sign_target_files_apks "${SIGN_TARGETS[@]}" \ + "$OUT/obj/PACKAGING/target_files_intermediates/$TARGET_FILES" "$OUT/$TARGET_FILES" + + # Generate OTA zip + echo ">> [$(date)] Generating OTA zip from target-files-package" + if [ "${BUILD_ONLY_SYSTEMIMAGE}" != true ]; then + if [ "$SIGN_BUILDS" = true ]; then + SIGN_KEY=(-k "user-keys/releasekey") + fi + ota_from_target_files --backup=true "${SIGN_KEY[@]}" "$OUT/$TARGET_FILES" \ + "$OUT/$E_VERSION" + md5sum $OUT/$E_VERSION >$OUT/$E_VERSION.md5sum + sha256sum $OUT/$E_VERSION >$OUT/$E_VERSION.sha256sum + fi + + # Generate fastboot package zip (Doesn't include firmware) + # Flash: fastboot update update.zip + FASTBOOT_PACKAGE="FASTBOOT-$E_VERSION" + echo ">> [$(date)] Generating fastboot zip from target-files-package" + img_from_target_files "$OUT/$TARGET_FILES" "$OUT/$FASTBOOT_PACKAGE" + + IMAGES=("recovery" "boot" "vendor_boot" "dtbo" "vbmeta" "vendor_kernel_boot" "super_empty" "system" "odm" "product" "system_ext" "vendor" "vbmeta_system" "super") + + for i in "${!IMAGES[@]}"; do + if unzip -l "$OUT/$FASTBOOT_PACKAGE" | grep -q "${IMAGES[i]}.img"; then + unzip -o -j -q "$OUT/$FASTBOOT_PACKAGE" "${IMAGES[i]}.img" -d "$OUT" + fi + done + + IMG_FLASH_PATH="$source_dir/vendor/eos/flash" + IMG_FIRMWARE_PATH="$source_dir/vendor/firmware" + QFIL_FLASH_PATH="$source_dir/vendor/murena-flash" + + FIRMWARE_CONFIG=$IMG_FIRMWARE_PATH/${DEVICE}/config.mk + QFIL_CONFIG=$QFIL_FLASH_PATH/${DEVICE}/config.mk + IMG_CONFIG=$IMG_FLASH_PATH/${DEVICE}/config.mk + + FIRMWARE_IMAGES=$(extract_images "FIRMWARE_IMAGES :=" "$FIRMWARE_CONFIG") + QFIL_IMAGES=$(extract_images "HLOS_QFIL_TARGET :=" "$QFIL_CONFIG") + IMG_IMAGES=$(extract_images "HLOS_IMAGES_TARGET :=" "$IMG_CONFIG") + + IMAGE_PACKAGE_NAME=IMG-${E_VERSION} + QFIL_IMAGE_PACKAGE_NAME=QFIL-${E_VERSION} + + if echo "$QFIL_IMAGES $IMG_IMAGES" | grep -q "super.img"; then + build_super_image "$OUT/$TARGET_FILES" "$OUT/super.img" + fi + + # Create a temp folder for creating IMG-e* + mkdir -p $OUT/IMG + + if [ -f "$IMG_FLASH_PATH/${DEVICE}/flash_${DEVICE}_factory.sh" ] && [ ! -z "$FIRMWARE_IMAGES" ]; then + if [[ $IMG_IMAGES =~ "userdata.img" ]]; then + mka userdataimage + fi + + # Copy required images for IMG-e* + for IMAGE in $IMG_IMAGES; do + cp $OUT/$IMAGE $OUT/IMG/$IMAGE + done + + # Copy required images for IMG-e* + for IMAGE in $FIRMWARE_IMAGES; do + cp $IMG_FIRMWARE_PATH/${DEVICE}/radio/$IMAGE.img $OUT/IMG/$IMAGE.img + done + + # Copy required fastboot tools for IMG-e* + cp -r $IMG_FLASH_PATH/fastboot/bin-msys $OUT/IMG/bin-msys + cp -r $IMG_FLASH_PATH/fastboot/bin-linux-x86 $OUT/IMG/bin-linux-x86 + cp $IMG_FLASH_PATH/${DEVICE}/flash_${DEVICE}_factory.sh $OUT/IMG/flash_${DEVICE}_factory.sh + + echo ">> [$(date)] Generating IMG zip" + cd $OUT/IMG + zip -r $OUT/$IMAGE_PACKAGE_NAME * + md5sum $OUT/$IMAGE_PACKAGE_NAME >$OUT/$IMAGE_PACKAGE_NAME.md5sum + sha256sum $OUT/$IMAGE_PACKAGE_NAME >$OUT/$IMAGE_PACKAGE_NAME.sha256sum + + rm -rf $OUT/IMG/bin-msys $OUT/IMG/bin-linux-x86 $OUT/IMG/flash_${DEVICE}_factory.sh $OUT/IMG/fastboot_update.zip + cd "$source_dir" + fi + + if [ -f "$QFIL_FLASH_PATH/${DEVICE}/configs/rawprogram0.xml" ] && [ ! -z "$FIRMWARE_IMAGES" ] && [ ! -z "$QFIL_IMAGES" ]; then + # Copy required images for IMG-e* + for IMAGE in $QFIL_IMAGES; do + cp $OUT/$IMAGE $OUT/IMG/$IMAGE + done + + cp -R $QFIL_FLASH_PATH/${DEVICE}/configs/* $OUT/IMG/ + cp -R $QFIL_FLASH_PATH/${DEVICE}/prebuilts/* $OUT/IMG/ + python2 $QFIL_FLASH_PATH/checksparse.py -i $OUT/IMG/rawprogram0.xml -s $OUT/IMG -t $OUT/IMG + + echo ">> [$(date)] Generating QFIL zip" + cd $OUT/IMG + zip -r $OUT/$QFIL_IMAGE_PACKAGE_NAME * + md5sum $OUT/$QFIL_IMAGE_PACKAGE_NAME >$OUT/$QFIL_IMAGE_PACKAGE_NAME.md5sum + sha256sum $OUT/$QFIL_IMAGE_PACKAGE_NAME >$OUT/$QFIL_IMAGE_PACKAGE_NAME.sha256sum + cd "$source_dir" + fi + + rm -rf $OUT/IMG + build_success=true + else + echo ">> [$(date)] Unable to find $TARGET_FILES" + fi fi if [ "$build_success" = true ]; then @@ -281,7 +439,6 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then echo ">> [$(date)] Moving build artifacts for ${DEVICE} to '$ZIP_DIR/$zipsubdir'" cd "${OUT}" || return 1 for build in $(ls e-*.zip); do - sha256sum "$build" > "$ZIP_DIR/$zipsubdir/$build.sha256sum" find . -maxdepth 1 \( -name 'e-*.zip*' -o -name 'IMG-e*.zip*' -o -name 'QFIL-e*.zip*' \) -type f -exec mv {} "$ZIP_DIR/$zipsubdir/" \; SKIP_DYNAMIC_IMAGES="odm.img product.img system.img system_ext.img vendor.img" @@ -290,8 +447,8 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then echo "backing up flash tools" git clone https://gitlab.e.foundation/e/os/flash_tools cd flash_tools - zip -r "$ZIP_DIR/$zipsubdir/IMG-$build" bin* - zip "$ZIP_DIR/$zipsubdir/IMG-$build" flash_${DEVICE}_factory.sh + zip -r "$ZIP_DIR/$zipsubdir/IMG-$build" bin* + zip "$ZIP_DIR/$zipsubdir/IMG-$build" flash_${DEVICE}_factory.sh cd .. fi if [ "$BUILD_SUPER_IMAGE" = true ]; then @@ -304,16 +461,16 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then find . -maxdepth 1 \( -name '*.img' -o -name '*_scatter.txt' -o -name '*.bin' \) -type f -exec zip "$ZIP_DIR/$zipsubdir/IMG-$build" {} \; fi cd "$ZIP_DIR/$zipsubdir" || return 1 - sha256sum "IMG-$build" > "IMG-$build.sha256sum" - md5sum "IMG-$build" > "IMG-$build.md5sum" + sha256sum "IMG-$build" >"IMG-$build.sha256sum" + md5sum "IMG-$build" >"IMG-$build.md5sum" cd "${OUT}" || return 1 fi if [ "$BACKUP_INTERMEDIATE_SYSTEM_IMG" = true ]; then - mv obj/PACKAGING/target_files_intermediates/lineage*/IMAGES/system.img ./ + mv $OUT/system.img ./ zip "$ZIP_DIR/$zipsubdir/IMG-$build" system.img cd $ZIP_DIR/$zipsubdir - sha256sum "IMG-$build" > "IMG-$build.sha256sum" - md5sum "IMG-$build" > "IMG-$build.md5sum" + sha256sum "IMG-$build" >"IMG-$build.sha256sum" + md5sum "IMG-$build" >"IMG-$build.md5sum" cd "${OUT}" || return 1 fi @@ -327,109 +484,109 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then RECOVERY_IMG_NAME="recovery-${build%.*}.img" RECOVERY_ZIP_NAME="recovery-IMG-${build%.*}.zip" - if [ "$RECOVERY_NEEDS_SUPPORT_IMG" = true ]; then - # Copy the files specified by the flags - if [ "$RECOVERY_NEEDS_BOOT_IMG" = true ]; then - cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/boot.img "$BOOT_IMG_NAME" - sha256sum "$BOOT_IMG_NAME" > "$BOOT_IMG_NAME.sha256sum" - fi - if [ "$RECOVERY_NEEDS_DTBO_IMG" = true ]; then - cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/dtbo.img "$DTBO_IMG_NAME" - sha256sum "$DTBO_IMG_NAME" > "$DTBO_IMG_NAME.sha256sum" - fi - if [ "$RECOVERY_NEEDS_VBMETA_IMG" = true ]; then - cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/vbmeta.img "$VBMETA_IMG_NAME" - sha256sum "$VBMETA_IMG_NAME" > "$VBMETA_IMG_NAME.sha256sum" - fi - if [ "$RECOVERY_NEEDS_VENDOR_BOOT_IMG" = true ]; then - cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/vendor_boot.img "$VENDOR_BOOT_IMG_NAME" - sha256sum "$VENDOR_BOOT_IMG_NAME" > "$VENDOR_BOOT_IMG_NAME.sha256sum" - fi - if [ "$RECOVERY_NEEDS_SUPER_IMG" = true ]; then - cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/super_empty.img "$SUPER_EMPTY_IMG_NAME" - sha256sum "$SUPER_EMPTY_IMG_NAME" > "$SUPER_EMPTY_IMG_NAME.sha256sum" - fi - if [ "$RECOVERY_NEEDS_VENDOR_KERNEL_BOOT_IMG" = true ]; then - cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/vendor_kernel_boot.img "$VENDOR_KERNEL_BOOT_IMG_NAME" - sha256sum "$VENDOR_KERNEL_BOOT_IMG_NAME" > "$VENDOR_KERNEL_BOOT_IMG_NAME.sha256sum" - fi - - if [ "$VBOOT_IS_RECOVERY" = true ]; then - cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/vendor_boot.img "$RECOVERY_IMG_NAME" - elif [ -f "recovery.img" ]; then - cp -a recovery.img "$RECOVERY_IMG_NAME" - else - cp -a boot.img "$RECOVERY_IMG_NAME" - fi - - # Generate SHA256 checksum for RECOVERY_IMG_NAME - sha256sum "$RECOVERY_IMG_NAME" > "$RECOVERY_IMG_NAME.sha256sum" - - # Conditionally include files in zip command based on flags - files_to_zip=("$RECOVERY_IMG_NAME" "$RECOVERY_IMG_NAME.sha256sum") - - if [ "$RECOVERY_NEEDS_BOOT_IMG" = true ]; then - files_to_zip+=("$BOOT_IMG_NAME") - files_to_zip+=("$BOOT_IMG_NAME.sha256sum") - fi - if [ "$RECOVERY_NEEDS_DTBO_IMG" = true ]; then - files_to_zip+=("$DTBO_IMG_NAME") - files_to_zip+=("$DTBO_IMG_NAME.sha256sum") - fi - if [ "$RECOVERY_NEEDS_VBMETA_IMG" = true ]; then - files_to_zip+=("$VBMETA_IMG_NAME") - files_to_zip+=("$VBMETA_IMG_NAME.sha256sum") - fi - if [ "$RECOVERY_NEEDS_VENDOR_BOOT_IMG" = true ]; then - files_to_zip+=("$VENDOR_BOOT_IMG_NAME") - files_to_zip+=("$VENDOR_BOOT_IMG_NAME.sha256sum") - fi - if [ "$RECOVERY_NEEDS_SUPER_IMG" = true ]; then - files_to_zip+=("$SUPER_EMPTY_IMG_NAME") - files_to_zip+=("$SUPER_EMPTY_IMG_NAME.sha256sum") - fi - if [ "$RECOVERY_NEEDS_VENDOR_KERNEL_BOOT_IMG" = true ]; then - files_to_zip+=("$VENDOR_KERNEL_BOOT_IMG_NAME") - files_to_zip+=("$VENDOR_KERNEL_BOOT_IMG_NAME.sha256sum") - fi - # Zip command - zip "$RECOVERY_ZIP_NAME" "${files_to_zip[@]}" - sha256sum "$RECOVERY_ZIP_NAME" > "$RECOVERY_ZIP_NAME.sha256sum" - mv "$RECOVERY_ZIP_NAME"* "$ZIP_DIR/$zipsubdir/" + if [ "$RECOVERY_NEEDS_SUPPORT_IMG" = true ]; then + # Copy the files specified by the flags + if [ "$RECOVERY_NEEDS_BOOT_IMG" = true ]; then + mv $OUT/boot.img "$BOOT_IMG_NAME" + sha256sum "$BOOT_IMG_NAME" >"$BOOT_IMG_NAME.sha256sum" + fi + if [ "$RECOVERY_NEEDS_DTBO_IMG" = true ]; then + cmv $OUT/dtbo.img "$DTBO_IMG_NAME" + sha256sum "$DTBO_IMG_NAME" >"$DTBO_IMG_NAME.sha256sum" + fi + if [ "$RECOVERY_NEEDS_VBMETA_IMG" = true ]; then + mv $OUT/vbmeta.img "$VBMETA_IMG_NAME" + sha256sum "$VBMETA_IMG_NAME" >"$VBMETA_IMG_NAME.sha256sum" + fi + if [ "$RECOVERY_NEEDS_VENDOR_BOOT_IMG" = true ]; then + mv $OUT/vendor_boot.img "$VENDOR_BOOT_IMG_NAME" + sha256sum "$VENDOR_BOOT_IMG_NAME" >"$VENDOR_BOOT_IMG_NAME.sha256sum" + fi + if [ "$RECOVERY_NEEDS_SUPER_IMG" = true ]; then + mv $OUT/super_empty.img "$SUPER_EMPTY_IMG_NAME" + sha256sum "$SUPER_EMPTY_IMG_NAME" >"$SUPER_EMPTY_IMG_NAME.sha256sum" + fi + if [ "$RECOVERY_NEEDS_VENDOR_KERNEL_BOOT_IMG" = true ]; then + mv $OUT/vendor_kernel_boot.img "$VENDOR_KERNEL_BOOT_IMG_NAME" + sha256sum "$VENDOR_KERNEL_BOOT_IMG_NAME" >"$VENDOR_KERNEL_BOOT_IMG_NAME.sha256sum" + fi + + if [ "$VBOOT_IS_RECOVERY" = true ]; then + mv $OUT/vendor_boot.img "$RECOVERY_IMG_NAME" + elif [ -f "recovery.img" ]; then + mv $OUT/recovery.img "$RECOVERY_IMG_NAME" else - if [ "$VBOOT_IS_RECOVERY" = true ]; then - cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/vendor_boot.img "$RECOVERY_IMG_NAME" - elif [ -f "recovery.img" ]; then - cp -a recovery.img "$RECOVERY_IMG_NAME" - else - cp -a boot.img "$RECOVERY_IMG_NAME" - fi - - # Calculate sha256sum and move file - sha256sum "$RECOVERY_IMG_NAME" > "$RECOVERY_IMG_NAME.sha256sum" - mv "$RECOVERY_IMG_NAME"* "$ZIP_DIR/$zipsubdir/" + mv $OUT/boot.img "$RECOVERY_IMG_NAME" + fi + + # Generate SHA256 checksum for RECOVERY_IMG_NAME + sha256sum "$RECOVERY_IMG_NAME" >"$RECOVERY_IMG_NAME.sha256sum" + + # Conditionally include files in zip command based on flags + files_to_zip=("$RECOVERY_IMG_NAME" "$RECOVERY_IMG_NAME.sha256sum") + + if [ "$RECOVERY_NEEDS_BOOT_IMG" = true ]; then + files_to_zip+=("$BOOT_IMG_NAME") + files_to_zip+=("$BOOT_IMG_NAME.sha256sum") + fi + if [ "$RECOVERY_NEEDS_DTBO_IMG" = true ]; then + files_to_zip+=("$DTBO_IMG_NAME") + files_to_zip+=("$DTBO_IMG_NAME.sha256sum") fi + if [ "$RECOVERY_NEEDS_VBMETA_IMG" = true ]; then + files_to_zip+=("$VBMETA_IMG_NAME") + files_to_zip+=("$VBMETA_IMG_NAME.sha256sum") + fi + if [ "$RECOVERY_NEEDS_VENDOR_BOOT_IMG" = true ]; then + files_to_zip+=("$VENDOR_BOOT_IMG_NAME") + files_to_zip+=("$VENDOR_BOOT_IMG_NAME.sha256sum") + fi + if [ "$RECOVERY_NEEDS_SUPER_IMG" = true ]; then + files_to_zip+=("$SUPER_EMPTY_IMG_NAME") + files_to_zip+=("$SUPER_EMPTY_IMG_NAME.sha256sum") + fi + if [ "$RECOVERY_NEEDS_VENDOR_KERNEL_BOOT_IMG" = true ]; then + files_to_zip+=("$VENDOR_KERNEL_BOOT_IMG_NAME") + files_to_zip+=("$VENDOR_KERNEL_BOOT_IMG_NAME.sha256sum") + fi + # Zip command + zip "$RECOVERY_ZIP_NAME" "${files_to_zip[@]}" + sha256sum "$RECOVERY_ZIP_NAME" >"$RECOVERY_ZIP_NAME.sha256sum" + mv "$RECOVERY_ZIP_NAME"* "$ZIP_DIR/$zipsubdir/" + else + if [ "$VBOOT_IS_RECOVERY" = true ]; then + mv $OUT/vendor_boot.img "$RECOVERY_IMG_NAME" + elif [ -f "recovery.img" ]; then + mv $OUT/recovery.img "$RECOVERY_IMG_NAME" + else + mv $OUT/boot.img "$RECOVERY_IMG_NAME" + fi + + # Calculate sha256sum and move file + sha256sum "$RECOVERY_IMG_NAME" >"$RECOVERY_IMG_NAME.sha256sum" + mv "$RECOVERY_IMG_NAME"* "$ZIP_DIR/$zipsubdir/" + fi fi done #with only systemimage, we don't have a e-*.zip if [ "${BUILD_ONLY_SYSTEMIMAGE}" = true ]; then - build=e-`grep lineage.version system/build.prop | sed s/#.*// | sed s/.*=// | tr -d \\n`.zip + build=e-$(grep lineage.version system/build.prop | sed s/#.*// | sed s/.*=// | tr -d \n).zip if [ "$BACKUP_INTERMEDIATE_SYSTEM_IMG" = true ]; then - mv obj/PACKAGING/target_files_intermediates/lineage*/IMAGES/system.img ./ + mv $OUT/system.img ./ zip "$ZIP_DIR/$zipsubdir/IMG-$build" system.img cd $ZIP_DIR/$zipsubdir - sha256sum "IMG-$build" > "IMG-$build.sha256sum" - md5sum "IMG-$build" > "IMG-$build.md5sum" + sha256sum "IMG-$build" >"IMG-$build.sha256sum" + md5sum "IMG-$build" >"IMG-$build.md5sum" cd "${OUT}" || return 1 fi fi if [ "$IS_EMULATOR" = true -a "$BACKUP_EMULATOR" = true ]; then - EMULATOR_ARCHIVE="IMG-e-`grep lineage.version system/build.prop | sed s/#.*// | sed s/.*=// | tr -d '\n'`.zip" + EMULATOR_ARCHIVE="IMG-e-$(grep lineage.version system/build.prop | sed s/#.*// | sed s/.*=// | tr -d '\n').zip" mv ../../../host/linux-x86/sdk_addon/*-img.zip "$ZIP_DIR/$zipsubdir/$EMULATOR_ARCHIVE" pushd "$ZIP_DIR/$zipsubdir" - sha256sum "$EMULATOR_ARCHIVE" > "$EMULATOR_ARCHIVE.sha256sum" + sha256sum "$EMULATOR_ARCHIVE" >"$EMULATOR_ARCHIVE.sha256sum" popd fi @@ -444,16 +601,16 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then # Remove old zips and logs if [ "$DELETE_OLD_ZIPS" -gt "0" ]; then if [ "$ZIP_SUBDIR" = true ]; then - /usr/bin/python /root/clean_up.py -n "$DELETE_OLD_ZIPS" -V "$los_ver" -N 1 "$ZIP_DIR/$zipsubdir" + /usr/bin/python /root/clean_up.py -n "$DELETE_OLD_ZIPS" -V "$e_ver" -N 1 "$ZIP_DIR/$zipsubdir" else - /usr/bin/python /root/clean_up.py -n "$DELETE_OLD_ZIPS" -V "$los_ver" -N 1 -c "${DEVICE}" "$ZIP_DIR" + /usr/bin/python /root/clean_up.py -n "$DELETE_OLD_ZIPS" -V "$e_ver" -N 1 -c "${DEVICE}" "$ZIP_DIR" fi fi if [ "$DELETE_OLD_LOGS" -gt "0" ]; then if [ "$LOGS_SUBDIR" = true ]; then - /usr/bin/python /root/clean_up.py -n "$DELETE_OLD_LOGS" -V "$los_ver" -N 1 "$LOGS_DIR/$logsubdir" + /usr/bin/python /root/clean_up.py -n "$DELETE_OLD_LOGS" -V "$e_ver" -N 1 "$LOGS_DIR/$logsubdir" else - /usr/bin/python /root/clean_up.py -n "$DELETE_OLD_LOGS" -V "$los_ver" -N 1 -c "${DEVICE}" "$LOGS_DIR" + /usr/bin/python /root/clean_up.py -n "$DELETE_OLD_LOGS" -V "$e_ver" -N 1 -c "${DEVICE}" "$LOGS_DIR" fi fi if [ -f /root/userscripts/post-build.sh ]; then diff --git a/src/init.sh b/src/init.sh index c482d48678c8432b220b900f1803a3e72155021f..63f5495eb58c358ce6e7f4d607d221ca3d3c89d8 100755 --- a/src/init.sh +++ b/src/init.sh @@ -37,7 +37,7 @@ if [ "$SIGN_BUILDS" = true ]; then echo ">> [$(date)] SIGN_BUILDS = true but empty \$KEYS_DIR, generating new keys" for c in releasekey platform shared media networkstack; do echo ">> [$(date)] Generating $c..." - /root/make_key "$KEYS_DIR/$c" "$KEYS_SUBJECT" <<< '' &> /dev/null + /root/make_key "$KEYS_DIR/$c" "$KEYS_SUBJECT" <<<'' &>/dev/null done else for c in releasekey platform shared media networkstack; do @@ -52,7 +52,7 @@ if [ "$SIGN_BUILDS" = true ]; then for c in cyngn{-priv,}-app testkey; do for e in pk8 x509.pem; do - ln -s releasekey.$e "$KEYS_DIR/$c.$e" 2> /dev/null + ln -s releasekey.$e "$KEYS_DIR/$c.$e" 2>/dev/null done done fi @@ -62,9 +62,9 @@ if [ "$CRONTAB_TIME" = "now" ]; then else # Initialize the cronjob cronFile=/tmp/buildcron - printf "SHELL=/bin/bash\n" > $cronFile - printenv -0 | sed -e 's/=\x0/=""\n/g' | sed -e 's/\x0/\n/g' | sed -e "s/_=/PRINTENV=/g" >> $cronFile - printf '\n%s /usr/bin/flock -n /var/lock/build.lock /root/build.sh >> /var/log/docker.log 2>&1\n' "$CRONTAB_TIME">> $cronFile + printf "SHELL=/bin/bash\n" >$cronFile + printenv -0 | sed -e 's/=\x0/=""\n/g' | sed -e 's/\x0/\n/g' | sed -e "s/_=/PRINTENV=/g" >>$cronFile + printf '\n%s /usr/bin/flock -n /var/lock/build.lock /root/build.sh >> /var/log/docker.log 2>&1\n' "$CRONTAB_TIME" >>$cronFile crontab $cronFile rm $cronFile