get_files #8
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: get_files | |
on: | |
workflow_dispatch: | |
inputs: | |
URL: | |
description: "下载地址(线刷包到tgz截止)" | |
required: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 检出仓库文件 | |
uses: actions/[email protected] | |
- name: 准备环境 | |
run: | | |
sudo timedatectl set-timezone Asia/Shanghai | |
if [[ "$URL" == *"CNXM"* ]]; then | |
URL="${URL/http:\/\/cdnorg.d.miui.com/https:\/\/bkt-sgp-miui-ota-update-alisgp.oss-ap-southeast-1.aliyuncs.com}" | |
fi | |
if [[ "$URL" == *"images"* ]]; then | |
device=$(echo "$URL" | cut -d"/" -f5 | cut -d"_" -f1) | |
ZIP_NAME=$(echo "$URL" | cut -d"/" -f5) | |
else | |
device=$(echo "$URL" | cut -d"_" -f2) | |
ZIP_NAME=$(echo "$URL" | sed 's/.*\(miui_.*\.zip\).*/\1/') | |
fi | |
echo "device=${device,,}" >> $GITHUB_ENV | |
echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV | |
echo "version=$(echo "$URL" | cut -d"/" -f4)" >> $GITHUB_ENV | |
sudo apt install aria2 p7zip-full tar | |
mkdir -p "$GITHUB_WORKSPACE"/get_files | |
sudo chmod -R 777 "$GITHUB_WORKSPACE"/tools | |
env: | |
URL: ${{ inputs.URL }} | |
- name: 下载系统包 | |
run: | | |
aria2c -x16 -j$(nproc) -U "Mozilla/5.0" -d "$GITHUB_WORKSPACE" "$URL" | |
env: | |
URL: ${{ inputs.URL }} | |
- name: 检测payload/br/线刷包 | |
run: | | |
if [[ "$ZIP_NAME" == *"images"* ]]; then | |
tar xvzf $ZIP_NAME -C "$GITHUB_WORKSPACE" | |
unpack_path="$(find "$GITHUB_WORKSPACE" -type d -name "*_images*")" | |
mv "$unpack_path" "$GITHUB_WORKSPACE"/$device | |
else | |
7z x "$GITHUB_WORKSPACE"/$ZIP_NAME -r -o"$GITHUB_WORKSPACE"/$device | |
fi | |
rm -rf "$GITHUB_WORKSPACE"/$ZIP_NAME | |
if [[ -e "$GITHUB_WORKSPACE"/$device/payload.bin ]]; then | |
echo "unpack=payload" >> $GITHUB_ENV | |
else | |
echo "unpack=br" >> $GITHUB_ENV | |
fi | |
if [[ "$ZIP_NAME" == *"images"* ]]; then | |
echo "unpack=flash" >> $GITHUB_ENV | |
fi | |
env: | |
URL: ${{ inputs.URL }} | |
- if: ${{ env.unpack == 'payload' }} | |
name: 解压payload | |
run: | | |
source unpack.sh | |
for i in $unpack_partiton; do | |
"$GITHUB_WORKSPACE"/tools/payload-dumper-go -o "$GITHUB_WORKSPACE"/$device/ -p $i "$GITHUB_WORKSPACE"/$device/payload.bin > /dev/null | |
done | |
- if: ${{ env.unpack == 'br' }} | |
name: 解压br | |
run: | | |
source unpack.sh | |
for i in $unpack_partiton; do | |
"$GITHUB_WORKSPACE"/tools/brotli -d "$GITHUB_WORKSPACE"/$device/$i.new.dat.br > /dev/null | |
rm -rf "$GITHUB_WORKSPACE"/$device/$i.new.dat.br | |
"$GITHUB_WORKSPACE"/tools/sdat2img "$GITHUB_WORKSPACE"/$device/$i.transfer.list "$GITHUB_WORKSPACE"/$device/$i.new.dat "$GITHUB_WORKSPACE"/$device/$i.img > /dev/null | |
rm -rf "$GITHUB_WORKSPACE"/$device/$i.patch.dat "$GITHUB_WORKSPACE"/$device/$i.transfer.list "$GITHUB_WORKSPACE"/$device/$i.new.dat | |
done | |
- if: ${{ env.unpack == 'flash' }} | |
name: 解压线刷包 | |
run: | | |
source unpack.sh | |
"$GITHUB_WORKSPACE"/tools/simg2img "$GITHUB_WORKSPACE"/$device/images/super.img "$GITHUB_WORKSPACE"/$device/super.img | |
rm -rf "$GITHUB_WORKSPACE"/$device/images/super.img | |
for i in $unpack_partiton; do | |
"$GITHUB_WORKSPACE"/tools/lpunpack -p "$i"_a "$GITHUB_WORKSPACE"/$device/super.img "$GITHUB_WORKSPACE"/$device | |
mv "$GITHUB_WORKSPACE"/$device/"$i"_a.img "$GITHUB_WORKSPACE"/$device/"$i".img | |
done | |
rm -rf "$GITHUB_WORKSPACE"/$device/super.img | |
- name: 解压img | |
run: | | |
source unpack.sh | |
for i in $unpack_partiton; do | |
if [[ $("$GITHUB_WORKSPACE"/tools/gettype -i "$GITHUB_WORKSPACE"/$device/$i.img) == "ext" ]]; then | |
sudo "$GITHUB_WORKSPACE"/tools/imgextractorLinux "$GITHUB_WORKSPACE"/$device/$i.img "$GITHUB_WORKSPACE"/$device > /dev/null | |
elif [[ $("$GITHUB_WORKSPACE"/tools/gettype -i "$GITHUB_WORKSPACE"/$device/$i.img) == "erofs" ]]; then | |
cd "$GITHUB_WORKSPACE"/$device && "$GITHUB_WORKSPACE"/tools/extract.erofs -i "$GITHUB_WORKSPACE"/$device/$i.img -x > /dev/null && cd "$GITHUB_WORKSPACE" | |
fi | |
rm -rf "$GITHUB_WORKSPACE"/$device/$i.img | |
done | |
- name: 提取指定文件 | |
run: | | |
source unpack.sh | |
extract_files | |
- name: 打包 | |
run: | | |
mkdir -p "$GITHUB_WORKSPACE"/zip | |
sudo chmod -R 777 "$GITHUB_WORKSPACE"/get_files | |
7z a "$GITHUB_WORKSPACE"/zip/"$device"_get_files.zip "$GITHUB_WORKSPACE"/get_files/* | |
mv "$GITHUB_WORKSPACE"/zip/"$device"_get_files.zip "$GITHUB_WORKSPACE"/zip/"$device"_"$version"_"$(date +"%Y-%m-%d_%H%M%S")".zip | |
cd "$GITHUB_WORKSPACE" | |
- name: 上传到Github Release | |
uses: ncipollo/release-action@main | |
with: | |
artifacts: ${{ github.workspace }}/zip/* | |
name: ${{ env.device }} | |
tag: ${{ env.device }} | |
bodyFile: "${{ github.workspace }}/info.txt" | |
allowUpdates: true | |
artifactErrorsFailBuild: true | |
token: ${{ secrets.GITHUB_TOKEN }} |