mirror of
https://github.com/elseif/MikroTikPatch.git
synced 2026-09-04 14:35:49 +00:00
Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4a4187e23 | ||
|
|
66323bbfea | ||
|
|
7f2ec84067 | ||
|
|
5589babdcc | ||
|
|
18bae23bf3 | ||
|
|
3d52d65eb5 | ||
|
|
a951a224b0 | ||
|
|
343fe653ee | ||
|
|
bfb4e91be7 | ||
|
|
898d1c1789 | ||
|
|
e4167afbec | ||
|
|
aeaf99729f | ||
|
|
d125a063ce | ||
|
|
ce926f7cc9 | ||
|
|
aea2da2a36 | ||
|
|
c869dca3c1 | ||
|
|
cbe8254d84 | ||
|
|
331df17ee7 | ||
|
|
35852182b2 | ||
|
|
e0d1eb1a98 | ||
|
|
0717a39c02 | ||
|
|
4993be82a6 | ||
|
|
0dbed4777f | ||
|
|
3b529862d1 | ||
|
|
6da98653fc | ||
|
|
27e023fb28 | ||
|
|
df6b25a30e | ||
|
|
60294067c7 | ||
|
|
d309253b06 | ||
|
|
b3579cb363 | ||
|
|
0f2c5e6081 | ||
|
|
8f59465bf0 | ||
|
|
736af6817b | ||
|
|
10a56eb673 | ||
|
|
6518dda504 | ||
|
|
74e812fa2b | ||
|
|
810909828a | ||
|
|
49f4ad0a59 | ||
|
|
ece607c8f7 | ||
|
|
1426fc061a | ||
|
|
7579dadaea | ||
|
|
6b6669fb23 | ||
|
|
5f603dcebc | ||
|
|
e1994f69d6 | ||
|
|
39af3326bd | ||
|
|
c657f2e736 | ||
|
|
a8dd672a66 | ||
|
|
cf01bbda4d | ||
|
|
1c9207d498 | ||
|
|
f1ed27cb52 | ||
|
|
8d38a80dd8 | ||
|
|
f4af3671be | ||
|
|
2f0f0b1abb | ||
|
|
ea10a1a4c7 | ||
|
|
bd03ecb963 | ||
|
|
5b909283a0 | ||
|
|
289ea3a34f |
109
.github/workflows/mikrotik_patch_6.yml
vendored
109
.github/workflows/mikrotik_patch_6.yml
vendored
@@ -3,10 +3,28 @@ name: Patch Mikrotik RouterOS 6.x
|
|||||||
on:
|
on:
|
||||||
# push:
|
# push:
|
||||||
# branches: [ "main" ]
|
# branches: [ "main" ]
|
||||||
schedule:
|
# schedule:
|
||||||
- cron: "0 0 * * *"
|
# - cron: "0 0 * * *"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
channel:
|
||||||
|
description: 'Channel (stable, long-term)'
|
||||||
|
required: true
|
||||||
|
default: 'stable'
|
||||||
|
type: choice
|
||||||
|
options:
|
||||||
|
- stable
|
||||||
|
- long-term
|
||||||
|
version:
|
||||||
|
description: "Version ('', 6.49.17, 6.49.18,...)"
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
type: string
|
||||||
|
buildtime:
|
||||||
|
description: "Build Time"
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
type: string
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
@@ -36,14 +54,20 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Set build time
|
- name: Set build time
|
||||||
id: set_buildtime
|
id: set_buildtime
|
||||||
run: echo "BUILD_TIME=$(date +'%s')" >> $GITHUB_OUTPUT
|
run: |
|
||||||
|
_BUILD_TIME=${{ github.event.inputs.buildtime }}
|
||||||
|
if [ -z "$_BUILD_TIME" ]; then
|
||||||
|
echo "BUILD_TIME=$(date +'%s')" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "BUILD_TIME=$_BUILD_TIME" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
Patch_RouterOS:
|
Patch_RouterOS:
|
||||||
needs: Set_BuildTime
|
needs: Set_BuildTime
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
channel: [long-term,stable]
|
channel: ${{ fromJSON(format('["{0}"]', github.event.inputs.channel || 'stable')) }}
|
||||||
env:
|
env:
|
||||||
TZ: 'Asia/Shanghai'
|
TZ: 'Asia/Shanghai'
|
||||||
LATEST_VERSION: ""
|
LATEST_VERSION: ""
|
||||||
@@ -60,7 +84,10 @@ jobs:
|
|||||||
id: get_latest
|
id: get_latest
|
||||||
run: |
|
run: |
|
||||||
echo $(uname -a)
|
echo $(uname -a)
|
||||||
LATEST_VERSION=$(wget -nv -O - https://upgrade.mikrotik.com/routeros/NEWEST6.${{ matrix.channel }} | cut -d ' ' -f1)
|
LATEST_VERSION=${{ github.event.inputs.version }}
|
||||||
|
if [ -z "$_LATEST_VERSION" ]; then
|
||||||
|
LATEST_VERSION=$(wget -nv -O - https://${{ env.MIKRO_UPGRADE_URL }}/routeros/NEWEST6.${{ matrix.channel }} | cut -d ' ' -f1)
|
||||||
|
fi
|
||||||
echo Latest Version:$LATEST_VERSION
|
echo Latest Version:$LATEST_VERSION
|
||||||
if [ "${{ github.event_name }}" == "schedule" ]; then
|
if [ "${{ github.event_name }}" == "schedule" ]; then
|
||||||
_LATEST_VERSION=$(wget -nv -O - https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/NEWEST6.${{ matrix.channel }} | cut -d ' ' -f1)
|
_LATEST_VERSION=$(wget -nv -O - https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/NEWEST6.${{ matrix.channel }} | cut -d ' ' -f1)
|
||||||
@@ -77,7 +104,21 @@ jobs:
|
|||||||
cat CHANGELOG
|
cat CHANGELOG
|
||||||
echo "LATEST_VERSION=${LATEST_VERSION}" >> $GITHUB_ENV
|
echo "LATEST_VERSION=${LATEST_VERSION}" >> $GITHUB_ENV
|
||||||
echo "BUILD_TIME=${BUILD_TIME}" >> $GITHUB_ENV
|
echo "BUILD_TIME=${BUILD_TIME}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
has_patched_npk=false
|
||||||
|
if wget -nv --spider https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/$LATEST_VERSION/routeros-x86-$LATEST_VERSION.npk; then
|
||||||
|
echo "RouterOS NPK file exists, attempting to download..."
|
||||||
|
if wget -nv -O routeros-x86-$LATEST_VERSION.npk https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/$LATEST_VERSION/routeros-x86-$LATEST_VERSION.npk; then
|
||||||
|
echo "RouterOS NPK file downloaded successfully."
|
||||||
|
if wget -nv --spider https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/$LATEST_VERSION/system-$LATEST_VERSION.npk; then
|
||||||
|
echo "System NPK file exists, attempting to download..."
|
||||||
|
if wget -nv -O system-$LATEST_VERSION.npk https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/$LATEST_VERSION/system-$LATEST_VERSION.npk; then
|
||||||
|
has_patched_npk=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "has_patched_npk=$has_patched_npk" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Cache mikrotik-${{ env.LATEST_VERSION }}.iso
|
- name: Cache mikrotik-${{ env.LATEST_VERSION }}.iso
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||||
@@ -105,8 +146,12 @@ jobs:
|
|||||||
sudo rsync -a ./iso/ ./new_iso/
|
sudo rsync -a ./iso/ ./new_iso/
|
||||||
sudo umount ./iso
|
sudo umount ./iso
|
||||||
sudo rm -rf ./iso
|
sudo rm -rf ./iso
|
||||||
sudo mv ./new_iso/system-$LATEST_VERSION.npk ./
|
if [ "${{ steps.get_latest.outputs.has_patched_npk }}" == "false" ]; then
|
||||||
sudo -E python3 patch.py npk system-$LATEST_VERSION.npk
|
sudo mv ./new_iso/system-$LATEST_VERSION.npk ./
|
||||||
|
sudo -E python3 patch.py npk system-$LATEST_VERSION.npk
|
||||||
|
else
|
||||||
|
sudo -E python3 npk.py sign system-$LATEST_VERSION.npk system-$LATEST_VERSION.npk
|
||||||
|
fi
|
||||||
sudo -E python3 patch.py kernel ./new_iso/isolinux/initrd.rgz
|
sudo -E python3 patch.py kernel ./new_iso/isolinux/initrd.rgz
|
||||||
NPK_FILES=$(find ./new_iso/*.npk)
|
NPK_FILES=$(find ./new_iso/*.npk)
|
||||||
for file in $NPK_FILES; do
|
for file in $NPK_FILES; do
|
||||||
@@ -129,13 +174,9 @@ jobs:
|
|||||||
sudo mkdir ./all_packages
|
sudo mkdir ./all_packages
|
||||||
sudo cp ./new_iso/*.npk ./all_packages/
|
sudo cp ./new_iso/*.npk ./all_packages/
|
||||||
sudo rm -rf ./new_iso
|
sudo rm -rf ./new_iso
|
||||||
cd ./all_packages
|
|
||||||
sudo zip ../all_packages-x86-$LATEST_VERSION.zip *.npk
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
|
|
||||||
- name: Create install-image-${{ env.LATEST_VERSION }}.img
|
- name: Create install-image-${{ env.LATEST_VERSION }}.img
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
run: |
|
run: |
|
||||||
sudo modprobe nbd
|
sudo modprobe nbd
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
@@ -184,19 +225,25 @@ jobs:
|
|||||||
- name: Create chr-${{ env.LATEST_VERSION }}.img
|
- name: Create chr-${{ env.LATEST_VERSION }}.img
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||||
run: |
|
run: |
|
||||||
|
sudo modprobe nbd
|
||||||
|
sudo apt-get install -y qemu-utils extlinux > /dev/null
|
||||||
sudo mkdir ./chr
|
sudo mkdir ./chr
|
||||||
sudo cp chr.img chr-$LATEST_VERSION.img
|
sudo cp chr.img chr-$LATEST_VERSION.img
|
||||||
sudo qemu-nbd -c /dev/nbd0 -f raw chr-$LATEST_VERSION.img
|
sudo qemu-nbd -c /dev/nbd0 -f raw chr-$LATEST_VERSION.img
|
||||||
sudo -E python3 patch.py block /dev/nbd0p1 boot/initrd.rgz
|
sudo -E python3 patch.py block /dev/nbd0p1 boot/initrd.rgz
|
||||||
sudo mount /dev/nbd0p1 ./chr
|
sudo mount /dev/nbd0p1 ./chr
|
||||||
sudo cp ./all_packages/dude-$LATEST_VERSION.npk ./chr/var/pdb/dude/image
|
sudo cp ./all_packages/dude-$LATEST_VERSION.npk ./chr/var/pdb/dude/image
|
||||||
sudo -E python3 patch.py npk ./chr/var/pdb/routeros-x86/image
|
if [ "${{ steps.get_latest.outputs.has_patched_npk }}" == "false" ]; then
|
||||||
sudo cp ./chr/var/pdb/routeros-x86/image ./all_packages/routeros-x86-$LATEST_VERSION.npk
|
sudo -E python3 patch.py npk ./chr/var/pdb/routeros-x86/image
|
||||||
sudo cp ./all_packages/routeros-x86-$LATEST_VERSION.npk routeros-x86-$LATEST_VERSION.npk
|
sudo cp ./chr/var/pdb/routeros-x86/image ./all_packages/routeros-x86-$LATEST_VERSION.npk
|
||||||
|
else
|
||||||
|
sudo -E python3 npk.py sign routeros-x86-$LATEST_VERSION.npk routeros-x86-$LATEST_VERSION.npk
|
||||||
|
sudo cp -f routeros-x86-$LATEST_VERSION.npk ./chr/var/pdb/routeros-x86/image
|
||||||
|
sudo cp routeros-x86-$LATEST_VERSION.npk ./all_packages/routeros-x86-$LATEST_VERSION.npk
|
||||||
|
fi
|
||||||
sudo umount ./chr
|
sudo umount ./chr
|
||||||
sudo qemu-nbd -d /dev/nbd0
|
sudo qemu-nbd -d /dev/nbd0
|
||||||
sudo rm -rf ./chr
|
sudo rm -rf ./chr
|
||||||
|
|
||||||
sudo qemu-img convert -f raw -O qcow2 chr-$LATEST_VERSION.img chr-$LATEST_VERSION.qcow2
|
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 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 vpc chr-$LATEST_VERSION.img chr-$LATEST_VERSION.vhd
|
||||||
@@ -217,14 +264,21 @@ jobs:
|
|||||||
sudo rm chr-$LATEST_VERSION$ARCH.vdi
|
sudo rm chr-$LATEST_VERSION$ARCH.vdi
|
||||||
sudo rm chr-$LATEST_VERSION$ARCH.img
|
sudo rm chr-$LATEST_VERSION$ARCH.img
|
||||||
|
|
||||||
|
cd ./all_packages
|
||||||
|
sudo zip ../all_packages-x86-$LATEST_VERSION.zip *.npk
|
||||||
|
cd ..
|
||||||
|
|
||||||
- name: Upload Files
|
- name: Upload Files
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||||
run: |
|
run: |
|
||||||
sudo mkdir -p ./publish/$LATEST_VERSION
|
if [ "${{ steps.get_latest.outputs.has_patched_npk }}" == "false" ]; then
|
||||||
echo $LATEST_VERSION $BUILD_TIME | sudo tee ./publish/NEWEST6.${{ matrix.channel }}
|
OUTDIR="$LATEST_VERSION-UNDONE"
|
||||||
sudo cp CHANGELOG ./publish/$LATEST_VERSION/
|
else
|
||||||
sudo cp ./all_packages/*.npk ./publish/$LATEST_VERSION/
|
OUTDIR="$LATEST_VERSION"
|
||||||
|
fi
|
||||||
|
sudo mkdir -p ./publish/$OUTDIR
|
||||||
|
sudo cp CHANGELOG ./publish/$OUTDIR/
|
||||||
|
sudo cp ./all_packages/*.npk ./publish/$OUTDIR/
|
||||||
sudo chown -R root:root ./publish/
|
sudo chown -R root:root ./publish/
|
||||||
sudo apt-get install -y lftp ssh sshpass > /dev/null 2>&1
|
sudo apt-get install -y lftp ssh sshpass > /dev/null 2>&1
|
||||||
sudo -E lftp -u ${{ secrets.SSH_USERNAME }},'${{ secrets.SSH_PASSWORD }}' sftp://${{ secrets.SSH_SERVER }}:${{ secrets.SSH_PORT }} <<EOF
|
sudo -E lftp -u ${{ secrets.SSH_USERNAME }},'${{ secrets.SSH_PASSWORD }}' sftp://${{ secrets.SSH_SERVER }}:${{ secrets.SSH_PORT }} <<EOF
|
||||||
@@ -232,7 +286,8 @@ jobs:
|
|||||||
mirror --reverse --verbose --only-newer ./publish ${{ secrets.SSH_DIRECTORY }}
|
mirror --reverse --verbose --only-newer ./publish ${{ secrets.SSH_DIRECTORY }}
|
||||||
bye
|
bye
|
||||||
EOF
|
EOF
|
||||||
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "chown -R 32768:32768 /rw/disk/${{ secrets.SSH_DIRECTORY }}/"
|
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "chown -R 32768:32768 /rw/disk/${{ secrets.SSH_DIRECTORY }}/"
|
||||||
|
|
||||||
- name: Clear Cloudflare cache
|
- name: Clear Cloudflare cache
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||||
run: |
|
run: |
|
||||||
@@ -242,7 +297,7 @@ jobs:
|
|||||||
--data '{"purge_everything": true}'
|
--data '{"purge_everything": true}'
|
||||||
|
|
||||||
- name: Delete Release tag ${{ env.LATEST_VERSION }}
|
- name: Delete Release tag ${{ env.LATEST_VERSION }}
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
run: |
|
run: |
|
||||||
HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
|
HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
|
||||||
RELEASE_INFO=$(curl -s -H $HEADER https://api.github.com/repos/${{ github.repository }}/releases/tags/$LATEST_VERSION$ARCH)
|
RELEASE_INFO=$(curl -s -H $HEADER https://api.github.com/repos/${{ github.repository }}/releases/tags/$LATEST_VERSION$ARCH)
|
||||||
@@ -258,7 +313,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Create Release tag ${{ env.LATEST_VERSION }}
|
- name: Create Release tag ${{ env.LATEST_VERSION }}
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
name: "RouterOS ${{ env.LATEST_VERSION }}"
|
name: "RouterOS ${{ env.LATEST_VERSION }}"
|
||||||
|
|||||||
129
.github/workflows/mikrotik_patch_7.yml
vendored
129
.github/workflows/mikrotik_patch_7.yml
vendored
@@ -2,10 +2,36 @@ name: Patch Mikrotik RouterOS 7.x
|
|||||||
on:
|
on:
|
||||||
# push:
|
# push:
|
||||||
# branches: [ "main" ]
|
# branches: [ "main" ]
|
||||||
schedule:
|
# schedule:
|
||||||
- cron: "0 0 * * *"
|
# - cron: "0 0 * * *"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
arch:
|
||||||
|
description: 'Architecture (x86, arm64)'
|
||||||
|
required: true
|
||||||
|
default: 'x86'
|
||||||
|
type: choice
|
||||||
|
options:
|
||||||
|
- x86
|
||||||
|
- arm64
|
||||||
|
channel:
|
||||||
|
description: 'Channel (stable, testing)'
|
||||||
|
required: true
|
||||||
|
default: 'stable'
|
||||||
|
type: choice
|
||||||
|
options:
|
||||||
|
- stable
|
||||||
|
- testing
|
||||||
|
version:
|
||||||
|
description: "Version ('', 7.17, 7.17.1, 7.17.2,...)"
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
type: string
|
||||||
|
buildtime:
|
||||||
|
description: "Build Time"
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
type: string
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
@@ -35,15 +61,21 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Set build time
|
- name: Set build time
|
||||||
id: set_buildtime
|
id: set_buildtime
|
||||||
run: echo "BUILD_TIME=$(date +'%s')" >> $GITHUB_OUTPUT
|
run: |
|
||||||
|
_BUILD_TIME=${{ github.event.inputs.buildtime }}
|
||||||
|
if [ -z "$_BUILD_TIME" ]; then
|
||||||
|
echo "BUILD_TIME=$(date +'%s')" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "BUILD_TIME=$_BUILD_TIME" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
Patch_RouterOS:
|
Patch_RouterOS:
|
||||||
needs: Set_BuildTime
|
needs: Set_BuildTime
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
arch: [x86,arm64]
|
arch: ${{ fromJSON(format('["{0}"]', github.event.inputs.arch || 'x86')) }}
|
||||||
channel: [stable, testing]
|
channel: ${{ fromJSON(format('["{0}"]', github.event.inputs.channel || 'stable')) }}
|
||||||
env:
|
env:
|
||||||
TZ: 'Asia/Shanghai'
|
TZ: 'Asia/Shanghai'
|
||||||
LATEST_VERSION: ""
|
LATEST_VERSION: ""
|
||||||
@@ -61,7 +93,10 @@ jobs:
|
|||||||
id: get_latest
|
id: get_latest
|
||||||
run: |
|
run: |
|
||||||
echo $(uname -a)
|
echo $(uname -a)
|
||||||
LATEST_VERSION=$(wget -nv -O - https://${{ env.MIKRO_UPGRADE_URL }}/routeros/NEWESTa7.${{ matrix.channel }} | cut -d ' ' -f1)
|
LATEST_VERSION=${{ github.event.inputs.version }}
|
||||||
|
if [ -z "$_LATEST_VERSION" ]; then
|
||||||
|
LATEST_VERSION=$(wget -nv -O - https://${{ env.MIKRO_UPGRADE_URL }}/routeros/NEWESTa7.${{ matrix.channel }} | cut -d ' ' -f1)
|
||||||
|
fi
|
||||||
echo Latest Version:$LATEST_VERSION
|
echo Latest Version:$LATEST_VERSION
|
||||||
if [ "${{ github.event_name }}" == "schedule" ]; then
|
if [ "${{ github.event_name }}" == "schedule" ]; then
|
||||||
_LATEST_VERSION=$(wget -nv -O - https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/NEWESTa7.${{ matrix.channel }} | cut -d ' ' -f1)
|
_LATEST_VERSION=$(wget -nv -O - https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/NEWESTa7.${{ matrix.channel }} | cut -d ' ' -f1)
|
||||||
@@ -85,7 +120,17 @@ jobs:
|
|||||||
ARCH='-arm64'
|
ARCH='-arm64'
|
||||||
echo "ARCH=$ARCH" >> $GITHUB_ENV
|
echo "ARCH=$ARCH" >> $GITHUB_ENV
|
||||||
fi
|
fi
|
||||||
echo "{\"arch\": \"${{ matrix.arch }}\", \"channel\": \"${{ matrix.channel }}\", \"latest_version\": \"$LATEST_VERSION\",\"build_time\": \"$BUILD_TIME\"}" > latest_version_${{ matrix.arch }}_${{ matrix.channel }}.json
|
has_patched_npk=false
|
||||||
|
if wget -nv --spider https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/$LATEST_VERSION/routeros-$LATEST_VERSION$ARCH.npk; then
|
||||||
|
echo "RouterOS NPK file exists, attempting to download..."
|
||||||
|
if wget -nv -O routeros-$LATEST_VERSION$ARCH.npk https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/$LATEST_VERSION/routeros-$LATEST_VERSION$ARCH.npk; then
|
||||||
|
echo "RouterOS NPK file downloaded successfully."
|
||||||
|
has_patched_npk=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "has_patched_npk=$has_patched_npk" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
echo "{\"arch\": \"${{ matrix.arch }}\", \"channel\": \"${{ matrix.channel }}\", \"latest_version\": \"$LATEST_VERSION\",\"build_time\": \"$BUILD_TIME\",\"patched\": \"$has_patched_npk\"}" > latest_version_${{ matrix.arch }}_${{ matrix.channel }}.json
|
||||||
sudo apt-get update > /dev/null
|
sudo apt-get update > /dev/null
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
@@ -94,7 +139,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: latest_version_${{ matrix.arch }}_${{ matrix.channel }}
|
name: latest_version_${{ matrix.arch }}_${{ matrix.channel }}
|
||||||
path: latest_version_${{ matrix.arch }}_${{ matrix.channel }}.json
|
path: latest_version_${{ matrix.arch }}_${{ matrix.channel }}.json
|
||||||
|
|
||||||
- name: Cache Squashfs
|
- name: Cache Squashfs
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||||
id: cache-squashfs
|
id: cache-squashfs
|
||||||
@@ -140,7 +185,7 @@ jobs:
|
|||||||
sudo rm -rf ./python
|
sudo rm -rf ./python
|
||||||
|
|
||||||
- name: Cache NetInstall ${{ env.LATEST_VERSION }}
|
- name: Cache NetInstall ${{ env.LATEST_VERSION }}
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86'
|
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
id: cache-netinstall
|
id: cache-netinstall
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
@@ -150,13 +195,13 @@ jobs:
|
|||||||
key: netinstall-${{ env.LATEST_VERSION }}
|
key: netinstall-${{ env.LATEST_VERSION }}
|
||||||
|
|
||||||
- name: Get netinstall ${{ env.LATEST_VERSION }}
|
- name: Get netinstall ${{ env.LATEST_VERSION }}
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.cache-netinstall.outputs.cache-hit != 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.cache-netinstall.outputs.cache-hit != 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
run: |
|
run: |
|
||||||
sudo wget -nv -O netinstall.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/netinstall-$LATEST_VERSION.zip
|
sudo wget -nv -O netinstall.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/netinstall-$LATEST_VERSION.zip
|
||||||
sudo wget -nv -O netinstall.tar.gz https://download.mikrotik.com/routeros/$LATEST_VERSION/netinstall-$LATEST_VERSION.tar.gz
|
sudo wget -nv -O netinstall.tar.gz https://download.mikrotik.com/routeros/$LATEST_VERSION/netinstall-$LATEST_VERSION.tar.gz
|
||||||
|
|
||||||
- name: Patch netinstall ${{ env.LATEST_VERSION }}
|
- name: Patch netinstall ${{ env.LATEST_VERSION }}
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86'
|
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
run: |
|
run: |
|
||||||
sudo unzip netinstall.zip
|
sudo unzip netinstall.zip
|
||||||
sudo -E python3 patch.py netinstall netinstall.exe
|
sudo -E python3 patch.py netinstall netinstall.exe
|
||||||
@@ -191,13 +236,17 @@ jobs:
|
|||||||
sudo rsync -a ./iso/ ./new_iso/
|
sudo rsync -a ./iso/ ./new_iso/
|
||||||
sudo umount ./iso
|
sudo umount ./iso
|
||||||
sudo rm -rf ./iso
|
sudo rm -rf ./iso
|
||||||
sudo mv ./new_iso/routeros-$LATEST_VERSION$ARCH.npk ./
|
if [ "${{ steps.get_latest.outputs.has_patched_npk }}" == "false" ]; then
|
||||||
sudo -E python3 patch.py npk routeros-$LATEST_VERSION$ARCH.npk
|
sudo mv ./new_iso/routeros-$LATEST_VERSION$ARCH.npk ./
|
||||||
|
sudo -E python3 patch.py npk routeros-$LATEST_VERSION$ARCH.npk
|
||||||
|
else
|
||||||
|
sudo -E python3 npk.py sign routeros-$LATEST_VERSION$ARCH.npk routeros-$LATEST_VERSION$ARCH.npk
|
||||||
|
fi
|
||||||
NPK_FILES=$(find ./new_iso/*.npk)
|
NPK_FILES=$(find ./new_iso/*.npk)
|
||||||
for file in $NPK_FILES; do
|
for file in $NPK_FILES; do
|
||||||
sudo -E python3 npk.py sign $file $file
|
sudo -E python3 npk.py sign $file $file
|
||||||
done
|
done
|
||||||
sudo cp routeros-$LATEST_VERSION$ARCH.npk ./new_iso/
|
sudo cp -f routeros-$LATEST_VERSION$ARCH.npk ./new_iso/
|
||||||
sudo -E python3 npk.py create ./new_iso/gps-$LATEST_VERSION$ARCH.npk ./option-$LATEST_VERSION$ARCH.npk option ./option.sfs -desc="busybox"
|
sudo -E python3 npk.py create ./new_iso/gps-$LATEST_VERSION$ARCH.npk ./option-$LATEST_VERSION$ARCH.npk option ./option.sfs -desc="busybox"
|
||||||
sudo cp option-$LATEST_VERSION$ARCH.npk ./new_iso/
|
sudo cp option-$LATEST_VERSION$ARCH.npk ./new_iso/
|
||||||
sudo -E python3 npk.py create ./new_iso/gps-$LATEST_VERSION$ARCH.npk ./python3-$LATEST_VERSION$ARCH.npk python3 ./python3.sfs -desc="python 3.11.9"
|
sudo -E python3 npk.py create ./new_iso/gps-$LATEST_VERSION$ARCH.npk ./python3-$LATEST_VERSION$ARCH.npk python3 ./python3.sfs -desc="python 3.11.9"
|
||||||
@@ -246,7 +295,7 @@ jobs:
|
|||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
- name: Cache refind
|
- name: Cache refind
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86'
|
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
id: cache-refind
|
id: cache-refind
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
@@ -254,11 +303,11 @@ jobs:
|
|||||||
key: refind
|
key: refind
|
||||||
|
|
||||||
- name: Get refind
|
- name: Get refind
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.cache-refind.outputs.cache-hit != 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.cache-refind.outputs.cache-hit != 'true' && steps.get_latest.outputs.has_patched_npk == '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
|
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
|
- name: Create install-image-${{ env.LATEST_VERSION }}.img
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86'
|
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
run: |
|
run: |
|
||||||
sudo modprobe nbd
|
sudo modprobe nbd
|
||||||
sudo apt-get install -y qemu-utils extlinux > /dev/null
|
sudo apt-get install -y qemu-utils extlinux > /dev/null
|
||||||
@@ -296,7 +345,7 @@ jobs:
|
|||||||
sudo rm ./install-image-$LATEST_VERSION.img
|
sudo rm ./install-image-$LATEST_VERSION.img
|
||||||
|
|
||||||
- name: Cache chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img.zip
|
- name: Cache chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img.zip
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
id: cache-chr-img
|
id: cache-chr-img
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
@@ -305,7 +354,7 @@ jobs:
|
|||||||
key: chr-${{ env.LATEST_VERSION }}-${{ matrix.arch }}.img
|
key: chr-${{ env.LATEST_VERSION }}-${{ matrix.arch }}.img
|
||||||
|
|
||||||
- name: Get chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img
|
- name: Get chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true' && steps.cache-chr-img.outputs.cache-hit != 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && steps.cache-chr-img.outputs.cache-hit != 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
run: |
|
run: |
|
||||||
sudo wget -nv -O chr.img.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/chr-$LATEST_VERSION$ARCH.img.zip
|
sudo wget -nv -O chr.img.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/chr-$LATEST_VERSION$ARCH.img.zip
|
||||||
sudo unzip chr.img.zip
|
sudo unzip chr.img.zip
|
||||||
@@ -313,7 +362,7 @@ jobs:
|
|||||||
sudo mv chr-$LATEST_VERSION$ARCH.img chr.img
|
sudo mv chr-$LATEST_VERSION$ARCH.img chr.img
|
||||||
|
|
||||||
- name: Create chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img
|
- name: Create chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
run: |
|
run: |
|
||||||
sudo modprobe nbd
|
sudo modprobe nbd
|
||||||
sudo apt-get install -y qemu-utils > /dev/null
|
sudo apt-get install -y qemu-utils > /dev/null
|
||||||
@@ -419,9 +468,14 @@ jobs:
|
|||||||
- name: Upload Files
|
- name: Upload Files
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||||
run: |
|
run: |
|
||||||
sudo mkdir -p ./publish/$LATEST_VERSION
|
if [ "${{ steps.get_latest.outputs.has_patched_npk }}" == "false" ]; then
|
||||||
sudo cp CHANGELOG ./publish/$LATEST_VERSION/
|
OUTDIR="$LATEST_VERSION-UNDONE"
|
||||||
sudo cp ./all_packages/*.npk ./publish/$LATEST_VERSION/
|
else
|
||||||
|
OUTDIR="$LATEST_VERSION"
|
||||||
|
fi
|
||||||
|
sudo mkdir -p ./publish/$OUTDIR
|
||||||
|
sudo cp CHANGELOG ./publish/$OUTDIR/
|
||||||
|
sudo cp ./all_packages/*.npk ./publish/$OUTDIR/
|
||||||
sudo chown -R root:root ./publish/
|
sudo chown -R root:root ./publish/
|
||||||
sudo apt-get install -y lftp ssh sshpass > /dev/null 2>&1
|
sudo apt-get install -y lftp ssh sshpass > /dev/null 2>&1
|
||||||
sudo -E lftp -u ${{ secrets.SSH_USERNAME }},'${{ secrets.SSH_PASSWORD }}' sftp://${{ secrets.SSH_SERVER }}:${{ secrets.SSH_PORT }} <<EOF
|
sudo -E lftp -u ${{ secrets.SSH_USERNAME }},'${{ secrets.SSH_PASSWORD }}' sftp://${{ secrets.SSH_SERVER }}:${{ secrets.SSH_PORT }} <<EOF
|
||||||
@@ -439,7 +493,7 @@ jobs:
|
|||||||
--data '{"purge_everything": true}'
|
--data '{"purge_everything": true}'
|
||||||
|
|
||||||
- name: Delete Release tag ${{ env.LATEST_VERSION }} ${{ matrix.arch }}
|
- name: Delete Release tag ${{ env.LATEST_VERSION }} ${{ matrix.arch }}
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
run: |
|
run: |
|
||||||
HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
|
HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
|
||||||
RELEASE_INFO=$(curl -s -H $HEADER https://api.github.com/repos/${{ github.repository }}/releases/tags/$LATEST_VERSION$ARCH)
|
RELEASE_INFO=$(curl -s -H $HEADER https://api.github.com/repos/${{ github.repository }}/releases/tags/$LATEST_VERSION$ARCH)
|
||||||
@@ -455,7 +509,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Create Release tag ${{ env.LATEST_VERSION }} ${{ matrix.arch }}
|
- name: Create Release tag ${{ env.LATEST_VERSION }} ${{ matrix.arch }}
|
||||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
if: steps.get_latest.outputs.has_new_version == 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
name: "RouterOS ${{ env.LATEST_VERSION }} ${{ matrix.arch }}"
|
name: "RouterOS ${{ env.LATEST_VERSION }} ${{ matrix.arch }}"
|
||||||
@@ -484,13 +538,20 @@ jobs:
|
|||||||
- name: Create Packages CSV File
|
- name: Create Packages CSV File
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get install ssh sshpass
|
sudo apt-get install ssh sshpass
|
||||||
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "chown -R 32768:32768 /rw/disk/${{ secrets.SSH_DIRECTORY }}/"
|
|
||||||
for file in artifacts/latest_version_*.json; do
|
for file in artifacts/latest_version_*.json; do
|
||||||
arch_channel=$(basename "$file" .json | sed 's/latest_version_//')
|
if [ -f "$file" ]; then
|
||||||
arch=$(echo "$arch_channel" | cut -d'_' -f1)
|
arch=$(jq -r '.arch' "$file")
|
||||||
channel=$(echo "$arch_channel" | cut -d'_' -f2)
|
channel=$(jq -r '.channel' "$file")
|
||||||
latest_version=$(jq -r '.latest_version' "$file")
|
latest_version=$(jq -r '.latest_version' "$file")
|
||||||
build_time=$(jq -r '.build_time' "$file")
|
build_time=$(jq -r '.build_time' "$file")
|
||||||
echo "Arch: $arch, Channel: $channel, Latest Version: $latest_version,Build Time: $build_time"
|
has_patched_npk=$(jq -r '.patched' "$file")
|
||||||
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "echo $latest_version $build_time | tee /rw/disk/${{ secrets.SSH_DIRECTORY }}/NEWESTa7.$channel; /rw/disk/${{ secrets.SSH_DIRECTORY }}/packages.sh /rw/disk/${{ secrets.SSH_DIRECTORY }}/$latest_version"
|
echo "Arch: $arch, Channel: $channel, Latest Version: $latest_version,Build Time: $build_time,Has Patched NPK: $has_patched_npk"
|
||||||
|
if [ "$has_patched_npk" == "false" ]; then
|
||||||
|
OUTDIR="$latest_version-UNDONE"
|
||||||
|
else
|
||||||
|
OUTDIR="$latest_version"
|
||||||
|
fi
|
||||||
|
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "echo $latest_version $build_time | tee /rw/disk/${{ secrets.SSH_DIRECTORY }}/NEWESTa7.$channel; /rw/disk/${{ secrets.SSH_DIRECTORY }}/packages.sh /rw/disk/${{ secrets.SSH_DIRECTORY }}/$OUTDIR"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "chown -R 32768:32768 /rw/disk/${{ secrets.SSH_DIRECTORY }}/"
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
[](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_6.yml)
|
||||||
|
[](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_7.yml)
|
||||||
# MikroTik RouterOS Patch [[English](README_EN.md)]
|
# MikroTik RouterOS Patch [[English](README_EN.md)]
|
||||||
|
|
||||||
### [[Discord](https://discord.gg/keV6MWQFtX)] [[Telegram](https://t.me/mikrotikpatch)] [[Keygen(Telegram Bot)](https://t.me/ROS_Keygen_Bot)]
|
### [[Discord](https://discord.gg/keV6MWQFtX)] [[Telegram](https://t.me/mikrotikpatch)] [[Keygen(Telegram Bot)](https://t.me/ROS_Keygen_Bot)]
|
||||||
@@ -50,3 +52,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
[](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_6.yml)
|
||||||
|
[](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_7.yml)
|
||||||
# MikroTik RouterOS Patch [[中文](README.md)]
|
# MikroTik RouterOS Patch [[中文](README.md)]
|
||||||
|
|
||||||
### [[Discord](https://discord.gg/keV6MWQFtX)] [[Telegram](https://t.me/mikrotikpatch)] [[Keygen(Telegram Bot)](https://t.me/ROS_Keygen_Bot)]
|
### [[Discord](https://discord.gg/keV6MWQFtX)] [[Telegram](https://t.me/mikrotikpatch)] [[Keygen(Telegram Bot)](https://t.me/ROS_Keygen_Bot)]
|
||||||
@@ -44,4 +46,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
51
patch.py
51
patch.py
@@ -1,7 +1,39 @@
|
|||||||
import subprocess,lzma
|
import subprocess,lzma
|
||||||
import struct,os
|
import struct,os,re
|
||||||
from npk import NovaPackage,NpkPartID,NpkFileContainer
|
from npk import NovaPackage,NpkPartID,NpkFileContainer
|
||||||
|
|
||||||
|
def replace_chunks(old_chunks,new_chunks,data,name):
|
||||||
|
pattern_parts = [re.escape(chunk) + b'(.{0,6})' for chunk in old_chunks[:-1]]
|
||||||
|
pattern_parts.append(re.escape(old_chunks[-1]))
|
||||||
|
pattern_bytes = b''.join(pattern_parts)
|
||||||
|
pattern = re.compile(pattern_bytes, flags=re.DOTALL)
|
||||||
|
def replace_match(match):
|
||||||
|
replaced = b''.join([new_chunks[i] + match.group(i+1) for i in range(len(new_chunks) - 1)])
|
||||||
|
replaced += new_chunks[-1]
|
||||||
|
print(f'{name} public key patched {b"".join(old_chunks)[:16].hex().upper()}...')
|
||||||
|
return replaced
|
||||||
|
return re.sub(pattern, replace_match, data)
|
||||||
|
|
||||||
|
def replace_key(old,new,data,name=''):
|
||||||
|
old_chunks = [old[i:i+4] for i in range(0, len(old), 4)]
|
||||||
|
new_chunks = [new[i:i+4] for i in range(0, len(new), 4)]
|
||||||
|
data = replace_chunks(old_chunks, new_chunks, data,name)
|
||||||
|
key_map = [28,19,25,16,14,3,24,15,22,8,6,17,11,7,9,23,18,13,10,0,26,21,2,5,20,30,31,4,27,29,1,12,]
|
||||||
|
old_chunks = [bytes([old[i]]) for i in key_map]
|
||||||
|
new_chunks = [bytes([new[i]]) for i in key_map]
|
||||||
|
data = replace_chunks(old_chunks, new_chunks, data,name)
|
||||||
|
|
||||||
|
if 'ARCH' in os.environ and os.environ['ARCH'] == '-arm64':
|
||||||
|
old_bytes = old_chunks[4] + old_chunks[5] + old_chunks[2] + old_chunks[0] + old_chunks[1] + old_chunks[6] + old_chunks[7]
|
||||||
|
new_bytes = new_chunks[4] + new_chunks[5] + new_chunks[2] + new_chunks[0] + new_chunks[1] + new_chunks[6] + new_chunks[7]
|
||||||
|
if old_bytes in data:
|
||||||
|
print(f'{name} public key patched {old[:16].hex().upper()}...')
|
||||||
|
data = data.replace(old_bytes,new_bytes)
|
||||||
|
old_codes = [bytes.fromhex('793583E2'),bytes.fromhex('FD3A83E2'),bytes.fromhex('193D83E2')]
|
||||||
|
new_codes = [bytes.fromhex('FF34A0E3'),bytes.fromhex('753C83E2'),bytes.fromhex('FC3083E2')]
|
||||||
|
data = replace_chunks(old_codes, new_codes, data,name)
|
||||||
|
return data
|
||||||
|
|
||||||
def patch_bzimage(data:bytes,key_dict:dict):
|
def patch_bzimage(data:bytes,key_dict:dict):
|
||||||
PE_TEXT_SECTION_OFFSET = 414
|
PE_TEXT_SECTION_OFFSET = 414
|
||||||
HEADER_PAYLOAD_OFFSET = 584
|
HEADER_PAYLOAD_OFFSET = 584
|
||||||
@@ -22,9 +54,7 @@ def patch_bzimage(data:bytes,key_dict:dict):
|
|||||||
initramfs = initramfs[:cpio_offset2]
|
initramfs = initramfs[:cpio_offset2]
|
||||||
new_initramfs = initramfs
|
new_initramfs = initramfs
|
||||||
for old_public_key,new_public_key in key_dict.items():
|
for old_public_key,new_public_key in key_dict.items():
|
||||||
if old_public_key in new_initramfs:
|
new_initramfs = replace_key(old_public_key,new_public_key,new_initramfs,'initramfs')
|
||||||
print(f'initramfs public key patched {old_public_key[:16].hex().upper()}...')
|
|
||||||
new_initramfs = new_initramfs.replace(old_public_key,new_public_key)
|
|
||||||
new_vmlinux = vmlinux.replace(initramfs,new_initramfs)
|
new_vmlinux = vmlinux.replace(initramfs,new_initramfs)
|
||||||
new_vmlinux_xz = lzma.compress(new_vmlinux,check=lzma.CHECK_CRC32,filters=[
|
new_vmlinux_xz = lzma.compress(new_vmlinux,check=lzma.CHECK_CRC32,filters=[
|
||||||
{"id": lzma.FILTER_X86},
|
{"id": lzma.FILTER_X86},
|
||||||
@@ -83,9 +113,7 @@ def patch_initrd_xz(initrd_xz:bytes,key_dict:dict,ljust=True):
|
|||||||
initrd = lzma.decompress(initrd_xz)
|
initrd = lzma.decompress(initrd_xz)
|
||||||
new_initrd = initrd
|
new_initrd = initrd
|
||||||
for old_public_key,new_public_key in key_dict.items():
|
for old_public_key,new_public_key in key_dict.items():
|
||||||
if old_public_key in new_initrd:
|
new_initrd = replace_key(old_public_key,new_public_key,new_initrd,'initrd')
|
||||||
print(f'initrd public key patched {old_public_key[:16].hex().upper()}...')
|
|
||||||
new_initrd = new_initrd.replace(old_public_key,new_public_key)
|
|
||||||
preset = 6
|
preset = 6
|
||||||
new_initrd_xz = lzma.compress(new_initrd,check=lzma.CHECK_CRC32,filters=[{"id": lzma.FILTER_LZMA2, "preset": preset }] )
|
new_initrd_xz = lzma.compress(new_initrd,check=lzma.CHECK_CRC32,filters=[{"id": lzma.FILTER_LZMA2, "preset": preset }] )
|
||||||
while len(new_initrd_xz) > len(initrd_xz) and preset < 9:
|
while len(new_initrd_xz) > len(initrd_xz) and preset < 9:
|
||||||
@@ -254,14 +282,15 @@ def patch_kernel(data:bytes,key_dict):
|
|||||||
def patch_squashfs(path,key_dict):
|
def patch_squashfs(path,key_dict):
|
||||||
for root, dirs, files in os.walk(path):
|
for root, dirs, files in os.walk(path):
|
||||||
for file in files:
|
for file in files:
|
||||||
|
if file =='loader':
|
||||||
|
continue
|
||||||
file = os.path.join(root,file)
|
file = os.path.join(root,file)
|
||||||
if os.path.isfile(file):
|
if os.path.isfile(file):
|
||||||
data = open(file,'rb').read()
|
data = open(file,'rb').read()
|
||||||
for old_public_key,new_public_key in key_dict.items():
|
for old_public_key,new_public_key in key_dict.items():
|
||||||
if old_public_key in data:
|
_data = replace_key(old_public_key,new_public_key,data,file)
|
||||||
print(f'{file} public key patched {old_public_key[:16].hex().upper()}...')
|
if _data != data:
|
||||||
data = data.replace(old_public_key,new_public_key)
|
open(file,'wb').write(_data)
|
||||||
open(file,'wb').write(data)
|
|
||||||
url_dict = {
|
url_dict = {
|
||||||
os.environ['MIKRO_LICENCE_URL'].encode():os.environ['CUSTOM_LICENCE_URL'].encode(),
|
os.environ['MIKRO_LICENCE_URL'].encode():os.environ['CUSTOM_LICENCE_URL'].encode(),
|
||||||
os.environ['MIKRO_UPGRADE_URL'].encode():os.environ['CUSTOM_UPGRADE_URL'].encode(),
|
os.environ['MIKRO_UPGRADE_URL'].encode():os.environ['CUSTOM_UPGRADE_URL'].encode(),
|
||||||
|
|||||||
Reference in New Issue
Block a user