MikroTikPatch/.github/workflows/mikrotik_patch.yml

141 lines
5.7 KiB
YAML

name: Patch Mikrotik RouterOS
on:
# push:
# branches: [ "main" ]
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
permissions:
contents: write
jobs:
Patch_Mikrotik_RouterOS:
runs-on: ubuntu-latest
env:
TZ: 'Asia/Shanghai'
LATEST_STABLE_VERSION_URL: 'https://upgrade.mikrotik.com/routeros/NEWESTa7.stable'
LATEST_VERSION: "7.15"
CUSTOM_LICENSE_PRIVATE_KEY: ${{ secrets.CUSTOM_LICENSE_PRIVATE_KEY }}
CUSTOM_LICENSE_PUBLIC_KEY: ${{ secrets.CUSTOM_LICENSE_PUBLIC_KEY }}
CUSTOM_NPK_SIGN_PRIVATE_KEY: ${{ secrets.CUSTOM_NPK_SIGN_PRIVATE_KEY }}
CUSTOM_NPK_SIGN_PUBLIC_KEY: ${{ secrets.CUSTOM_NPK_SIGN_PUBLIC_KEY }}
MIKRO_LICENSE_PUBLIC_KEY: ${{ secrets.MIKRO_LICENSE_PUBLIC_KEY }}
MIKRO_NPK_SIGN_PUBLIC_LKEY: ${{ secrets.MIKRO_NPK_SIGN_PUBLIC_LKEY }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Get latest routeros stable version
run: |
echo $(uname -a)
LATEST_VERSION=$(wget -nv -O - $LATEST_STABLE_VERSION_URL | cut -d ' ' -f1)
echo Latest Stabel Version:$LATEST_VERSION
echo "LATEST_VERSION=${LATEST_VERSION}" >> $GITHUB_ENV
- name: Create keygen
run: |
zip keygen.zip ./keygen.exe
- name: Create squashfs for option npk
run: |
cd $GITHUB_WORKSPACE
sudo wget -O bash -nv https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/busybox_ASH
sudo wget -O busybox -nv https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/busybox
sudo chmod +x busybox
sudo chmod +x bash
sudo mkdir -p ./option-root/bin/
sudo mv busybox ./option-root/bin/
sudo mv bash ./option-root/bin/
COMMANDS=$(./option-root/bin/busybox --list)
for cmd in $COMMANDS; do
sudo ln -sf /pckg/option/bin/busybox ./option-root/bin/$cmd
done
sudo rm -f option.sfs
sudo mksquashfs option-root option.sfs -quiet -comp xz -no-xattrs -b 256k
sudo rm -rf option-root
- name: Get routeros-${{ env.LATEST_VERSION }}.npk
run: sudo wget -nv -O routeros-$LATEST_VERSION.npk https://download.mikrotik.com/routeros/$LATEST_VERSION/routeros-$LATEST_VERSION.npk
- name: Patch routeros-${{ env.LATEST_VERSION }}.npk
run: sudo -E python3 patch.py routeros-$LATEST_VERSION.npk
- name: Get mikrotik-${{ env.LATEST_VERSION }}.iso
run: sudo wget -nv -O mikrotik-$LATEST_VERSION.iso https://download.mikrotik.com/routeros/$LATEST_VERSION/mikrotik-$LATEST_VERSION.iso
- name: Patch mikrotik-${{ env.LATEST_VERSION }}.iso
run: |
sudo apt-get install -y mkisofs > /dev/null
sudo mkdir ./iso
sudo mount -o loop,ro mikrotik-$LATEST_VERSION.iso ./iso
sudo mkdir ./new_iso
sudo cp -r ./iso/* ./new_iso/
sudo rsync -a ./iso/ ./new_iso/
sudo umount ./iso
sudo rm -rf ./iso
sudo rm -f mikrotik-$LATEST_VERSION.iso
sudo rm -rf ./new_iso/routeros-$LATEST_VERSION.npk
sudo cp keygen.zip ./new_iso/rw/disk/
NPK_FILES=$(find ./new_iso/*.npk)
for file in $NPK_FILES; do
sudo -E python3 npk.py sign $file $file
done
sudo cp routeros-$LATEST_VERSION.npk ./new_iso/
sudo -E python3 npk.py create ./new_iso/gps-$LATEST_VERSION.npk ./option.sfs ./option-$LATEST_VERSION.npk
sudo cp option-$LATEST_VERSION.npk ./new_iso/
sudo cp linux ./new_iso/isolinux/
sudo mkdir ./efiboot
sudo mount -o loop ./new_iso/efiboot.img ./efiboot
sudo cp linux ./efiboot/linux.x86_64
sudo umount ./efiboot
sudo rm -rf ./efiboot
sudo mkisofs -o mikrotik-$LATEST_VERSION.iso \
-V "MikroTik $LATEST_VERSION Patched" \
-sysid "" -preparer "MiKroTiK" \
-publisher "" -A "MiKroTiK RouterOS" \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-eltorito-alt-boot \
-e efiboot.img \
-no-emul-boot \
-R \
./new_iso
sudo rm -rf ./new_iso
- name: Delete Release tag ${{ env.LATEST_VERSION }}
run: |
HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
RELEASE_INFO=$(curl -s -H $HEADER https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.LATEST_VERSION }})
RELEASE_ID=$(echo $RELEASE_INFO | jq -r '.id')
echo "Release ID: $RELEASE_ID"
if [ "$RELEASE_ID" != "null" ]; then
curl -X DELETE -H "$HEADER" https://api.github.com/repos/${{ github.repository }}/git/refs/tags/${{ env.LATEST_VERSION }}
echo "Tag ${{ env.LATEST_VERSION }} deleted successfully."
curl -X DELETE -H "$HEADER" https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID
echo "Release with tag ${{ env.LATEST_VERSION }} deleted successfully."
else
echo "Release not found for tag: ${{ env.LATEST_VERSION }})"
fi
- name: Create Release tag ${{ env.LATEST_VERSION }}
uses: softprops/action-gh-release@v2
with:
name: "MikroTik ${{ env.LATEST_VERSION }}"
body: "MikroTik ${{ env.LATEST_VERSION }}"
tag_name: ${{ env.LATEST_VERSION }}
make_latest: "true"
files: |
mikrotik-${{ env.LATEST_VERSION }}.iso
routeros-${{ env.LATEST_VERSION }}.npk
option-${{ env.LATEST_VERSION }}.npk
keygen.zip