diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/.github/workflows/build-on-schedule.yml b/.github/workflows/build-on-schedule.yml index 6c628ef..f57f094 100644 --- a/.github/workflows/build-on-schedule.yml +++ b/.github/workflows/build-on-schedule.yml @@ -11,6 +11,7 @@ jobs: runs-on: ubuntu-latest outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} + id: ${{ steps.create_release.outputs.id }} steps: - name: Determine tag name id: get_tag_name @@ -58,32 +59,46 @@ jobs: - name: Download latest OTA build for ${{ matrix.device_name }} run: ./download_latest_ota_build.sh ${{ matrix.device_name }} - - name: Extract images and build props + - name: Extract images and build id: extract_and_build run: ./extract_images.sh - - name: Prepare for upload - id: prepare - run: | - mkdir -p result - - BASE_NAME=${{ steps.extract_and_build.outputs.DEVICE_CODE_NAME_TITLE }}.A${{ steps.extract_and_build.outputs.DEVICE_BUILD_ANDROID_VERSION }}.$(echo ${{ steps.extract_and_build.outputs.DEVICE_BUILD_SECURITY_PATCH }} | sed 's/-//g') - - cp ./**/**/{system,module}.prop result/ - cp -r ./magisk_module_files/* result/ - - cd result - zip -r ../$BASE_NAME.zip . - cd .. - - echo "base_name=$BASE_NAME" >> $GITHUB_OUTPUT - - name: Upload files to release uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.prepare_build.outputs.upload_url }} - asset_path: ./${{ steps.prepare.outputs.base_name }}.zip - asset_name: ${{ steps.prepare.outputs.base_name }}.zip - asset_content_type: application/zip \ No newline at end of file + asset_path: ./${{ steps.extract_and_build.outputs.module_base_name }}.zip + asset_name: ${{ steps.extract_and_build.outputs.module_base_name }}.zip + asset_content_type: application/zip + + - name: Add information to release + uses: irongut/EditRelease@v1.2.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + id: ${{ needs.prepare_build.outputs.id }} + replacebody: false + body: | + ## ${{ steps.extract_and_build.outputs.device_name }} (${{ steps.extract_and_build.outputs.device_code_name_title }}) + #### Module + - File name: `${{ steps.extract_and_build.outputs.module_base_name }}.zip` + - File hash (SHA256): `${{ steps.extract_and_build.outputs.module_hash }}` + #### Firmware + - Build ID: `${{ steps.extract_and_build.outputs.device_build_id }}` + - Android version: `${{ steps.extract_and_build.outputs.device_build_android_version }}` + - Security patch: `${{ steps.extract_and_build.outputs.device_build_security_patch }}` + + - name: Send to Telegram + run: | + { + echo '${{ steps.extract_and_build.outputs.device_name }} - ${{ steps.extract_and_build.outputs.device_code_name_title }}'; + echo 'Security Patch: `${{ steps.extract_and_build.outputs.device_build_security_patch }}`'; + echo 'ID: `${{ steps.extract_and_build.outputs.device_build_id }}`'; + } > .tg_caption + + curl -X POST "https://api.telegram.org/bot${{ secrets.BOT_TOKEN }}/sendDocument" \ + -H "Content-Type: multipart/form-data" \ + -F "chat_id=${{ secrets.CHANNEL_ID }}" \ + -F "document=@${{ steps.extract_and_build.outputs.module_base_name }}.zip;type=application/zip" \ + -F "caption=$(cat .tg_caption)" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 23c167c..f810b5b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,29 +64,13 @@ jobs: - name: Download latest OTA build for ${{ github.event.inputs.device_name }} run: ./download_latest_ota_build.sh ${{ github.event.inputs.device_name }} - - name: Extract images and build props + - name: Extract images and build id: extract_and_build run: ./extract_images.sh - - name: Prepare for upload - id: prepare - run: | - mkdir -p result - - BASE_NAME=${{ steps.extract_and_build.outputs.DEVICE_CODE_NAME_TITLE }}.A${{ steps.extract_and_build.outputs.DEVICE_BUILD_ANDROID_VERSION }}.$(echo ${{ steps.extract_and_build.outputs.DEVICE_BUILD_SECURITY_PATCH }} | sed 's/-//g') - - cp ./**/**/{system,module}.prop result/ - cp -r ./magisk_module_files/* result/ - - cd result - zip -r ../$BASE_NAME.zip . - cd .. - - echo "base_name=$BASE_NAME" >> $GITHUB_OUTPUT - - name: Upload artifacts uses: actions/upload-artifact@v3 with: - name: ${{ steps.prepare.outputs.base_name }} + name: ${{ steps.extract_and_build.outputs.module_base_name }} path: result if-no-files-found: error diff --git a/README.md b/README.md index 54fa779..0c23db6 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ $ ./download_latest_ota_build.sh cheetah raven redfin - [x] Extract OTA images - [x] Build props - [x] Use of GitHub Actions to automate the update/commit/push/release process on schedule + - [ ] Previous release checker (to check for duplicates, via git notes) - [ ] Use of GitHub Actions to automate the release of props on the Telegram Channel - [ ] ~~Download latest factory image from [Google Android Images](https://developers.google.com/android/images)~~ diff --git a/build_magisk_module.sh b/build_magisk_module.sh new file mode 100644 index 0000000..b48a53a --- /dev/null +++ b/build_magisk_module.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# Using util_functions.sh +[ -f "util_functions.sh" ] && . ./util_functions.sh || { echo "util_functions.sh not found" && exit 1; } + +# Load data from script base path if no directory were specified +[ -n "$1" ] && dir=$1 || { + for dir in ./*; do # List directory ./* + if [ -d "$dir" ]; then # Check if it is a directory + dir=${dir%*/} # Remove last / + print_message "Processing \"${dir##*/}\"" debug + + # Build system.prop + ./"${BASH_SOURCE[0]}" "$dir" + fi + done + exit 1 +} + +vendor_path="$dir/extracted/vendor/build.prop" +system_path="$dir/extracted/system/system/build.prop" + +device_name=$(grep_prop "ro.product.vendor.model" "$vendor_path") +device_build_id=$(grep_prop "ro.build.id" "$system_path") +device_code_name=$(grep_prop "ro.product.vendor.name" "$vendor_path") +device_code_name_title=${device_code_name^} +device_build_android_version=$(grep_prop "ro.vendor.build.version.release" "$vendor_path") +device_build_security_patch=$(grep_prop "ro.vendor.build.security_patch" "$vendor_path") + +mkdir -p result + +base_name=$device_code_name_title.A$device_build_android_version.$(echo "$device_build_security_patch" | sed 's/-//g') +subdir=$(basename "$dir") + +mkdir -p "result/$subdir" +cp "$dir/{module,system}.prop" "result/$subdir/" +cp -r ./magisk_module_files/* "result/$subdir/" + +cd "result/$subdir" || exit 1 +zip -r "../../$base_name.zip" . +cd ../.. + +print_message "Module saved to $base_name.zip" info + +# IMPORTANT: This will save the latest build's (last directory the shell loops thru) base name +# This won't be a problem for GitHub Actions as we have different instances running for each build +if [ -n "$GITHUB_OUTPUT" ]; then + { + echo "module_base_name=$base_name" ; + echo "module_hash=$(sha256sum "$base_name.zip" | awk '{print $1}')"; + echo "device_name=$device_name"; + echo "device_code_name_title=$device_code_name_title"; + echo "device_build_id=$device_build_id"; + echo "device_build_android_version=$device_build_android_version"; + echo "device_build_security_patch=$device_build_security_patch"; + } >> "$GITHUB_OUTPUT" +fi diff --git a/build_props.sh b/build_props.sh index ea51419..0b86b95 100644 --- a/build_props.sh +++ b/build_props.sh @@ -4,7 +4,7 @@ [ -f "util_functions.sh" ] && . ./util_functions.sh || { echo "util_functions.sh not found" && exit 1; } # Build props from script base path if no directory were specified -[ ! -z $1 ] && dir=$1 || { +[ -n "$1" ] && dir=$1 || { for dir in ./*; do # List directory ./* if [ -d "$dir" ]; then # Check if it is a directory dir=${dir%*/} # Remove last / @@ -249,7 +249,6 @@ echo -n "${system_prop::-1}" >"$dir/system.prop" device_name=$(grep_prop "ro.product.vendor.model" "$vendor_path") device_build_description=$(grep_prop "ro.build.description" "$system_path") device_code_name=$(grep_prop "ro.product.vendor.name" "$vendor_path") -device_android_version=$(grep_prop "ro.vendor.build.version.release" "$vendor_path") device_build_security_patch=$(grep_prop "ro.vendor.build.security_patch" "$vendor_path") add_prop_as_ini to_module_prop "id" "${device_code_name^}_Prop" @@ -268,14 +267,8 @@ echo -n "${module_prop::-1}" >"$dir/module.prop" print_message "Built props for $device_name [$device_build_description]!" debug # Display saving location -print_message "Saved to \"${dir}/system.prop\"" info -print_message "Saved to \"${dir}/module.prop\"" info - -if ! [ -z $GITHUB_OUTPUT ]; then - echo "DEVICE_NAME=$device_name" >> $GITHUB_OUTPUT - echo "DEVICE_BUILD_DESCRIPTION=$device_build_description" >> $GITHUB_OUTPUT - echo "DEVICE_CODE_NAME=$device_code_name" >> $GITHUB_OUTPUT - echo "DEVICE_CODE_NAME_TITLE=${device_code_name^}" >> $GITHUB_OUTPUT - echo "DEVICE_BUILD_ANDROID_VERSION=$device_android_version" >> $GITHUB_OUTPUT - echo "DEVICE_BUILD_SECURITY_PATCH=$device_build_security_patch" >> $GITHUB_OUTPUT -fi \ No newline at end of file +print_message "Props saved to \"${dir}\"" info + +# Build Magisk module +print_message "\nBuilding Magisk module...\n" info +./build_magisk_module.sh "$dir" diff --git a/download_latest_ota_build.sh b/download_latest_ota_build.sh index b1ca992..47cbf88 100644 --- a/download_latest_ota_build.sh +++ b/download_latest_ota_build.sh @@ -11,8 +11,8 @@ fi print_message "Downloading OTA builds for the following devices: $(IFS=, ; echo "${@[*]}")..." info # Get download link from the latest build that is not mobile carrier restricted {33} chars to be expected. -for device_name in "${@}"; do # Allow multiple arguments - last_build_url=$(curl -Ls 'https://developers.google.cn/android/ota?partial=1' | grep -Eo "\"(\S+$device_name\S{33})?zip" | tail -1 | tr -d \") +for device_name in "$@"; do # Allow multiple arguments + last_build_url=$(curl -Ls 'https://developers.google.cn/android/ota?partial=1' | grep -Eo "\"(\S+${device_name}\S{33})?zip" | tail -1 | tr -d \") print_message "Downloading OTA build for ${device_name^} (\"$last_build_url\")..." debug wget --tries=inf --show-progress -q "$last_build_url" done diff --git a/magisk_module_files/customize.sh b/magisk_module_files/customize.sh index c580ddf..c819aa6 100644 --- a/magisk_module_files/customize.sh +++ b/magisk_module_files/customize.sh @@ -1,42 +1,47 @@ +#!/sbin/sh + # Module variables -SYS_PROP_MANUFACTURER=`grep_prop ro.product.system.manufacturer` -MOD_PROP_MANUFACTURER=`grep_prop ro.product.system.manufacturer $MODPATH/system.prop` -MOD_PROP_MODEL=`grep_prop ro.product.model $MODPATH/system.prop` -MOD_PROP_PRODUCT=`grep_prop ro.build.product $MODPATH/system.prop | tr '[:lower:]' '[:upper:]'` -MOD_PROP_VERSION=`grep_prop ro.build.version.release $MODPATH/system.prop` -MOD_PROP_SECURITYPATCH=`grep_prop ro.build.version.security_patch $MODPATH/system.prop` -MOD_PROP_VERSIONCODE=`date -d $MOD_PROP_SECURITYPATCH '+%y%m%d'` -MOD_PROP_MONTH=`date -d $MOD_PROP_SECURITYPATCH '+%B'` -MOD_PROP_YEAR=`date -d $MOD_PROP_SECURITYPATCH '+%Y'` +SYS_PROP_MANUFACTURER=$(grep_prop ro.product.system.manufacturer) +MOD_PROP_MANUFACTURER=$(grep_prop ro.product.system.manufacturer "$MODPATH/system.prop") +MOD_PROP_MODEL=$(grep_prop ro.product.model "$MODPATH/system.prop") +MOD_PROP_PRODUCT=$(grep_prop ro.build.product "$MODPATH/system.prop" | tr '[:lower:]' '[:upper:]') +MOD_PROP_VERSION=$(grep_prop ro.build.version.release "$MODPATH/system.prop") +MOD_PROP_SECURITYPATCH=$(grep_prop ro.build.version.security_patch "$MODPATH"/system.prop) +MOD_PROP_VERSIONCODE=$(date -d "$MOD_PROP_SECURITYPATCH" '+%y%m%d') +MOD_PROP_MONTH=$(date -d "$MOD_PROP_SECURITYPATCH" '+%B') +MOD_PROP_YEAR=$(date -d "$MOD_PROP_SECURITYPATCH" '+%Y') # Print head message ui_print "- Installing, $MOD_PROP_MODEL ($MOD_PROP_PRODUCT) Prop - $MOD_PROP_MONTH $MOD_PROP_YEAR" # Checking if the system sdk matches the module sdk -MOD_API=`grep_prop ro.build.version.sdk $MODPATH/system.prop | grep -ohE '[0-9]{2}'` +MOD_API=$(grep_prop ro.build.version.sdk "$MODPATH/system.prop" | grep -ohE '[0-9]{2}') -# Make sure device manufacturer was not disturbed +# Make sure device manufacturer was not disturbed # in order to fix few apps such as camera on Xiaomi devices -if [ $SYS_PROP_MANUFACTURER == $MOD_PROP_MANUFACTURER ]; then +if [ "$SYS_PROP_MANUFACTURER" = "$MOD_PROP_MANUFACTURER" ]; then ui_print "- MANUFACTURER=$SYS_PROP_MANUFACTURER, running unsafe mode" else - sed -i 's/^ro.product.system.manufacturer/# ro.product.system.manufacturer/' $MODPATH/system.prop + sed -i 's/^ro.product.system.manufacturer/# ro.product.system.manufacturer/' "$MODPATH"/system.prop ui_print "- MANUFACTURER=$SYS_PROP_MANUFACTURER, running safe mode" fi # Make sure device API matches the one on the prop in order to avoid bootloop -if [ $API -gt $MOD_API ]; then +if [ "$API" -gt "$MOD_API" ]; then ui_print "- SDK=$API, running unsafe mode" else - sed -i 's/^ro.build.version.sdk/# ro.build.version.sdk/' $MODPATH/system.prop + sed -i 's/^ro.build.version.sdk/# ro.build.version.sdk/' "$MODPATH"/system.prop ui_print "- SDK=$API, running safe mode" fi # Remove comments from files and place them, add blank line to end if not already present # Scripts -for i in $(find $MODPATH -type f -name "*.sh" -o -name "*.prop" -o -name "*.rule"); do - [ -f $i ] && { sed -i -e "/^#/d" -e "/^ *$/d" $i; [ "$(tail -1 $i)" ] && echo "" >> $i; } || continue +for i in $(find "$MODPATH" -type f -name "*.sh" -o -name "*.prop" -o -name "*.rule"); do + [ -f "$i" ] && { + sed -i -e "/^#/d" -e "/^ *$/d" "$i" + [ "$(tail -1 "$i")" ] && echo "" >>"$i" + } || continue done # Print footer message -ui_print "- Script by Tesla, Telegram: @T3SL4" \ No newline at end of file +ui_print "- Script by Tesla, Telegram: @T3SL4" diff --git a/requirements.sh b/requirements.sh index d75b01e..96bc700 100644 --- a/requirements.sh +++ b/requirements.sh @@ -7,7 +7,7 @@ declare IMAGES2EXTRACT=("product" "vendor" "system" "system_ext") # Make sure zip is installed if ! hash zip 2>/dev/null; then - print_message "zip was not found, you can run \"apt install zip\" in order to install it." error + print_message "zip was not found, you can run \"apt install zip\" in order to install it." error exit fi