Skip to content

Commit

Permalink
Merge pull request #4 from PalmDevs/upstream-main
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
0x11DFE authored Sep 27, 2023
2 parents 1d9e5f9 + 607ff1c commit 224c020
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 74 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

55 changes: 35 additions & 20 deletions .github/workflows/build-on-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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/[email protected]
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)"
20 changes: 2 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)~~

Expand Down
57 changes: 57 additions & 0 deletions build_magisk_module.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 6 additions & 13 deletions build_props.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 /
Expand Down Expand Up @@ -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"
Expand All @@ -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
print_message "Props saved to \"${dir}\"" info

# Build Magisk module
print_message "\nBuilding Magisk module...\n" info
./build_magisk_module.sh "$dir"
4 changes: 2 additions & 2 deletions download_latest_ota_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 23 additions & 18 deletions magisk_module_files/customize.sh
Original file line number Diff line number Diff line change
@@ -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"
ui_print "- Script by Tesla, Telegram: @T3SL4"
2 changes: 1 addition & 1 deletion requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 224c020

Please sign in to comment.