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: Create squashfs for python3 npk run: | wget -nv https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tar.xz tar -xf Python-3.11.9.tar.xz rm -f Python-3.11.9.tar.xz sudo mkdir -p /pckg/python3/ cd Python-3.11.9 sudo apt install -y pkg-config libbz2-dev liblzma-dev libssl-dev libgd-dev libreadline-dev zlib1g-dev libgdbm-dev ./configure --enable-optimizations --prefix=/pckg/python3/ --disable-test-modules --without-static-libpython CONFIGURE_LDFLAGS="-static" make -j$(nproc) sudo make altinstall cd .. sudo rm -rf Python-3.11.9 sudo mksquashfs /pckg/python3 python3.sfs -quiet -comp xz -no-xattrs -b 256 sudo rm -rf /pckg - name: Archive Generated File uses: actions/upload-artifact@v2 with: name: python3 path: python3.sfs - 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 routeros-$LATEST_VERSION.npk sudo cp keygen.exe ./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 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: Get install-image-${{ env.LATEST_VERSION }}.img run: | sudo wget -nv -O install-image-$LATEST_VERSION.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/install-image-$LATEST_VERSION.zip - name: Patch install-image-${{ env.LATEST_VERSION }}.img run: | sudo unzip install-image-$LATEST_VERSION.zip sudo mkdir ./install sudo mount -o loop install-image-$LATEST_VERSION.img ./install sudo rm install-image-$LATEST_VERSION.zip sudo rm ./install/1.npk NPK_FILES=$(find ./install/*.npk) for file in $NPK_FILES; do sudo -E python3 npk.py sign $file $file done sudo cp routeros-$LATEST_VERSION.npk ./install/1.npk sudo cp keygen.exe ./install/ sudo cp option-$LATEST_VERSION.npk ./install/100.npk sudo cp linux ./install/ sudo umount ./install sudo rm -rf ./install sudo zip install-image-$LATEST_VERSION.zip ./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/${{ 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 install-image-${{ env.LATEST_VERSION }}.zip