This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
Check firmware update #265
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check firmware update | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 12 * * *" | |
push: | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- model: "SM-A736B" | |
csc: "INS" | |
omc: "ODM" | |
- model: "SM-A736B" | |
csc: "EGY" | |
omc: "OJM" | |
- model: "SM-A736B" | |
csc: "XID" | |
omc: "OLE" | |
- model: "SM-A736B" | |
csc: "XME" | |
omc: "OLM" | |
- model: "SM-A736B" | |
csc: "ZTO" | |
omc: "OWO" | |
- model: "SM-A736B" | |
csc: "SEK" | |
omc: "OXE" | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@main | |
with: | |
submodules: true | |
- name: Compare latest version with current version | |
run: | | |
need_update=0 | |
latest=`curl --retry 5 --retry-delay 5 http://fota-cloud-dn.ospserver.net/firmware/${{ matrix.csc }}/${{ matrix.model }}/version.xml | grep latest | sed 's/^[^>]*>//' | sed 's/<.*//'` | |
latest_short=`echo $latest | cut -d'/' -f1` | |
latest_csc=`echo $latest | cut -d'/' -f2` | |
latest_modem=`echo $latest | cut -d'/' -f3` | |
current=`cat current.${{ matrix.model }}_${{ matrix.omc }}` || need_update=1 | |
[[ $latest != $current ]] && need_update=1 | |
echo "latest_version=$latest" >> $GITHUB_ENV | |
echo "latest_shortversion=$latest_short" >> $GITHUB_ENV | |
echo "latest_cscversion=$latest_csc" >> $GITHUB_ENV | |
echo "latest_modemversion=$latest_modem" >> $GITHUB_ENV | |
echo "need_update=$need_update" >> $GITHUB_ENV | |
- name: Set up Node.js | |
if: env.need_update == 1 | |
uses: actions/setup-node@main | |
with: | |
node-version: 'latest' | |
- name: Set up Python 3 | |
if: env.need_update == 1 | |
uses: actions/setup-python@main | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
if: env.need_update == 1 | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y liblz4-tool zip simg2img f2fs-tools | |
sudo wget -O /usr/bin/samfirm https://github.com/DavidArsene/samfirm.js/releases/download/v0.3.0/samfirm.js && sudo chmod +x /usr/bin/samfirm | |
- name: Fetch firmware | |
if: env.need_update == 1 | |
run: | | |
if [[ "${{ matrix.model }}" == "SM-A736B" ]]; then | |
imei="352828291234563" | |
else | |
imei="352828291234563" | |
fi | |
samfirm -m ${{ matrix.model }} -r ${{ matrix.csc }} -i $imei | |
- name: Get path of files | |
if: env.need_update == 1 | |
run: | | |
echo "ap_tar=`find -name AP*`" >> $GITHUB_ENV | |
echo "bl_tar=`find -name BL*`" >> $GITHUB_ENV | |
echo "cp_tar=`find -name CP*`" >> $GITHUB_ENV | |
echo "csc_tar=`find -name CSC*`" >> $GITHUB_ENV | |
echo "home_csc_tar=`find -name HOME_CSC*`" >> $GITHUB_ENV | |
- name: Check downloaded firmware version | |
if: env.need_update == 1 | |
run: | | |
version_short=`echo ${{ env.ap_tar }} | cut -d'_' -f3` | |
version_csc=`echo ${{ env.csc_tar }} | cut -d'_' -f4` | |
version_modem=`echo ${{ env.cp_tar }} | cut -d'_' -f3` | |
[[ $version_short == ${{ env.latest_shortversion }} ]] | |
[[ $version_csc == ${{ env.latest_cscversion }} ]] | |
[[ $version_modem == ${{ env.latest_modemversion }} ]] | |
echo PDA version: $version_short > versions.txt | |
echo CSC version: $version_csc >> versions.txt | |
echo Modem version: $version_modem >> versions.txt | |
- name: Cleanup space | |
if: env.need_update == 1 | |
run: | | |
sudo apt-get remove --purge -y "php*" "dotnet*" "mysql*" "nodejs*" "clang*" "google*" | |
sudo apt-get autoremove -y | |
sudo apt-get clean | |
sudo rm -rf /usr/local | |
- name: Extract kernel images | |
if: env.need_update == 1 | |
env: | |
FILES: boot.img.lz4 dtbo.img.lz4 vbmeta.img.lz4 vendor_boot.img.lz4 | |
run: | | |
for file in $FILES; do tar xvf ${{ env.ap_tar }} ${file}; done | |
tar cvf ${{ env.latest_shortversion }}_kernel.tar *.lz4 | |
rm *.lz4 | |
- name: Extract PIT file | |
if: env.need_update == 1 | |
run: | | |
tar --wildcards --exclude='*/*' -xvf ${{ env.csc_tar }} '*.pit' | |
echo "pit_file=`find -name *.pit`" >> $GITHUB_ENV | |
- name: Generate patched vbmeta | |
if: env.need_update == 1 | |
run: | | |
tar xvf ${{ env.ap_tar }} vbmeta.img.lz4 | |
lz4 -d vbmeta.img.lz4 vbmeta.img | |
rm vbmeta.img.lz4 | |
printf "$(printf '\\x%02X' 3)" | dd of="vbmeta.img" bs=1 seek=123 count=1 conv=notrunc &> /dev/null | |
tar cvf ${{ env.latest_shortversion }}_patched_vbmeta.tar vbmeta.img | |
rm vbmeta.img | |
- name: Extract vendor and vendor_dlkm partition | |
if: env.need_update == 1 | |
run: | | |
tar xvf ${{ env.ap_tar }} super.img.lz4 | |
lz4 -d super.img.lz4 super.img | |
rm super.img.lz4 | |
simg2img super.img super_raw.img | |
rm super.img | |
mv super_raw.img super.img | |
python3 tools/bin/lpunpack.py -p vendor,vendor_dlkm super.img . | |
rm super.img | |
[[ -e vendor.img ]] && zip ${{ env.latest_shortversion }}_vendor.zip vendor.img | |
[[ -e vendor.img ]] && rm vendor.img | |
- name: Update current version | |
if: env.need_update == 1 | |
run: | | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git pull origin ${{github.ref}} --ff-only | |
echo ${{ env.latest_version }} > current.${{ matrix.model }}_${{ matrix.omc }} | |
git add current.${{ matrix.model }}_${{ matrix.omc }} | |
git commit -m "${{ matrix.model }}: ${{ env.latest_version }}" | |
git tag "${{ env.latest_shortversion }}_${{ matrix.omc }}" | |
- name: Push changes to repo | |
if: env.need_update == 1 | |
uses: ad-m/github-push-action@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
tags: true | |
- name: Upload release assets | |
if: env.need_update == 1 | |
uses: softprops/action-gh-release@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
body_path: versions.txt | |
tag_name: "${{ env.latest_shortversion }}_${{ matrix.omc }}" | |
name: "${{ env.latest_shortversion }} - ${{ matrix.model }} - ${{ matrix.omc }}" | |
files: | | |
${{ env.bl_tar }} | |
${{ env.cp_tar }} | |
${{ env.home_csc_tar }} | |
${{ env.latest_shortversion }}_kernel.tar | |
${{ env.pit_file }} | |
${{ env.latest_shortversion }}_patched_vbmeta.tar | |
${{ env.latest_shortversion }}_vendor.zip | |
${{ env.latest_shortversion }}_vendor_dlkm.zip |