name: Patch Mikrotik RouterOS on: # push: # branches: [ "main" ] schedule: - cron: "0 0 * * *" workflow_dispatch: permissions: contents: write jobs: Create_SquashFS: runs-on: ubuntu-latest env: TZ: 'Asia/Shanghai' steps: - name: Cache id: cache-squashfs uses: actions/cache@v4 with: path: | cpython-3.11.9.tar.gz bash busybox key: ${{ runner.os }}-squashfs - name: Get Busybox and Python3 if: steps.cache-squashfs.outputs.cache-hit != 'true' run: | 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 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 - name: Create squashfs for option npk run: | sudo chmod +x busybox sudo chmod +x bash sudo mkdir -p ./option-root/bin/ sudo cp busybox ./option-root/bin/ sudo cp 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 tar -xf 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: branch: ["7"] channel: [stable, testing] env: TZ: 'Asia/Shanghai' LATEST7_VERSION_URL: 'https://upgrade.mikrotik.com/routeros/NEWESTa7' LATEST6_VERSION_URL: 'http://upgrade.mikrotik.com/routeros/LATEST.6' 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) LATEST_VERSION=$(wget -nv -O - ${{ env.LATEST7_VERSION_URL }}.${{ matrix.channel }} | cut -d ' ' -f1) echo Latest Version:$LATEST_VERSION echo "LATEST_VERSION=${LATEST_VERSION}" >> $GITHUB_ENV - name: Cache ${{ env.LATEST_VERSION }} id: cache-mikrotik uses: actions/cache@v4 with: path: | netinstall-${{ env.LATEST_VERSION }}.zip mikrotik-${{ env.LATEST_VERSION }}.iso key: ${{ runner.os }}-${{ env.LATEST_VERSION }} - name: Get netinstall-${{ env.LATEST_VERSION }}.zip and mikrotik-${{ env.LATEST_VERSION }}.iso if: steps.cache-mikrotik.outputs.cache-hit != 'true' run: | sudo wget -nv -O netinstall-$LATEST_VERSION.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/netinstall-$LATEST_VERSION.zip sudo wget -nv -O mikrotik-$LATEST_VERSION.iso https://download.mikrotik.com/routeros/$LATEST_VERSION/mikrotik-$LATEST_VERSION.iso - name: Patch netinstall.exe run: | sudo unzip netinstall-$LATEST_VERSION.zip sudo -E python3 patch.py netinstall netinstall.exe sudo zip netinstall-$LATEST_VERSION.zip ./netinstall.exe - 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 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 cd ./new_iso sudo zip ../all_packages-x86-$LATEST_VERSION.zip *.npk cd .. - name: Create chr-${{ env.LATEST_VERSION }}.img run: | sudo modprobe nbd sudo apt install -y qemu-utils extlinux > /dev/null truncate --size 128M chr-$LATEST_VERSION.img sgdisk --clear --set-alignment=2 \ --new=1::+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" --attributes=1:set:2 \ --new=2::-0 --typecode=2:8300 --change-name=2:"RouterOS" \ --gpttombr=1:2 \ chr-$LATEST_VERSION.img dd if=chr-$LATEST_VERSION.img of=pt.bin bs=1 count=66 skip=446 echo -e "\x80" | dd of=pt.bin bs=1 count=1 conv=notrunc sgdisk --mbrtogpt --clear --set-alignment=2 \ --new=1::+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" --attributes=1:set:2 \ --new=2::-0 --typecode=2:8300 --change-name=2:"RouterOS" \ chr-$LATEST_VERSION.img dd if=mbr.bin of=chr-$LATEST_VERSION.img bs=1 count=446 conv=notrunc dd if=pt.bin of=chr-$LATEST_VERSION.img bs=1 count=66 seek=446 conv=notrunc sudo qemu-nbd -c /dev/nbd0 -f raw chr-$LATEST_VERSION.img sudo mkfs.vfat -n "Boot" /dev/nbd0p1 sudo mkfs.ext4 -F -L "RouterOS" -m 0 /dev/nbd0p2 sudo mkdir -p ./img/{boot,routeros} sudo mount /dev/nbd0p1 ./img/boot/ sudo mkdir -p ./img/boot/{BOOT,EFI/BOOT} sudo cp linux ./img/boot/EFI/BOOT/BOOTX64.EFI sudo xxd -p -u /usr/bin/extlinux | tr -d '\n' | sed \ -e 's/0D0A5359534C494E555820362E30342000/4C6F6164696E672073797374656D0D0A00/g' \ -e 's/20436F707972696768742028432920313939342D3230313520482E20506574657220416E76696E20657420616C0D0A/00436F707972696768742028432920313939342D3230313520482E20506574657220416E76696E20657420616C0D0A/g' \ -e 's/203230323130383131/003230323130383131/g' \ -e 's/43485300454444/00485300004444/g' | xxd -p -r >extlinux sudo chmod +x extlinux sudo ./extlinux --install -H 64 -S 32 ./img/boot/BOOT echo -e "default system\nlabel system\n\tkernel /EFI/BOOT/BOOTX64.EFI\n\tappend load_ramdisk=1 root=/dev/ram0 quiet" > syslinux.cfg sudo cp syslinux.cfg ./img/boot/BOOT/ sudo rm syslinux.cfg sudo umount /dev/nbd0p1 sudo mount /dev/nbd0p2 ./img/routeros/ sudo mkdir -p ./img/routeros/{var/pdb/{system,option},rw/disk,dev,boot} sudo cp keygen.zip ./img/routeros/rw/disk/ sudo cp option-$LATEST_VERSION.npk ./img/routeros/var/pdb/option/image sudo cp routeros-$LATEST_VERSION.npk ./img/routeros/var/pdb/system/image sudo mknod ./img/routeros/dev/bootdev b 8 0 sudo mknod ./img/routeros/dev/bootpart b 8 1 sudo umount /dev/nbd0p2 sudo rm -rf ./img sudo qemu-nbd -d /dev/nbd0 sudo qemu-img convert -f raw -O qcow2 chr-$LATEST_VERSION.img chr-$LATEST_VERSION.qcow2 sudo qemu-img convert -f raw -O vmdk chr-$LATEST_VERSION.img chr-$LATEST_VERSION.vmdk sudo qemu-img convert -f raw -O vpc chr-$LATEST_VERSION.img chr-$LATEST_VERSION.vhd sudo qemu-img convert -f raw -O vhdx chr-$LATEST_VERSION.img chr-$LATEST_VERSION.vhdx sudo qemu-img convert -f raw -O vdi chr-$LATEST_VERSION.img chr-$LATEST_VERSION.vdi 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 *.qcow2 sudo rm *.vmdk sudo rm *.vhd sudo rm *.vhdx sudo rm *.vdi sudo rm *.img - name: Cache refind id: cache-refind uses: actions/cache@v4 with: path: refind-bin-0.14.2.zip key: ${{ runner.os }}-refind - name: Get refind if: steps.cache-refind.outputs.cache-hit != 'true' run: sudo wget -nv -O refind-bin-0.14.2.zip https://nchc.dl.sourceforge.net/project/refind/0.14.2/refind-bin-0.14.2.zip - name: Create install-image-${{ env.LATEST_VERSION }}.img run: | truncate --size 128M install-image-$LATEST_VERSION.img sudo qemu-nbd -c /dev/nbd0 -f raw install-image-$LATEST_VERSION.img sudo mkfs.vfat -n "Install" /dev/nbd0 sudo mkdir ./install sudo mount /dev/nbd0 ./install sudo mkdir -p ./install/EFI/BOOT sudo unzip refind-bin-0.14.2.zip refind-bin-0.14.2/refind/refind_x64.efi sudo cp refind-bin-0.14.2/refind/refind_x64.efi ./install/EFI/BOOT/BOOTX64.EFI sudo rm -rf refind-bin-0.14.2 echo -e 'timeout 0\ntextonly\ntextmode 0\nshowtools shutdown, reboot, exit\nmenuentry "Install RouterOS" {\n\tloader /linux\n\toptions "load_ramdisk=1 root=/dev/ram0 -install -hdd"\n}\ndefault_selection /EFI/BOOT/BOOTX64.EFI' \ > refind.conf sudo cp refind.conf ./install/EFI/BOOT/ sudo rm refind.conf sudo ./extlinux --install -H 64 -S 32 ./install/ echo -e 'default system\nLABEL system\n\tKERNEL linux\n\tAPPEND load_ramdisk=1 -install -hdd' \ > syslinux.conf sudo cp syslinux.conf ./install/ sudo rm syslinux.conf sudo cp linux ./install/ NPK_FILES=($(find ./new_iso/*.npk)) for ((i=1; i<=${#NPK_FILES[@]}; i++)) do echo "${NPK_FILES[$i-1]}=>$i.npk" sudo cp ${NPK_FILES[$i-1]} ./install/$i.npk done sudo cp keygen.zip ./install/ sudo umount /dev/nbd0 sudo qemu-nbd -d /dev/nbd0 sudo rm -rf ./install sudo rm -rf ./new_iso sudo zip install-image-$LATEST_VERSION.zip ./install-image-$LATEST_VERSION.img sudo rm ./install-image-$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 RouterOS ${{ env.LATEST_VERSION }}" body: "MikroTik RouterOS ${{ env.LATEST_VERSION }}" tag_name: ${{ env.LATEST_VERSION }} make_latest: ${{ matrix.channel == 'stable' && matrix.branch == '7' }} prerelease: ${{ matrix.channel == 'testing' }} files: | mikrotik-${{ env.LATEST_VERSION }}.iso chr-${{ env.LATEST_VERSION }}*.zip netinstall-${{ env.LATEST_VERSION }}.zip install-image-${{ env.LATEST_VERSION }}.zip routeros-${{ env.LATEST_VERSION }}.npk option-${{ env.LATEST_VERSION }}.npk all_packages-x86-${{ env.LATEST_VERSION }}.zip