Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d527605 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

build: Sign apex files while building

parent 7fbec968
Loading
Loading
Loading
Loading
+93 −27
Original line number Original line Diff line number Diff line
@@ -173,9 +173,22 @@ for branch in ${BRANCH_NAME//,/ }; do
      exit 1
      exit 1
    fi
    fi


    los_ver_major=$(sed -n -e 's/^\s*PRODUCT_VERSION_MAJOR = //p' "vendor/$vendor/config/common.mk")
    config_file="vendor/$vendor/config/version.mk"
    los_ver_minor=$(sed -n -e 's/^\s*PRODUCT_VERSION_MINOR = //p' "vendor/$vendor/config/common.mk")
    if [ ! -f "$config_file" ]; then
    los_ver="$los_ver_major.$los_ver_minor"
      # 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"
    echo ">> [$(date)] Setting \"$RELEASE_TYPE\" as release type"
    sed -i "/\$(filter .*\$(${vendor^^}_BUILDTYPE)/,+2d" "vendor/$vendor/config/common.mk"
    sed -i "/\$(filter .*\$(${vendor^^}_BUILDTYPE)/,+2d" "vendor/$vendor/config/common.mk"
@@ -202,19 +215,23 @@ for branch in ${BRANCH_NAME//,/ }; do
      echo ">> [$(date)] Adding keys path ($KEYS_DIR)"
      echo ">> [$(date)] Adding keys path ($KEYS_DIR)"
      # Soong (Android 9+) complains if the signing keys are outside the build path
      # Soong (Android 9+) complains if the signing keys are outside the build path
      ln -sf "$KEYS_DIR" user-keys
      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
    # Remove build number and date on builds.
        sed -i "1s;^;PRODUCT_DEFAULT_DEV_CERTIFICATE := user-keys/releasekey\nPRODUCT_OTA_PUBLIC_KEYS := user-keys/releasekey\n\n;" "vendor/$vendor/config/common.mk"
    if [ -f out/build_date.txt ]; then
      rm out/build_date.txt
    fi
    fi
    if [ -f out/soong/build_number.txt ]; then
      rm out/soong/build_number.txt
    fi
    fi


    # Prepare the environment
    # Prepare the environment
    echo ">> [$(date)] Preparing build 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
    if [ -f /root/userscripts/before.sh ]; then
      echo ">> [$(date)] Running before.sh"
      echo ">> [$(date)] Running before.sh"
      /root/userscripts/before.sh
      /root/userscripts/before.sh
@@ -276,7 +293,7 @@ for branch in ${BRANCH_NAME//,/ }; do
          logsubdir=
          logsubdir=
        fi
        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
        if [ -f /root/userscripts/pre-build.sh ]; then
          echo ">> [$(date)] Running pre-build.sh for $codename" >>"$DEBUG_LOG"
          echo ">> [$(date)] Running pre-build.sh for $codename" >>"$DEBUG_LOG"
@@ -299,13 +316,59 @@ for branch in ${BRANCH_NAME//,/ }; do
        echo ">> [$(date)] Switch to Python2"
        echo ">> [$(date)] Switch to Python2"
        ln -fs /usr/bin/python2 /usr/bin/python
        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}
        BRUNCH_DEVICE=${codename}


        if [ "${ENG_BUILD}" = true ]; then
        if [ "${ENG_BUILD}" = true ]; then
          BRUNCH_DEVICE=lineage_${codename}-eng
          BRUNCH_DEVICE=lineage_${codename}-eng
        fi
        fi


        if brunch ${BRUNCH_DEVICE} &>>"$DEBUG_LOG"; then
        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

          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)
            currentdate=$(date +%Y%m%d)
            if [ "$builddate" != "$currentdate" ]; then
            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"
              find out/target/product/$codename -maxdepth 1 -name "e-*-$currentdate-*.zip*" -type f -exec sh /root/fix_build_date.sh {} $currentdate $builddate \; &>>"$DEBUG_LOG"
@@ -320,6 +383,9 @@ for branch in ${BRANCH_NAME//,/ }; do
            find . -maxdepth 1 -name 'e-*.zip*' -type f -exec mv {} "$ZIP_DIR/$zipsubdir/" \; &>>"$DEBUG_LOG"
            find . -maxdepth 1 -name 'e-*.zip*' -type f -exec mv {} "$ZIP_DIR/$zipsubdir/" \; &>>"$DEBUG_LOG"
            cd "$source_dir"
            cd "$source_dir"
            build_successful=true
            build_successful=true
          else
            echo ">> [$(date)] Unable to find $TARGET_FILES" | tee -a "$DEBUG_LOG"
          fi
        else
        else
          echo ">> [$(date)] Failed build for $codename" | tee -a "$DEBUG_LOG"
          echo ">> [$(date)] Failed build for $codename" | tee -a "$DEBUG_LOG"
        fi
        fi
@@ -327,16 +393,16 @@ for branch in ${BRANCH_NAME//,/ }; do
        # Remove old zips and logs
        # Remove old zips and logs
        if [ "$DELETE_OLD_ZIPS" -gt "0" ]; then
        if [ "$DELETE_OLD_ZIPS" -gt "0" ]; then
          if [ "$ZIP_SUBDIR" = true ]; 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
          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
        fi
        fi
        if [ "$DELETE_OLD_LOGS" -gt "0" ]; then
        if [ "$DELETE_OLD_LOGS" -gt "0" ]; then
          if [ "$LOGS_SUBDIR" = true ]; 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
          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
        fi
        fi
        if [ -f /root/userscripts/post-build.sh ]; then
        if [ -f /root/userscripts/post-build.sh ]; then

src/apex.list

0 → 100644
+50 −0
Original line number Original line Diff line number Diff line
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
+116 −32
Original line number Original line Diff line number Diff line
@@ -159,27 +159,44 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then
    exit 1
    exit 1
  fi
  fi


  los_ver_major=$(sed -n -e 's/^\s*PRODUCT_VERSION_MAJOR = //p' "vendor/$vendor/config/common.mk")
  config_file="vendor/lineage/config/version.mk"
  los_ver_minor=$(sed -n -e 's/^\s*PRODUCT_VERSION_MINOR = //p' "vendor/$vendor/config/common.mk")
  if [ ! -f "$config_file" ]; then
  los_ver="$los_ver_major.$los_ver_minor"
    # 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
  if [ "$SIGN_BUILDS" = true ]; then
    echo ">> [$(date)] Adding keys path ($KEYS_DIR)"
    echo ">> [$(date)] Adding keys path ($KEYS_DIR)"
    # Soong (Android 9+) complains if the signing keys are outside the build path
    # Soong (Android 9+) complains if the signing keys are outside the build path
    ln -sf "$KEYS_DIR" user-keys
    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
  # Remove build number and date on builds.
      sed -i "1s;^;PRODUCT_DEFAULT_DEV_CERTIFICATE := user-keys/releasekey\nPRODUCT_OTA_PUBLIC_KEYS := user-keys/releasekey\n\n;" "vendor/$vendor/config/common.mk"
  if [ -f out/build_date.txt ]; then
    rm out/build_date.txt
  fi
  fi
  if [ -f out/soong/build_number.txt ]; then
    rm out/soong/build_number.txt
  fi
  fi


  # Prepare the environment
  # Prepare the environment
  echo ">> [$(date)] Preparing build 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
  if [ -f /root/userscripts/before.sh ]; then
    echo ">> [$(date)] Running before.sh"
    echo ">> [$(date)] Running before.sh"
    /root/userscripts/before.sh
    /root/userscripts/before.sh
@@ -249,6 +266,16 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then
      BRUNCH_DEVICE=lineage_${DEVICE}-userdebug
      BRUNCH_DEVICE=lineage_${DEVICE}-userdebug
    fi
    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
    build_success=false
    if [ "${BUILD_ONLY_SYSTEMIMAGE}" = true ]; then
    if [ "${BUILD_ONLY_SYSTEMIMAGE}" = true ]; then
      breakfast "${BRUNCH_DEVICE}"
      breakfast "${BRUNCH_DEVICE}"
@@ -259,12 +286,70 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then
      if lunch "${BRUNCH_DEVICE}" && mka sdk_addon; then
      if lunch "${BRUNCH_DEVICE}" && mka sdk_addon; then
        build_success=true
        build_success=true
      fi
      fi
    elif [ "${BUILD_SUPER_IMAGE}" = true ]; then
    elif breakfast "${BRUNCH_DEVICE}"; then
      if breakfast "${BRUNCH_DEVICE}" && mka bacon superimage; then
      mka target-files-package otatools
        build_success=true
      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

      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
      fi
    elif brunch "${BRUNCH_DEVICE}"; then

      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

        if [ -f "$OUT/super_empty.img" ]; then
          build_super_image "$OUT/$TARGET_FILES" "$OUT/super.img"
        fi

        build_success=true
        build_success=true
      else
        echo ">> [$(date)] Unable to find $TARGET_FILES"
      fi
    fi
    fi


    if [ "$build_success" = true ]; then
    if [ "$build_success" = true ]; then
@@ -277,7 +362,6 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then
      echo ">> [$(date)] Moving build artifacts for ${DEVICE} to '$ZIP_DIR/$zipsubdir'"
      echo ">> [$(date)] Moving build artifacts for ${DEVICE} to '$ZIP_DIR/$zipsubdir'"
      cd "${OUT}" || return 1
      cd "${OUT}" || return 1
      for build in $(ls e-*.zip); do
      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/" \;
        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"
        SKIP_DYNAMIC_IMAGES="odm.img product.img system.img system_ext.img vendor.img"
@@ -305,7 +389,7 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then
          cd "${OUT}" || return 1
          cd "${OUT}" || return 1
        fi
        fi
        if [ "$BACKUP_INTERMEDIATE_SYSTEM_IMG" = true ]; then
        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
          zip "$ZIP_DIR/$zipsubdir/IMG-$build" system.img
          cd $ZIP_DIR/$zipsubdir
          cd $ZIP_DIR/$zipsubdir
          sha256sum "IMG-$build" >"IMG-$build.sha256sum"
          sha256sum "IMG-$build" >"IMG-$build.sha256sum"
@@ -326,36 +410,36 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then
          if [ "$RECOVERY_NEEDS_SUPPORT_IMG" = true ]; then
          if [ "$RECOVERY_NEEDS_SUPPORT_IMG" = true ]; then
            # Copy the files specified by the flags
            # Copy the files specified by the flags
            if [ "$RECOVERY_NEEDS_BOOT_IMG" = true ]; then
            if [ "$RECOVERY_NEEDS_BOOT_IMG" = true ]; then
              cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/boot.img "$BOOT_IMG_NAME"
              mv $OUT/boot.img "$BOOT_IMG_NAME"
              sha256sum "$BOOT_IMG_NAME" >"$BOOT_IMG_NAME.sha256sum"
              sha256sum "$BOOT_IMG_NAME" >"$BOOT_IMG_NAME.sha256sum"
            fi
            fi
            if [ "$RECOVERY_NEEDS_DTBO_IMG" = true ]; then
            if [ "$RECOVERY_NEEDS_DTBO_IMG" = true ]; then
              cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/dtbo.img "$DTBO_IMG_NAME"
              cmv $OUT/dtbo.img "$DTBO_IMG_NAME"
              sha256sum "$DTBO_IMG_NAME" >"$DTBO_IMG_NAME.sha256sum"
              sha256sum "$DTBO_IMG_NAME" >"$DTBO_IMG_NAME.sha256sum"
            fi
            fi
            if [ "$RECOVERY_NEEDS_VBMETA_IMG" = true ]; then
            if [ "$RECOVERY_NEEDS_VBMETA_IMG" = true ]; then
              cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/vbmeta.img "$VBMETA_IMG_NAME"
              mv $OUT/vbmeta.img "$VBMETA_IMG_NAME"
              sha256sum "$VBMETA_IMG_NAME" >"$VBMETA_IMG_NAME.sha256sum"
              sha256sum "$VBMETA_IMG_NAME" >"$VBMETA_IMG_NAME.sha256sum"
            fi
            fi
            if [ "$RECOVERY_NEEDS_VENDOR_BOOT_IMG" = true ]; then
            if [ "$RECOVERY_NEEDS_VENDOR_BOOT_IMG" = true ]; then
              cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/vendor_boot.img "$VENDOR_BOOT_IMG_NAME"
              mv $OUT/vendor_boot.img "$VENDOR_BOOT_IMG_NAME"
              sha256sum "$VENDOR_BOOT_IMG_NAME" >"$VENDOR_BOOT_IMG_NAME.sha256sum"
              sha256sum "$VENDOR_BOOT_IMG_NAME" >"$VENDOR_BOOT_IMG_NAME.sha256sum"
            fi
            fi
            if [ "$RECOVERY_NEEDS_SUPER_IMG" = true ]; then
            if [ "$RECOVERY_NEEDS_SUPER_IMG" = true ]; then
              cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/super_empty.img "$SUPER_EMPTY_IMG_NAME"
              mv $OUT/super_empty.img "$SUPER_EMPTY_IMG_NAME"
              sha256sum "$SUPER_EMPTY_IMG_NAME" >"$SUPER_EMPTY_IMG_NAME.sha256sum"
              sha256sum "$SUPER_EMPTY_IMG_NAME" >"$SUPER_EMPTY_IMG_NAME.sha256sum"
            fi
            fi
            if [ "$RECOVERY_NEEDS_VENDOR_KERNEL_BOOT_IMG" = true ]; then
            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"
              mv $OUT/vendor_kernel_boot.img "$VENDOR_KERNEL_BOOT_IMG_NAME"
              sha256sum "$VENDOR_KERNEL_BOOT_IMG_NAME" >"$VENDOR_KERNEL_BOOT_IMG_NAME.sha256sum"
              sha256sum "$VENDOR_KERNEL_BOOT_IMG_NAME" >"$VENDOR_KERNEL_BOOT_IMG_NAME.sha256sum"
            fi
            fi


            if [ "$VBOOT_IS_RECOVERY" = true ]; then
            if [ "$VBOOT_IS_RECOVERY" = true ]; then
              cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/vendor_boot.img "$RECOVERY_IMG_NAME"
              mv $OUT/vendor_boot.img "$RECOVERY_IMG_NAME"
            elif [ -f "recovery.img" ]; then
            elif [ -f "recovery.img" ]; then
              cp -a recovery.img "$RECOVERY_IMG_NAME"
              mv $OUT/recovery.img "$RECOVERY_IMG_NAME"
            else
            else
              cp -a boot.img "$RECOVERY_IMG_NAME"
              mv $OUT/boot.img "$RECOVERY_IMG_NAME"
            fi
            fi


            # Generate SHA256 checksum for RECOVERY_IMG_NAME
            # Generate SHA256 checksum for RECOVERY_IMG_NAME
@@ -394,11 +478,11 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then
            mv "$RECOVERY_ZIP_NAME"* "$ZIP_DIR/$zipsubdir/"
            mv "$RECOVERY_ZIP_NAME"* "$ZIP_DIR/$zipsubdir/"
          else
          else
            if [ "$VBOOT_IS_RECOVERY" = true ]; then
            if [ "$VBOOT_IS_RECOVERY" = true ]; then
              cp -a obj/PACKAGING/target_files_intermediates/lineage_*/IMAGES/vendor_boot.img "$RECOVERY_IMG_NAME"
              mv $OUT/vendor_boot.img "$RECOVERY_IMG_NAME"
            elif [ -f "recovery.img" ]; then
            elif [ -f "recovery.img" ]; then
              cp -a recovery.img "$RECOVERY_IMG_NAME"
              mv $OUT/recovery.img "$RECOVERY_IMG_NAME"
            else
            else
              cp -a boot.img "$RECOVERY_IMG_NAME"
              mv $OUT/boot.img "$RECOVERY_IMG_NAME"
            fi
            fi


            # Calculate sha256sum and move file
            # Calculate sha256sum and move file
@@ -412,7 +496,7 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then
      if [ "${BUILD_ONLY_SYSTEMIMAGE}" = true ]; then
      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
        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
          zip "$ZIP_DIR/$zipsubdir/IMG-$build" system.img
          cd $ZIP_DIR/$zipsubdir
          cd $ZIP_DIR/$zipsubdir
          sha256sum "IMG-$build" >"IMG-$build.sha256sum"
          sha256sum "IMG-$build" >"IMG-$build.sha256sum"
@@ -440,16 +524,16 @@ if [ -n "${BRANCH_NAME}" ] && [ -n "${DEVICE}" ]; then
    # Remove old zips and logs
    # Remove old zips and logs
    if [ "$DELETE_OLD_ZIPS" -gt "0" ]; then
    if [ "$DELETE_OLD_ZIPS" -gt "0" ]; then
      if [ "$ZIP_SUBDIR" = true ]; 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
      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
    fi
    fi
    if [ "$DELETE_OLD_LOGS" -gt "0" ]; then
    if [ "$DELETE_OLD_LOGS" -gt "0" ]; then
      if [ "$LOGS_SUBDIR" = true ]; 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
      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
    fi
    fi
    if [ -f /root/userscripts/post-build.sh ]; then
    if [ -f /root/userscripts/post-build.sh ]; then