mirror of
https://github.com/elseif/MikroTikPatch.git
synced 2025-01-23 21:44:59 +03:00
227 lines
9.5 KiB
YAML
227 lines
9.5 KiB
YAML
name: Patch Mikrotik RouterOS
|
|
on:
|
|
# push:
|
|
# branches: [ "main" ]
|
|
schedule:
|
|
- cron: "0 0 * * *"
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: 'RouterOS version, e.g.: 7.15.1, blank for latest'
|
|
type: string
|
|
default: ''
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
Create_SquashFS:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
TZ: 'Asia/Shanghai'
|
|
steps:
|
|
- 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 mksquashfs option-root option.sfs -quiet -comp xz -no-xattrs -b 256k
|
|
sudo rm -rf option-root
|
|
|
|
- name: Create squashfs for python3 npk
|
|
run: |
|
|
sudo wget -O cpython-3.11.9.tar.gz -nv https://github.com/indygreg/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-x86_64-unknown-linux-musl-install_only.tar.gz
|
|
sudo tar -xf cpython-3.11.9.tar.gz
|
|
sudo rm -f cpython-3.11.9.tar.gz
|
|
sudo rm -rf ./python/include
|
|
sudo rm -rf ./python/share
|
|
sudo mksquashfs python python3.sfs -quiet -comp xz -no-xattrs -b 256k
|
|
sudo rm -rf python
|
|
|
|
- name: Upload Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
retention-days: 1
|
|
name: squashfs
|
|
path: ./*.sfs
|
|
|
|
Patch_Latest_RouterOS:
|
|
runs-on: ubuntu-latest
|
|
needs: Create_SquashFS
|
|
strategy:
|
|
matrix:
|
|
channel: [stable, testing]
|
|
env:
|
|
TZ: 'Asia/Shanghai'
|
|
LATEST_VERSION_URL: 'https://upgrade.mikrotik.com/routeros/NEWESTa7.'
|
|
LATEST_VERSION: ""
|
|
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: Download Artifact
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: squashfs
|
|
|
|
- name: Get latest routeros version
|
|
run: |
|
|
echo $(uname -a)
|
|
if [ "${{ inputs.version }}" == "" ]; then
|
|
LATEST_VERSION=$(wget -nv -O - ${{ env.LATEST_VERSION_URL }}${{ matrix.channel }} | cut -d ' ' -f1)
|
|
else
|
|
LATEST_VERSION=${{ inputs.version }}
|
|
fi
|
|
echo Latest Version:$LATEST_VERSION
|
|
echo "LATEST_VERSION=${LATEST_VERSION}" >> $GITHUB_ENV
|
|
|
|
- name: Get netinstall-${{ env.LATEST_VERSION }}.zip
|
|
run: |
|
|
sudo wget -nv -O netinstall-$LATEST_VERSION.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/netinstall-$LATEST_VERSION.zip
|
|
sudo unzip netinstall-$LATEST_VERSION.zip
|
|
sudo rm netinstall-$LATEST_VERSION.zip
|
|
- name: Patch netinstall.exe
|
|
run: |
|
|
sudo -E python3 patch.py netinstall netinstall.exe
|
|
sudo zip netinstall-$LATEST_VERSION.zip ./netinstall.exe
|
|
|
|
- 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 mv ./new_iso/routeros-$LATEST_VERSION.npk ./
|
|
sudo -E python3 patch.py npk routeros-$LATEST_VERSION.npk
|
|
sudo cp keygen.zip ./new_iso/
|
|
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-$LATEST_VERSION.npk option ./option.sfs -desc="busybox and ash"
|
|
sudo cp option-$LATEST_VERSION.npk ./new_iso/
|
|
sudo -E python3 npk.py create ./new_iso/gps-$LATEST_VERSION.npk ./python3-$LATEST_VERSION.npk python3 ./python3.sfs -desc="python 3.11.9"
|
|
sudo cp python3-$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 -J \
|
|
./new_iso
|
|
sudo rm -rf ./new_iso
|
|
|
|
- name: Get chr-${{ env.LATEST_VERSION }}.img
|
|
run: |
|
|
sudo wget -nv -O chr-$LATEST_VERSION.img.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/chr-$LATEST_VERSION.img.zip
|
|
sudo unzip chr-$LATEST_VERSION.img.zip
|
|
sudo rm chr-$LATEST_VERSION.img.zip
|
|
|
|
- name: Patch chr-${{ env.LATEST_VERSION }}.img
|
|
run: |
|
|
sudo modprobe nbd
|
|
sudo apt install -y qemu-utils > /dev/null
|
|
sudo qemu-img convert -f raw -O qcow2 chr-$LATEST_VERSION.img chr-$LATEST_VERSION.qcow2
|
|
sudo rm chr-$LATEST_VERSION.img
|
|
sudo qemu-nbd -c /dev/nbd0 chr-$LATEST_VERSION.qcow2
|
|
sudo -E python3 patch.py boot /dev/nbd0p1
|
|
sudo mkdir ./routeros
|
|
sudo mount /dev/nbd0p2 ./routeros
|
|
sudo mkdir -p ./routeros/rw/disk
|
|
sudo cp keygen.zip ./routeros/rw/disk
|
|
sudo mkdir -p ./routeros/var/pdb/option
|
|
sudo cp option-$LATEST_VERSION.npk ./routeros/var/pdb/option/image
|
|
sudo cp routeros-$LATEST_VERSION.npk ./routeros/var/pdb/system/image
|
|
sudo umount /dev/nbd0p2
|
|
sudo rm -rf ./routeros
|
|
sudo qemu-nbd -d /dev/nbd0
|
|
|
|
sudo qemu-img convert -f qcow2 -O vmdk chr-$LATEST_VERSION.qcow2 chr-$LATEST_VERSION.vmdk
|
|
sudo qemu-img convert -f qcow2 -O vpc chr-$LATEST_VERSION.qcow2 chr-$LATEST_VERSION.vhd
|
|
sudo qemu-img convert -f qcow2 -O vhdx chr-$LATEST_VERSION.qcow2 chr-$LATEST_VERSION.vhdx
|
|
sudo qemu-img convert -f qcow2 -O vdi chr-$LATEST_VERSION.qcow2 chr-$LATEST_VERSION.vdi
|
|
sudo qemu-img convert -f qcow2 -O raw chr-$LATEST_VERSION.qcow2 chr-$LATEST_VERSION.img
|
|
|
|
sudo zip chr-$LATEST_VERSION.qcow2.zip chr-$LATEST_VERSION.qcow2
|
|
sudo zip chr-$LATEST_VERSION.vmdk.zip chr-$LATEST_VERSION.vmdk
|
|
sudo zip chr-$LATEST_VERSION.vhd.zip chr-$LATEST_VERSION.vhd
|
|
sudo zip chr-$LATEST_VERSION.vhdx.zip chr-$LATEST_VERSION.vhdx
|
|
sudo zip chr-$LATEST_VERSION.vdi.zip chr-$LATEST_VERSION.vdi
|
|
sudo zip chr-$LATEST_VERSION.img.zip chr-$LATEST_VERSION.img
|
|
|
|
sudo rm chr-$LATEST_VERSION.qcow2
|
|
sudo rm chr-$LATEST_VERSION.vmdk
|
|
sudo rm chr-$LATEST_VERSION.vhd
|
|
sudo rm chr-$LATEST_VERSION.vhdx
|
|
sudo rm chr-$LATEST_VERSION.vdi
|
|
sudo rm chr-$LATEST_VERSION.img
|
|
|
|
|
|
- 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/$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/$LATEST_VERSION
|
|
echo "Tag $LATEST_VERSION deleted successfully."
|
|
curl -X DELETE -H "$HEADER" https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID
|
|
echo "Release with tag $LATEST_VERSION deleted successfully."
|
|
else
|
|
echo "Release not found for tag: $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: ${{ matrix.channel == 'stable' }}
|
|
files: |
|
|
mikrotik-${{ env.LATEST_VERSION }}.iso
|
|
chr-${{ env.LATEST_VERSION }}.*.zip
|
|
netinstall-${{ env.LATEST_VERSION }}.zip |