Compare commits

..

141 Commits

Author SHA1 Message Date
elseif
677889f569 modified: .github/workflows/patch_v6.yml
modified:   .github/workflows/patch_v7.yml
2026-09-04 20:18:19 +08:00
elseif
b6d61fff0f modified: .github/workflows/main.yml 2026-09-04 20:01:34 +08:00
elseif
c2c50f2944 modified: .github/workflows/main.yml 2026-09-04 19:59:18 +08:00
elseif
49b2bf3366 modified: .github/workflows/main.yml 2026-09-04 19:52:44 +08:00
elseif
d2e0a07d49 modified: .github/workflows/main.yml 2026-09-04 19:39:16 +08:00
elseif
6d68d3767f modified: .github/workflows/main.yml
modified:   .github/workflows/patch_v6.yml
	modified:   .github/workflows/patch_v7.yml
2026-09-04 18:16:44 +08:00
elseif
e124f5a97b modified: .github/workflows/main.yml 2026-09-04 16:40:40 +08:00
elseif
e6462f2f03 modified: .github/workflows/main.yml
modified:   .github/workflows/patch_v6.yml
	modified:   .github/workflows/patch_v7.yml
2026-09-04 16:08:42 +08:00
elseif
5499390241 modified: .github/workflows/main.yml
modified:   .github/workflows/patch_v6.yml
	modified:   .github/workflows/patch_v7.yml
2026-09-04 15:35:13 +08:00
elseif
8162e48464 modified: .github/workflows/main.yml 2026-09-03 21:20:45 +08:00
elseif
fec8972b11 modified: .github/workflows/main.yml 2026-09-03 20:26:08 +08:00
elseif
6307abfa84 modified: .github/workflows/main.yml 2026-09-03 20:25:32 +08:00
elseif
777f09760b modified: .github/workflows/main.yml 2026-09-03 20:09:47 +08:00
elseif
da9a657837 modified: .github/workflows/main.yml 2026-09-03 20:05:46 +08:00
elseif
a925bfaa51 modified: .github/workflows/main.yml 2026-09-03 19:57:16 +08:00
elseif
41e23585ef modified: .github/workflows/main.yml 2026-09-03 19:54:49 +08:00
elseif
778e0adc1d modified: .github/workflows/main.yml 2026-09-03 19:52:18 +08:00
elseif
e9d87975ac modified: .github/workflows/main.yml 2026-09-03 19:51:38 +08:00
elseif
82febfa6ae modified: .github/workflows/main.yml 2026-09-03 19:50:27 +08:00
elseif
4a4c226a47 modified: .github/workflows/main.yml 2026-09-03 19:49:09 +08:00
elseif
24bb59e3b1 modified: .github/workflows/main.yml 2026-09-03 19:32:00 +08:00
elseif
88f8a40223 modified: .github/workflows/main.yml 2026-09-03 19:30:26 +08:00
elseif
f20530ed8c modified: .github/workflows/main.yml 2026-09-03 19:29:40 +08:00
elseif
dd24667ef4 modified: .github/workflows/main.yml 2026-09-03 19:08:08 +08:00
elseif
66de07e0a9 modified: .github/workflows/main.yml 2026-09-03 19:00:28 +08:00
elseif
b606604720 modified: .github/workflows/main.yml 2026-09-03 18:54:55 +08:00
elseif
452cf3133f modified: .github/workflows/main.yml
modified:   .github/workflows/patch_v7.yml
2026-09-03 15:27:09 +08:00
elseif
c00a16b842 modified: .github/workflows/patch_v7.yml 2026-09-03 11:01:00 +08:00
elseif
a5928e0373 modified: .github/workflows/patch_v7.yml 2026-09-02 11:41:43 +08:00
elseif
a2b711af17 modified: .github/workflows/patch_v7.yml 2026-09-02 11:29:55 +08:00
elseif
433252aa17 modified: .github/workflows/patch_v7.yml
modified:   setup-routeros.sh
2026-09-02 11:24:23 +08:00
elseif
3572a73c28 modified: .github/workflows/build_docker.yml
modified:   .github/workflows/main.yml
	modified:   .github/workflows/patch_v7.yml
	modified:   chr.sh
	modified:   setup-routeros.sh
2026-09-02 10:55:18 +08:00
elseif
640fb1cd62 modified: .github/workflows/patch_v7.yml 2026-09-01 19:37:45 +08:00
elseif
5f37a5ca17 modified: .github/workflows/patch_v7.yml
modified:   setup-routeros.sh
2026-09-01 15:59:58 +08:00
elseif
e7d95343fe modified: .github/workflows/patch_v7.yml
modified:   setup-routeros.sh
2026-09-01 14:14:40 +08:00
elseif
3745c4f679 modified: patch.py 2026-09-01 09:07:29 +08:00
elseif
453d75b40e modified: setup-routeros.sh 2026-09-01 09:01:41 +08:00
elseif
63eb12549c modified: setup-routeros.sh 2026-09-01 09:00:27 +08:00
elseif
7b994ba4d4 modified: .github/workflows/patch_v7.yml
renamed:    install_routeros.sh -> setup-routeros.sh
2026-09-01 08:36:19 +08:00
elseif
c09a094fe0 modified: .github/workflows/patch_v7.yml 2026-09-01 06:48:27 +08:00
elseif
8fba559697 modified: .github/workflows/patch_v7.yml 2026-08-31 22:37:11 +08:00
elseif
5cc61a7856 modified: .github/workflows/patch_v7.yml
modified:   install_routeros.sh
2026-08-31 22:27:59 +08:00
elseif
350f239333 modified: .github/workflows/patch_v7.yml 2026-08-31 11:38:12 +08:00
elseif
30a2ac1979 modified: .github/workflows/patch_v7.yml 2026-08-31 05:57:47 +08:00
elseif
6f9b747f25 modified: install_routeros.sh 2026-08-31 05:57:01 +08:00
elseif
7f55448ff3 modified: install_routeros.sh 2026-08-31 05:39:42 +08:00
elseif
be7efa6d48 modified: .github/workflows/patch_v7.yml
modified:   install_routeros.sh
2026-08-31 05:35:12 +08:00
elseif
6a76352efa modified: .github/workflows/patch_v7.yml
new file:   install_routeros.sh
	new file:   npkextract/Makefile
	new file:   npkextract/npkextract
	new file:   npkextract/npkextract.c
2026-08-30 07:38:00 +08:00
elseif
ea54dcf295 modified: .github/workflows/patch_v7.yml 2026-08-29 10:43:35 +08:00
elseif
beb4435dba modified: .github/workflows/patch_v7.yml 2026-08-29 10:34:20 +08:00
elseif
2c77a67e7d modified: .github/workflows/patch_v7.yml 2026-08-29 10:11:57 +08:00
elseif
66667fc2ed modified: .github/workflows/patch_v7.yml 2026-08-29 10:02:36 +08:00
elseif
39ae5ca66d modified: .github/workflows/patch_v7.yml 2026-08-29 09:53:20 +08:00
elseif
486d4afe26 modified: .github/workflows/patch_v7.yml 2026-08-29 09:48:39 +08:00
elseif
f984370098 modified: .github/workflows/patch_v7.yml 2026-08-29 09:47:30 +08:00
elseif
d13e050198 modified: .github/workflows/patch_v7.yml 2026-08-29 09:43:31 +08:00
elseif
daca50dced # modified: .github/workflows/patch_v7.yml 2026-08-29 09:33:33 +08:00
elseif
c126421897 modified: .github/workflows/patch_v7.yml 2026-08-28 21:35:43 +08:00
elseif
2a4ad51ca9 modified: .github/workflows/patch_v7.yml
modified:   busybox/busybox_arm64
	modified:   busybox/busybox_x86
2026-08-28 20:11:46 +08:00
elseif
a988945f52 update keygen 2026-08-26 01:34:39 +08:00
elseif
e94750a0d8 update keygen 2026-08-25 21:21:44 +08:00
elseif
489427c34f use musl-toolchain compile busybox 2026-08-25 19:48:01 +08:00
elseif
f7a2316049 Merge branch 'main' of github.com:elseif/MikroTikPatch 2026-08-25 17:22:51 +08:00
elseif
7410c6dc6b modified: .github/workflows/build_docker.yml
modified:   index.html
2026-08-25 17:22:35 +08:00
elseif
fc1d950da6 Update patch_v7.yml
Signed-off-by: elseif <elseif@live.cn>
2026-08-21 19:00:54 +08:00
elseif
622ba70c2a Update patch_v7.yml
Signed-off-by: elseif <elseif@live.cn>
2026-08-21 17:42:56 +08:00
elseif
4761e53917 Update main.yml
Signed-off-by: elseif <elseif@live.cn>
2026-08-21 17:40:18 +08:00
elseif
74a6a9c8dd modified: .github/workflows/build_docker.yml 2026-08-05 01:39:42 +08:00
elseif
e29a43041c modified: .github/workflows/build_docker.yml 2026-08-05 01:36:43 +08:00
elseif
3dc5e43434 modified: .github/workflows/build_docker.yml 2026-08-05 01:21:20 +08:00
elseif
68dcd99bc0 modified: keygen/keygen_arm64
modified:   keygen/keygen_x86
2026-07-22 23:00:59 +08:00
elseif
63bff2eed4 modified: keygen/keygen_arm64
modified:   keygen/keygen_x86
2026-07-22 19:21:38 +08:00
elseif
7163a9d629 Change alignment setting from 1 to 8 in sgdisk commands
change to 4k align

Signed-off-by: elseif <elseif@live.cn>
2026-07-22 04:38:39 +08:00
elseif
1403e9c3d5 Update cloud service section in README_CN.md
Signed-off-by: elseif <elseif@live.cn>
2026-07-22 04:29:43 +08:00
elseif
e7899eef0a Update README_CN.md
Signed-off-by: elseif <elseif@live.cn>
2026-07-22 04:29:20 +08:00
elseif
3bb2470535 Fix formatting in feature guide of README
Correct formatting of feature guide section in README.

Signed-off-by: elseif <elseif@live.cn>
2026-07-22 04:28:32 +08:00
elseif
072d684830 Update README.md
Signed-off-by: elseif <elseif@live.cn>
2026-07-22 04:27:52 +08:00
elseif
e2387c9ab3 Update README.md
Signed-off-by: elseif <elseif@live.cn>
2026-07-22 04:26:53 +08:00
elseif
3d7033276a Update README.md
Signed-off-by: elseif <elseif@live.cn>
2026-07-22 04:26:21 +08:00
elseif
34aba15f4c modified: .github/workflows/main.yml 2026-07-21 18:15:03 +08:00
elseif
e6b0e3a7c7 modified: .github/workflows/main.yml 2026-07-21 18:11:30 +08:00
elseif
bf1143fa81 modified: chr.sh 2026-07-21 13:54:24 +08:00
elseif
53cfc32c64 modified: README.md 2026-07-21 09:59:27 +08:00
elseif
4522e4c245 modified: README.md
modified:   README_CN.md
2026-07-21 09:38:40 +08:00
elseif
155823c638 modified: README.md
new file:   README_CN.md
2026-07-21 09:29:18 +08:00
elseif
5ef16bd0a2 modified: README.md 2026-07-21 09:17:20 +08:00
elseif
37bc80919a modified: README.md 2026-07-21 09:16:27 +08:00
elseif
57a1f98516 modified: README.md 2026-07-20 17:12:28 +08:00
elseif
45cfa3693a modified: README.md 2026-07-20 17:05:09 +08:00
elseif
bc4887e9e5 modified: .github/workflows/build_docker.yml 2026-07-20 16:57:24 +08:00
elseif
cd727fe33c modified: .github/workflows/build_docker.yml 2026-07-20 16:49:11 +08:00
elseif
017302e6e6 modified: .github/workflows/patch_v6.yml
modified:   .github/workflows/patch_v7.yml
	modified:   patch.py
2026-07-20 15:54:13 +08:00
elseif
c4aa017ec2 Simplify Docker run command in README
Updated Docker run command by removing memory, CPU, and disk parameters.

Signed-off-by: elseif <elseif@live.cn>
2026-07-19 19:46:44 +08:00
elseif
ec3fc1d8b0 Update README.md
Signed-off-by: elseif <elseif@live.cn>
2026-07-19 19:46:02 +08:00
elseif
9ff5bc4d49 Update README.md
Signed-off-by: elseif <elseif@live.cn>
2026-07-19 19:43:41 +08:00
elseif
2daa51ba67 modified: README.md 2026-07-18 17:02:34 +08:00
elseif
cebf02d5f6 modified: README.md 2026-07-18 17:00:15 +08:00
elseif
85582304cb modified: README.md 2026-07-18 16:56:24 +08:00
elseif
d4287e92a3 modified: README.md 2026-07-18 16:53:58 +08:00
elseif
4de5fd88c0 modified: README.md 2026-07-18 16:51:51 +08:00
elseif
d970a10e08 modified: README.md 2026-07-18 16:51:07 +08:00
elseif
88b7f61b42 modified: index.html 2026-07-18 16:23:42 +08:00
elseif
630e9be8e6 modified: README.md 2026-07-17 09:13:17 +08:00
elseif
b3398d2341 Merge branch 'main' of github.com:elseif/MikroTikPatch 2026-07-17 09:10:23 +08:00
elseif
7aabc6ffcd modified: README.md 2026-07-17 09:08:16 +08:00
elseif
17b6db1acc modified: README.md
modified:   README.md

Changes not staged for commit:
	modified:   README.md
2026-07-17 09:08:09 +08:00
elseif
a6e8bb3c87 modified: README.md 2026-07-17 09:06:37 +08:00
elseif
50b4c1036e modified: README.md 2026-07-17 09:04:42 +08:00
elseif
5e4e7eead0 deleted: README_EN.md
deleted:    README_PT.md
	deleted:    image/arm.png
	deleted:    image/install.png
	deleted:    image/mips.png
	deleted:    image/renew.png
	deleted:    image/renew_v6.png
	deleted:    image/routeros.png
2026-07-17 09:03:58 +08:00
elseif
37ba5451aa modified: README.md 2026-07-17 09:01:41 +08:00
elseif
e07ec52d34 modified: .github/workflows/build_docker.yml 2026-07-16 14:45:52 +08:00
elseif
bf73ab201b modified: .github/workflows/build_docker.yml 2026-07-16 14:42:38 +08:00
elseif
ae7943de83 modified: .github/workflows/build_docker.yml 2026-07-16 14:26:58 +08:00
elseif
3b42f1c5fb modified: .github/workflows/build_docker.yml 2026-07-16 14:22:52 +08:00
elseif
7b273f0464 modified: .github/workflows/build_docker.yml 2026-07-16 14:01:06 +08:00
elseif
5033270988 modified: .github/workflows/build_docker.yml 2026-07-16 13:54:42 +08:00
elseif
063cd7785f modified: .github/workflows/build_docker.yml 2026-07-16 13:28:07 +08:00
elseif
b628eaadd2 modified: .github/workflows/build_docker.yml 2026-07-16 13:25:36 +08:00
elseif
4d32f80f8b modified: .github/workflows/build_docker.yml 2026-07-16 13:19:44 +08:00
elseif
e576f75398 modified: .github/workflows/build_docker.yml 2026-07-16 13:15:39 +08:00
elseif
c7eba4be0c modified: .github/workflows/build_docker.yml 2026-07-16 13:14:00 +08:00
elseif
78a2720c82 modified: .github/workflows/build_docker.yml 2026-07-16 13:10:22 +08:00
elseif
9cc32db4d2 modified: .github/workflows/build_docker.yml 2026-07-16 12:47:25 +08:00
elseif
4f3f8b5e40 modified: .github/workflows/build_docker.yml 2026-07-16 12:43:14 +08:00
elseif
68e9f1f5c2 modified: .github/workflows/build_docker.yml 2026-07-16 12:14:25 +08:00
elseif
a46286d886 modified: .github/workflows/build_docker.yml 2026-07-16 10:03:43 +08:00
elseif
e44ea1504b modified: .github/workflows/build_docker.yml 2026-07-16 09:59:39 +08:00
elseif
57f2724d69 modified: .github/workflows/build_docker.yml 2026-07-16 09:57:55 +08:00
elseif
672c225645 modified: .github/workflows/build_docker.yml 2026-07-16 09:47:00 +08:00
elseif
ad036099ce modified: .github/workflows/build_docker.yml 2026-07-16 09:42:18 +08:00
elseif
723969a497 modified: .github/workflows/build_docker.yml 2026-07-16 09:31:54 +08:00
elseif
ae84c4ecde modified: .github/workflows/build_docker.yml 2026-07-16 09:12:32 +08:00
elseif
54c562f054 Simplify multi arch manifest creation
Removed unnecessary output of JSON file contents before creating the multi-architecture manifest.

Signed-off-by: elseif <elseif@live.cn>
2026-07-16 07:00:23 +08:00
elseif
ddb8fe368e Update Docker build workflow to use QEMU setup
Signed-off-by: elseif <elseif@live.cn>
2026-07-16 06:57:58 +08:00
elseif
e4138453e1 Add IMAGE variable for Docker build process
Signed-off-by: elseif <elseif@live.cn>
2026-07-16 06:55:37 +08:00
elseif
db0273d518 Output digests before creating Docker manifest
Add commands to output digests from JSON files before creating a multi-architecture Docker manifest.

Signed-off-by: elseif <elseif@live.cn>
2026-07-16 06:45:05 +08:00
elseif
c4cada441a Add permissions for package writing in workflow
Signed-off-by: elseif <elseif@live.cn>
2026-07-16 06:33:59 +08:00
elseif
89ea52c7df Refactor Docker build workflow and update inputs
Signed-off-by: elseif <elseif@live.cn>
2026-07-16 06:26:37 +08:00
elseif
0670bf0818 Add Patch_Development_V7 workflow for version v7
Signed-off-by: elseif <elseif@live.cn>
2026-07-16 03:20:46 +08:00
elseif
ea433daaf8 Add 'development' option to channel input
Signed-off-by: elseif <elseif@live.cn>
2026-07-16 03:20:05 +08:00
elseif
18fd42ae68 Rename jobs for V7 in GitHub Actions workflow
Signed-off-by: elseif <elseif@live.cn>
2026-07-16 01:16:56 +08:00
25 changed files with 2876 additions and 778 deletions

297
.github/workflows/build_docker.yml vendored Normal file
View File

@@ -0,0 +1,297 @@
name: Build CHR Docker
on:
schedule:
- cron: "00 10 * * *" # At UTC 09:00 (Beijing 17:00) on every day
workflow_dispatch:
inputs:
version:
description: "Specify version (e.g., 7.19.2), empty for latest"
required: false
default: ''
type: string
force:
description: "Force rebuild even if version already exists"
required: false
default: false
type: boolean
permissions:
packages: write
jobs:
Prepare:
runs-on: ubuntu-24.04
outputs:
MATRIX: ${{ steps.filter_matrix.outputs.MATRIX }}
steps:
- name: Get versions and generate matrix
id: get_versions
run: |
VERSION="${{ inputs.version }}"
if [ -n "$VERSION" ]; then
MATRIX=$(jq -c -n '
[
{ "version": $VERSION, "channel": ""}
]
' --arg VERSION "$VERSION")
else
TIMESTAMP=$(date +%s)
LONG_TERM=$(wget -nv -O - "https://upgrade.mikrotik.ltd/routeros/NEWESTa7.long-term?t=$TIMESTAMP" | cut -d ' ' -f1)
STABLE=$(wget -nv -O - "https://upgrade.mikrotik.ltd/routeros/NEWESTa7.stable?t=$TIMESTAMP" | cut -d ' ' -f1)
echo "Long-term version: $LONG_TERM"
echo "Stable version: $STABLE"
if [ -z "$LONG_TERM" ]; then
echo "Failed to get long-term version"
exit 1
fi
if [ -z "$STABLE" ]; then
echo "Failed to get stable version"
exit 1
fi
MATRIX=$(jq -c -n '
[
{version: $LONG_TERM, channel: "long-term"},
{version: $STABLE, channel: "stable"}
]
' --arg LONG_TERM "$LONG_TERM" --arg STABLE "$STABLE")
fi
echo "Generated matrix: $MATRIX"
echo "MATRIX=$MATRIX" >> $GITHUB_OUTPUT
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Filter already-published versions from matrix
id: filter_matrix
env:
IMAGE: "ghcr.io/${{ github.repository_owner }}/chr"
FORCE: ${{ github.event.inputs.force == 'true' }}
run: |
MATRIX='${{ steps.get_versions.outputs.MATRIX }}'
if [ "$FORCE" = "true" ]; then
echo "Force mode enabled, skipping version existence check."
FILTERED="$MATRIX"
else
FILTERED='[]'
while read -r row; do
VERSION=$(echo "$row" | jq -r '.version')
CHANNEL=$(echo "$row" | jq -r '.channel')
set +e
docker manifest inspect "${IMAGE}:${VERSION}" >/dev/null 2>&1
RET=$?
set -e
if [ "$RET" -eq 0 ]; then
echo "Skipping already published version: ${VERSION}"
else
FILTERED=$(echo "$FILTERED" | jq -c --arg VERSION "$VERSION" --arg CHANNEL "$CHANNEL" '. + [{"version": $VERSION, "channel": $CHANNEL}]')
fi
done < <(echo "$MATRIX" | jq -c '.[]')
fi
echo "Filtered matrix: $FILTERED"
echo "MATRIX=$FILTERED" >> "$GITHUB_OUTPUT"
Build:
if: needs.Prepare.outputs.MATRIX != '[]'
runs-on: ubuntu-24.04
needs: Prepare
strategy:
max-parallel: 1
matrix:
include: ${{ fromJson(needs.Prepare.outputs.MATRIX != '[]' && needs.Prepare.outputs.MATRIX || '[{"version":"__NO_BUILD__","channel":""}]') }}
env:
TZ: 'Asia/Shanghai'
VERSION: ${{ matrix.version }}
CHANNEL: ${{ matrix.channel }}
IMAGE: "ghcr.io/${{ github.repository_owner }}/chr"
DOCKER_BUILD_SUMMARY: 'false'
DOCKER_BUILD_RECORD_UPLOAD: 'false'
steps:
- name: Show build info
run: |
echo "Version: ${{ env.VERSION }}"
echo "Channel: ${{ env.CHANNEL }}"
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download CHR image
run: |
# x86 架构
mkdir -p "amd64"
wget -nv -O "amd64/chr-$VERSION.img.zip" \
"https://github.com/elseif/MikroTikPatch/releases/download/$VERSION/chr-$VERSION-legacy-bios.img.zip"
unzip "amd64/chr-$VERSION.img.zip" -d "amd64/"
mv "amd64/chr-$VERSION-legacy-bios.img" "amd64/chr.img"
rm "amd64/chr-$VERSION.img.zip"
# arm64 架构
mkdir -p "arm64"
wget -nv -O "arm64/chr-$VERSION-arm64.img.zip" \
"https://github.com/elseif/MikroTikPatch/releases/download/$VERSION-arm64/chr-$VERSION-arm64.img.zip"
unzip "arm64/chr-$VERSION-arm64.img.zip" -d "arm64/"
mv "arm64/chr-$VERSION-arm64.img" "arm64/chr.img"
rm "arm64/chr-$VERSION-arm64.img.zip"
ls -la amd64/ arm64/
- name: Create start.sh
run: |
cat <<'EOF' > start.sh
#!/bin/sh
set -e
MEM="${MEM:=512m}"
DISK="${DISK:=128M}"
CPUS="${CPUS:=1}"
bridge_index=0
get_mac_address() {
ifname="$1"
ip link show "$ifname" 2>/dev/null | awk '/link\/ether/ {print $2}'
}
increment_mac() {
mac=$1
mac_no_colons=$(echo "$mac" | tr -d ':' | tr '[:lower:]' '[:upper:]')
mac_dec=$((16#${mac_no_colons}))
mac_dec=$((mac_dec + 1))
mac_hex=$(printf "%012X" "$mac_dec")
echo "$mac_hex" | sed 's/.\{2\}/&:/g;s/:$//'
}
echo "" > /etc/qemu/bridge.conf
qemu="qemu-system-x86_64"
if [[ `uname -m` == "aarch64" ]]; then
qemu="qemu-system-aarch64 -pflash /usr/share/qemu/edk2-aarch64-code.fd -M virt"
fi
if [ -e /dev/kvm ]; then
qemu="$qemu -enable-kvm -cpu host"
else
if [[ `uname -m` == "aarch64" ]]; then
qemu="$qemu -cpu cortex-a57"
fi
fi
img=`ls /diskimage/*.img`
qemu="$qemu -nographic -m $MEM -smp cpus=$CPUS -drive file=$img,format=raw"
truncate -s $DISK $img
while read -r line; do
iface=$(echo "$line" | sed "s/ *\([a-z0-9]*\):.*/\1/")
if [[ "$iface" =~ " " ]]; then
continue
fi
if [[ "$iface" =~ ^br ]]; then
continue
fi
if [[ "$iface" == "lo" ]]; then
continue
fi
if [[ "$iface" == "" ]]; then
continue
fi
echo "iface: $iface"
bridge="br$bridge_index"
ip link add name "$bridge" type bridge
ip link set dev "$bridge" up
ip link set "$iface" master "$bridge"
echo "allow $bridge" >> /etc/qemu/bridge.conf
veth_mac=$(get_mac_address "$iface")
tap_mac=$(increment_mac "$veth_mac")
bridge_index=$((bridge_index + 1))
qemu="$qemu -netdev bridge,id=$bridge,br=$bridge -device virtio-net,netdev=$bridge,mac=$tap_mac "
done < /proc/net/dev
echo "qemu: $qemu"
exec $qemu
EOF
chmod +x start.sh
- name: Create Dockerfile
run: |
cat > Dockerfile << 'EOF'
FROM alpine:latest
ARG TARGETARCH
ARG VERSION
RUN case "$TARGETARCH" in \
amd64) apk add --no-cache qemu-system-x86_64 ;; \
arm64) apk add --no-cache qemu-system-aarch64 ;; \
esac \
&& rm -rf /var/cache/apk/*
RUN mkdir -p /diskimage
COPY ${TARGETARCH}/*.img /diskimage/
COPY start.sh /start.sh
ENTRYPOINT ["/start.sh"]
EOF
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and Push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE }}:${{ env.VERSION }}
build-args: VERSION=${{ env.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
sbom: false
outputs: >
type=image,
annotation-index.org.opencontainers.image.title=MikroTik CHR RouterOS,
annotation-index.org.opencontainers.image.description=MikroTik CHR (Cloud Hosted Router) running on QEMU with Docker,
annotation-index.org.opencontainers.image.version=${{ env.VERSION }},
annotation-index.org.opencontainers.image.url=https://mikrotik.ltd
- name: Update channel tags
if: env.CHANNEL != ''
run: |
TAGS="-t ${{ env.IMAGE }}:${{ env.CHANNEL }}"
if [ "${{ env.CHANNEL }}" = "stable" ]; then
TAGS="$TAGS -t ${{ env.IMAGE }}:latest"
fi
echo "Creating tags: $TAGS"
docker buildx imagetools create $TAGS ${{ env.IMAGE }}:${{ env.VERSION }}
- name: Save Docker Image as tar
run: |
mkdir -p artifacts
echo "Exporting amd64 tar..."
docker pull --platform linux/amd64 ${{ env.IMAGE }}:${{ env.VERSION }}
docker save ${{ env.IMAGE }}:${{ env.VERSION }} -o artifacts/chr-${{ env.VERSION }}-amd64.tar
echo "Exporting arm64 tar..."
docker pull --platform linux/arm64 ${{ env.IMAGE }}:${{ env.VERSION }}
docker save ${{ env.IMAGE }}:${{ env.VERSION }} -o artifacts/chr-${{ env.VERSION }}-arm64.tar
ls -lh artifacts/
- name: Upload tar artifact
uses: actions/upload-artifact@v7
with:
name: chr-${{ env.VERSION }}-docker-images
path: artifacts/
retention-days: 30

View File

@@ -2,11 +2,40 @@
name: Patch Mikrotik RouterOS
on:
schedule:
- cron: "00 10 * * *" # At UTC 10:00 (Beijing 18:00) on every day
- cron: "25 * * * *" # Every hour at minute 25 (UTC)
workflow_dispatch:
inputs:
version:
description: 'Select Version (v6/v7/all)'
stable:
description: 'Build stable channel'
required: false
type: boolean
default: true
long_term:
description: 'Build long-term channel'
required: false
type: boolean
default: false
development:
description: 'Build development channel'
required: false
type: boolean
default: false
testing:
description: 'Build testing channel'
required: false
type: boolean
default: false
arch:
description: 'Architectures (x86, arm64)'
required: true
default: 'all'
type: choice
options:
- all
- x86
- arm64
major_version:
description: 'RouterOS major version'
required: true
default: 'all'
type: choice
@@ -14,53 +43,232 @@ on:
- all
- v6
- v7
version:
description: '(e.g. 7.xx.x), empty for latest'
required: false
default: ''
type: string
buildtime:
description: "build imestamp, leave empty for original"
required: false
default: ''
type: string
release:
description: 'Release'
required: false
default: false
type: boolean
force:
description: 'Force patch even if already patched'
required: false
default: false
type: boolean
jobs:
Patch_Stable:
if: |
(github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.version == 'all' || github.event.inputs.version == 'v7'))
uses: ./.github/workflows/patch_v7.yml
with:
channel: stable
release: true
secrets: inherit
Patch_LongTerm:
if: |
(github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.version == 'all' || github.event.inputs.version == 'v7'))
uses: ./.github/workflows/patch_v7.yml
with:
channel: long-term
release: true
secrets: inherit
Prepare_Patch:
runs-on: ubuntu-latest
outputs:
upgrades_v6: ${{ steps.prepare.outputs.upgrades_v6 }}
upgrades_v7: ${{ steps.prepare.outputs.upgrades_v7 }}
patch_v6: ${{ steps.prepare.outputs.patch_v6 }}
patch_v7: ${{ steps.prepare.outputs.patch_v7 }}
archs: ${{ steps.prepare.outputs.archs }}
steps:
- name: Prepare Patch
id: prepare
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
channels=()
[[ "${{ inputs.stable }}" == "true" ]] && channels+=("stable")
[[ "${{ inputs.long_term }}" == "true" ]] && channels+=("long-term")
[[ "${{ inputs.development }}" == "true" ]] && channels+=("development")
[[ "${{ inputs.testing }}" == "true" ]] && channels+=("testing")
if [ ${#channels[@]} -eq 0 ]; then
echo "ERROR: At least one channel must be selected"
exit 1
fi
CHANNELS=$(printf '%s\n' "${channels[@]}" | jq -Rsc 'split("\n")[:-1]')
VERSION_INPUT='${{ inputs.version }}'
MAJOR_VERSION='${{ inputs.major_version }}'
FORCE="${{ inputs.force || 'false' }}"
Patch_Testing:
if: |
(github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.version == 'all' || github.event.inputs.version == 'v7'))
uses: ./.github/workflows/patch_v7.yml
with:
channel: testing
release: true
secrets: inherit
if [[ -n "$VERSION_INPUT" && "$MAJOR_VERSION" != "all" ]]; then
case "$MAJOR_VERSION" in
v6)
if [[ ! "$VERSION_INPUT" =~ ^6\. ]]; then
echo "ERROR: $VERSION_INPUT is not RouterOS v6"
exit 1
fi
;;
v7)
if [[ ! "$VERSION_INPUT" =~ ^7\. ]]; then
echo "ERROR: $VERSION_INPUT is not RouterOS v7"
exit 1
fi
;;
esac
fi
else
CHANNELS='["stable","long-term","development","testing"]'
VERSION_INPUT=""
MAJOR_VERSION="all"
FORCE="false"
fi
Patch_Stable_V6:
if: |
(github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.version == 'all' || github.event.inputs.version == 'v6'))
ARCH_INPUT="${{ inputs.arch || 'all' }}"
if [[ "$ARCH_INPUT" == "all" ]]; then
if [[ "$MAJOR_VERSION" == "v6" ]]; then
ARCHS='["x86"]'
else
ARCHS='["x86","arm64"]'
fi
else
if [[ "$ARCH_INPUT" == "arm64" && "$MAJOR_VERSION" == "v6" ]]; then
echo "ERROR: RouterOS v6 does not support arm64"
exit 1
fi
ARCHS=$(jq -c -n --arg arch "$ARCH_INPUT" '[$arch]')
fi
echo "Major Version: $MAJOR_VERSION"
echo "Force: $FORCE"
echo "Architectures:"
echo "$ARCHS" | jq .
echo "Channels:"
echo "$CHANNELS" | jq .
if [[ -n "$VERSION_INPUT" ]]; then
echo "Using fixed version: $VERSION_INPUT"
CANDIDATES=$(jq -cn --arg version "$VERSION_INPUT" --argjson channels "$CHANNELS" '
[{ version:$version, channels:$channels}]
')
else
echo "Resolving version from channels"
OFFICIAL_UPGRADE=$(curl -fsSL https://upgrade.mikrotik.com/routeros/upgrade.json) || { echo "ERROR: Failed to fetch OFFICIAL_UPGRADE" >&2; exit 1; }
echo "$OFFICIAL_UPGRADE" | jq -e . >/dev/null 2>&1 || { echo "ERROR: OFFICIAL_UPGRADE is not valid JSON" >&2; exit 1; }
CANDIDATES=$( echo "$OFFICIAL_UPGRADE" |
jq -c --argjson channels "$CHANNELS" --arg major "$MAJOR_VERSION" '
[
$channels[] as $c |
if $major == "v6" then
{
version: .upgradePaths["NEWEST6."+ $c].version,
channel: $c
}
elif $major == "v7" then
{
version: .upgradePaths["NEWESTa7."+ $c].version,
channel: $c
}
else
[
{
version: .upgradePaths["NEWEST6."+ $c].version,
channel: $c
},
{
version: .upgradePaths["NEWESTa7."+ $c].version,
channel: $c
}
]
end
] |
flatten |
map(select(.version != null)) |
sort_by(.version) |
group_by(.version) |
map({
version: .[0].version,
channels: map(.channel)
})
'
)
fi
echo "Candidates:"
echo "$CANDIDATES" | jq .
if [[ "$FORCE" == "true" ]]; then
echo "Force mode enabled: skip patched version check"
else
echo "Checking patched versions"
PATCH_UPGRADE=$(curl -fsSL https://upgrade.mikrotik.ltd/routeros/upgrade.json) || { echo "ERROR: Failed to fetch PATCH_UPGRADE" >&2; exit 1; }
echo "$PATCH_UPGRADE" | jq -e . >/dev/null 2>&1 || { echo "ERROR: PATCH_UPGRADE is not valid JSON" >&2; exit 1; }
PATCH_VERSIONS=$(echo "$PATCH_UPGRADE" | jq -c '
[.upgradePaths[].version] | unique
')
ALREADY_PATCHED=$(echo "$CANDIDATES" | jq -c --argjson patched "$PATCH_VERSIONS" '
map(select(
(.version as $v | ($patched | index($v))) != null
))
')
echo "Already patched:"
echo "$ALREADY_PATCHED" | jq .
CANDIDATES=$(echo "$CANDIDATES" | jq -c --argjson patched "$PATCH_VERSIONS" '
map(select(
(.version as $v | ($patched | index($v))) == null
))
')
fi
V6_MATRIX=$(echo "$CANDIDATES" | jq -c 'map(select(.version | startswith("6.")))')
V7_MATRIX=$(echo "$CANDIDATES" | jq -c 'map(select(.version | startswith("7.")))')
echo "upgrades_v6=$V6_MATRIX" >> "$GITHUB_OUTPUT"
echo "upgrades_v7=$V7_MATRIX" >> "$GITHUB_OUTPUT"
echo "archs=$ARCHS" >> "$GITHUB_OUTPUT"
echo "patch_v6=$(jq 'length > 0' <<< "$V6_MATRIX")" >> "$GITHUB_OUTPUT"
echo "patch_v7=$(jq 'length > 0' <<< "$V7_MATRIX")" >> "$GITHUB_OUTPUT"
echo "=== Upgrades V6 ==="
echo "$V6_MATRIX" | jq .
echo "=== Upgrades V7 ==="
echo "$V7_MATRIX" | jq .
echo "=== Architectures ==="
echo "$ARCHS" | jq .
Patch_V6:
needs: Prepare_Patch
if: needs.Prepare_Patch.result == 'success' && needs.Prepare_Patch.outputs.patch_v6 == 'true'
uses: ./.github/workflows/patch_v6.yml
strategy:
matrix:
target: ${{ fromJson(needs.Prepare_Patch.outputs.upgrades_v6) }}
fail-fast: false
with:
channel: stable
release: true
version: ${{ matrix.target.version }}
channels: ${{ toJson(matrix.target.channels) }}
archs: ${{ needs.Prepare_Patch.outputs.archs }}
buildtime: ${{ inputs.buildtime }}
release: ${{ github.event_name != 'workflow_dispatch' || inputs.release }}
secrets: inherit
Patch_LongTerm_V6:
if: |
(github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.version == 'all' || github.event.inputs.version == 'v6'))
uses: ./.github/workflows/patch_v6.yml
Patch_V7:
needs: Prepare_Patch
if: needs.Prepare_Patch.result == 'success' && needs.Prepare_Patch.outputs.patch_v7 == 'true'
uses: ./.github/workflows/patch_v7.yml
strategy:
matrix:
target: ${{ fromJson(needs.Prepare_Patch.outputs.upgrades_v7) }}
fail-fast: false
with:
channel: long-term
release: true
secrets: inherit
version: ${{ matrix.target.version }}
channels: ${{ toJson(matrix.target.channels) }}
archs: ${{ needs.Prepare_Patch.outputs.archs }}
buildtime: ${{ inputs.buildtime }}
release: ${{ github.event_name != 'workflow_dispatch' || inputs.release }}
secrets: inherit

View File

@@ -1,47 +1,23 @@
name: Patch RouterOS v6
on:
workflow_dispatch:
inputs:
channel:
description: 'Channel (stable, long-term)'
required: true
default: 'stable'
type: choice
options:
- stable
- long-term
version:
description: "Specify version (e.g., 6.49.19), empty for latest"
required: false
default: ''
type: string
buildtime:
description: "Custom build time, leave empty for original"
required: false
default: ''
type: string
release:
description: "Release to Upload "
required: false
default: false
type: boolean
workflow_call:
inputs:
channel:
version:
required: true
type: string
version:
required: false
channels:
required: true
type: string
default: ''
archs:
required: true
type: string
release:
required: true
type: boolean
buildtime:
required: false
type: string
default: ''
release:
required: false
type: boolean
default: false
env:
CUSTOM_LICENSE_PRIVATE_KEY: ${{ secrets.CUSTOM_LICENSE_PRIVATE_KEY }}
@@ -60,70 +36,25 @@ env:
CUSTOM_RENEW_URL: ${{ secrets.CUSTOM_RENEW_URL }}
MIKRO_CLOUD_URL: ${{ secrets.MIKRO_CLOUD_URL }}
CUSTOM_CLOUD_URL: ${{ secrets.CUSTOM_CLOUD_URL }}
MIKRO_CLOUD2_URL: ${{ secrets.MIKRO_CLOUD2_URL }}
CUSTOM_CLOUD2_URL: ${{ secrets.CUSTOM_CLOUD2_URL }}
jobs:
Prepare_Patch:
runs-on: ubuntu-24.04
outputs:
VERSION: ${{ steps.prepare.outputs.VERSION }}
BUILD_TIME: ${{ steps.prepare.outputs.BUILD_TIME }}
ARCHS: ${{ steps.prepare.outputs.ARCHS }}
RELEASE: ${{ steps.prepare.outputs.RELEASE }}
SKIP_BUILD: ${{ steps.prepare.outputs.SKIP_BUILD }}
steps:
- name: Prepare Patch for ${{ inputs.channel }}
id: prepare
run: |
CHANNEL="${{ inputs.channel }}"
VERSION="${{ inputs.version }}"
RELEASE="${{ inputs.release }}"
BUILD_TIME="${{ inputs.buildtime }}"
ARCHS='["x86"]'
SKIP_BUILD=false
if [ -z "$VERSION" ]; then
echo "Checking latest version from $CHANNEL channel..."
TIMESTAMP=$(date +%s)
NEWEST=$(wget -nv -O - "https://${{ env.MIKRO_UPGRADE_URL }}/routeros/NEWEST6.$CHANNEL?t=$TIMESTAMP")
VERSION=$(echo "$NEWEST" | cut -d ' ' -f1)
echo "Official version: $VERSION"
if [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then
PATCH_NEWEST=$(wget -nv -O - "https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/NEWEST6.$CHANNEL?t=$TIMESTAMP" 2>/dev/null || echo "")
PATCH_VERSION=$(echo "$PATCH_NEWEST" | cut -d ' ' -f1)
echo "Patch version: ${PATCH_VERSION:-none}"
if [ "$PATCH_VERSION" == "$VERSION" ]; then
echo "No new version for $CHANNEL, skipping..."
SKIP_BUILD=true
else
echo "New version $VERSION available, building..."
fi
fi
fi
echo "SKIP_BUILD=$SKIP_BUILD" >> $GITHUB_OUTPUT
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "BUILD_TIME=$BUILD_TIME" >> $GITHUB_OUTPUT
echo "ARCHS=$ARCHS" >> $GITHUB_OUTPUT
echo "RELEASE=$RELEASE" >> $GITHUB_OUTPUT
echo "Version: $VERSION, Archs: $ARCHS"
Patch_RouterOS:
needs: Prepare_Patch
if: needs.Prepare_Patch.outputs.SKIP_BUILD == 'false'
runs-on: ubuntu-24.04
strategy:
matrix:
arch: ${{ fromJson(needs.Prepare_Patch.outputs.ARCHS) }}
arch: ${{ fromJson( inputs.archs ) }}
fail-fast: false
env:
TZ: 'Asia/Shanghai'
CHANNEL: ${{ inputs.channel }}
CHANNELS: ${{ inputs.channels }}
ARCH: ${{ matrix.arch }}
VERSION: ${{ needs.Prepare_Patch.outputs.VERSION }}
BUILD_TIME: ${{ needs.Prepare_Patch.outputs.BUILD_TIME }}
BUILD_DIR: "/tmp/build/${{ needs.Prepare_Patch.outputs.VERSION }}"
PUBLISH_DIR: "${{ github.workspace }}/publish/${{ needs.Prepare_Patch.outputs.VERSION }}"
VERSION: ${{ inputs.version }}
BUILD_TIME: ${{ inputs.buildtime }}
RELEASE: ${{ inputs.release }}
BUILD_DIR: "/tmp/build/${{ inputs.version }}}"
PUBLISH_DIR: "${{ github.workspace }}/publish/${{ inputs.version }}"
ARCH_EXT: ""
PACKAGES: ""
steps:
@@ -156,7 +87,7 @@ jobs:
- name: Create Squashfs for Option Package
run: |
echo "Creating Option Package Squashfs for channel: $CHANNEL, arch: $ARCH"
echo "Creating Option Package Squashfs for arch: $ARCH"
mkdir -p $BUILD_DIR/option-root/bin/
cp ./busybox/busybox_$ARCH $BUILD_DIR/option-root/bin/busybox
chmod +x $BUILD_DIR/option-root/bin/busybox
@@ -427,7 +358,7 @@ jobs:
rm $BUILD_DIR/chr-$VERSION$ARCH_EXT.*
- name: Upload Files as Artifact (No Release)
if: needs.Prepare_Patch.outputs.RELEASE == 'false'
if: env.RELEASE == 'false'
uses: actions/upload-artifact@v7
with:
name: mikrotik-${{ env.VERSION }}${{ env.ARCH_EXT }}
@@ -436,7 +367,7 @@ jobs:
${{ env.PUBLISH_DIR }}/*.iso
- name: Generate SHA256 checksum files
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
run: |
(
cd $PUBLISH_DIR
@@ -449,7 +380,7 @@ jobs:
)
- name: Delete Release tag ${{ env.VERSION }}${{ env.ARCH_EXT }}
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
run: |
sed -i "1i Build Time:$BUILD_TIME" $PUBLISH_DIR/CHANGELOG
HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
@@ -468,7 +399,7 @@ jobs:
fi
- name: Create Release tag ${{ env.VERSION }}${{ env.ARCH_EXT }}
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
uses: softprops/action-gh-release@v3
with:
name: "RouterOS ${{ env.VERSION }}${{ env.ARCH_EXT }}"
@@ -487,7 +418,7 @@ jobs:
${{env.PUBLISH_DIR}}/routeros*.npk.sha256
- name: Upload Files
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
run: |
sudo apt-get install -y knockd lftp > /dev/null
knock -4 ${{ secrets.SSH_SERVER }} ${{ secrets.SSH_KNOCK_PORT }}
@@ -509,7 +440,11 @@ jobs:
rm -f $PUBLISH_DIR/*.iso.sha256
sed -i '1d' $PUBLISH_DIR/CHANGELOG
echo $VERSION $BUILD_TIME | tee $PUBLISH_DIR/info
touch $PUBLISH_DIR/$CHANNEL
echo "$CHANNELS" | jq -r '.[]' | while read -r CHANNEL
do
touch "$PUBLISH_DIR/$CHANNEL"
done
REMOTE_PATH=${{ secrets.SSH_DIRECTORY }}/$VERSION
SERVER=${{ secrets.SSH_SERVER }}
USER=${{ secrets.SSH_USERNAME }}
@@ -523,7 +458,7 @@ jobs:
EOF
- name: Clear Cloudflare cache
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
run: |
curl --request POST --url "https://api.cloudflare.com/client/v4/zones/fe6831ed6dc9e6235e69ef2a31f2e7fe/purge_cache" \
--header "Authorization: Bearer 9GDQkzU51QXaqzp1qMjyFKpyeJyOdnNoG9GZQaGP" \
@@ -532,15 +467,12 @@ jobs:
Update_Release:
needs: [Prepare_Patch,Patch_RouterOS]
if: |
needs.Prepare_Patch.outputs.SKIP_BUILD == 'false' &&
needs.Patch_RouterOS.result == 'success' &&
needs.Prepare_Patch.outputs.RELEASE == 'true'
needs: [Patch_RouterOS]
if: needs.Patch_RouterOS.result == 'success' && inputs.release == true
runs-on: ubuntu-24.04
env:
CHANNEL: ${{ inputs.channel }}
VERSION: ${{ needs.Prepare_Patch.outputs.VERSION }}
CHANNELS: ${{ inputs.channels }}
VERSION: ${{ inputs.version }}
steps:
- name: Update Release
run: |
@@ -563,8 +495,19 @@ jobs:
USER=${{ secrets.SSH_USERNAME }}
PASS=${{ secrets.SSH_PASSWORD }}
PORT=${{ secrets.SSH_PORT }}
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no -p $PORT $USER@$SERVER \
"ln -sf /root/$REMOTE_PATH/$VERSION/info /rw/disk/$REMOTE_PATH/NEWEST6.$CHANNEL; \
ln -sf /root/$REMOTE_PATH/$VERSION/info /rw/disk/$REMOTE_PATH/NEWESTa6.$CHANNEL; \
chown -R 32768:32768 /rw/disk/$REMOTE_PATH"
REMOTE_CMD="
while read -r CHANNEL
do
REMOTE_CMD="$REMOTE_CMD
ln -sfn /root/$REMOTE_PATH/$VERSION/info /rw/disk/$REMOTE_PATH/NEWEST6.$CHANNEL"
ln -sfn /root/$REMOTE_PATH/$VERSION/info /rw/disk/$REMOTE_PATH/NEWESTa6.$CHANNEL"
done < <(echo "$CHANNELS" | jq -r '.[]')
REMOTE_CMD="$REMOTE_CMD
chown -R 32768:32768 /rw/disk/$REMOTE_PATH
"
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no -p $PORT $USER@$SERVER "$REMOTE_CMD"
echo "✅ Updated release info."

View File

@@ -1,62 +1,23 @@
name: Patch RouterOS v7
on:
workflow_dispatch:
inputs:
channel:
description: 'Channel (stable, long-term, testing)'
required: true
default: 'stable'
type: choice
options:
- stable
- long-term
- testing
arch:
description: 'Architecture (x86, arm64)'
required: true
default: 'all'
type: choice
options:
- all
- x86
- arm64
version:
description: "Specify version (e.g., 7.19.2), empty for latest"
required: false
default: ''
type: string
buildtime:
description: "Custom build time, leave empty for original"
required: false
default: ''
type: string
release:
description: "Release to Upload "
required: false
default: false
type: boolean
workflow_call:
inputs:
channel:
version:
required: true
type: string
arch:
required: false
channels:
required: true
type: string
default: 'all'
version:
required: false
archs:
required: true
type: string
default: ''
release:
required: true
type: boolean
buildtime:
required: false
type: string
default: ''
release:
required: false
type: boolean
default: false
env:
CUSTOM_LICENSE_PRIVATE_KEY: ${{ secrets.CUSTOM_LICENSE_PRIVATE_KEY }}
@@ -75,79 +36,30 @@ env:
CUSTOM_RENEW_URL: ${{ secrets.CUSTOM_RENEW_URL }}
MIKRO_CLOUD_URL: ${{ secrets.MIKRO_CLOUD_URL }}
CUSTOM_CLOUD_URL: ${{ secrets.CUSTOM_CLOUD_URL }}
MIKRO_CLOUD2_URL: ${{ secrets.MIKRO_CLOUD2_URL }}
CUSTOM_CLOUD2_URL: ${{ secrets.CUSTOM_CLOUD2_URL }}
jobs:
Prepare_Patch:
runs-on: ubuntu-24.04
outputs:
VERSION: ${{ steps.prepare.outputs.VERSION }}
BUILD_TIME: ${{ steps.prepare.outputs.BUILD_TIME }}
ARCHS: ${{ steps.prepare.outputs.ARCHS }}
RELEASE: ${{ steps.prepare.outputs.RELEASE }}
SKIP_BUILD: ${{ steps.prepare.outputs.SKIP_BUILD }}
steps:
- name: Prepare Patch for ${{ inputs.channel }}
id: prepare
run: |
CHANNEL="${{ inputs.channel }}"
ARCH_INPUT="${{ inputs.arch }}"
VERSION="${{ inputs.version }}"
RELEASE="${{ inputs.release }}"
BUILD_TIME="${{ inputs.buildtime }}"
if [ "$ARCH_INPUT" == "all" ]; then
ARCHS='["x86", "arm64"]'
else
ARCHS=$(jq -c -n --arg arch "$ARCH_INPUT" '[$arch]')
fi
SKIP_BUILD=false
if [ -z "$VERSION" ]; then
echo "Checking latest version from $CHANNEL channel..."
TIMESTAMP=$(date +%s)
NEWEST=$(wget -nv -O - "https://${{ env.MIKRO_UPGRADE_URL }}/routeros/NEWESTa7.$CHANNEL?t=$TIMESTAMP")
VERSION=$(echo "$NEWEST" | cut -d ' ' -f1)
echo "Official version: $VERSION"
if [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then
PATCH_NEWEST=$(wget -nv -O - "https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/NEWESTa7.$CHANNEL?t=$TIMESTAMP" 2>/dev/null || echo "")
PATCH_VERSION=$(echo "$PATCH_NEWEST" | cut -d ' ' -f1)
echo "Patch version: ${PATCH_VERSION:-none}"
if [ "$PATCH_VERSION" == "$VERSION" ]; then
echo "No new version for $CHANNEL, skipping..."
SKIP_BUILD=true
else
echo "New version $VERSION available, building..."
fi
fi
fi
echo "SKIP_BUILD=$SKIP_BUILD" >> $GITHUB_OUTPUT
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "BUILD_TIME=$BUILD_TIME" >> $GITHUB_OUTPUT
echo "ARCHS=$ARCHS" >> $GITHUB_OUTPUT
echo "RELEASE=$RELEASE" >> $GITHUB_OUTPUT
echo "Version: $VERSION, Archs: $ARCHS"
Patch_RouterOS:
needs: Prepare_Patch
if: needs.Prepare_Patch.outputs.SKIP_BUILD == 'false'
runs-on: ubuntu-24.04
strategy:
matrix:
arch: ${{ fromJson(needs.Prepare_Patch.outputs.ARCHS) }}
arch: ${{ fromJson( inputs.archs ) }}
fail-fast: false
env:
TZ: 'Asia/Shanghai'
CHANNEL: ${{ inputs.channel }}
CHANNELS: ${{ inputs.channels }}
ARCH: ${{ matrix.arch }}
VERSION: ${{ needs.Prepare_Patch.outputs.VERSION }}
BUILD_TIME: ${{ needs.Prepare_Patch.outputs.BUILD_TIME }}
BUILD_DIR: "/tmp/build/${{ needs.Prepare_Patch.outputs.VERSION }}"
PUBLISH_DIR: "${{ github.workspace }}/publish/${{ needs.Prepare_Patch.outputs.VERSION }}"
VERSION: ${{ inputs.version }}
BUILD_TIME: ${{ inputs.buildtime }}
RELEASE: ${{ inputs.release }}
BUILD_DIR: "/tmp/build/${{ inputs.version }}"
PUBLISH_DIR: "${{ github.workspace }}/publish/${{ inputs.version }}"
ARCH_EXT: ""
PACKAGES: ""
steps:
- uses: actions/checkout@v6
- name: Setup environment
- name: Setup environment
run: |
sudo apt-get update > /dev/null
sudo apt-get install -y zip unzip squashfs-tools jq > /dev/null
@@ -178,14 +90,12 @@ jobs:
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
echo "PACKAGES: $PACKAGES"
- name: Create Squashfs for Option and Python Package
- name: Build Squashfs for Option and Python Package
run: |
echo "Creating Option Package Squashfs for channel: $CHANNEL, arch: $ARCH"
echo "Creating Option Package Squashfs for arch: $ARCH"
mkdir -p $BUILD_DIR/option-root/bin/
cp ./busybox/busybox_$ARCH $BUILD_DIR/option-root/bin/busybox
chmod +x $BUILD_DIR/option-root/bin/busybox
cp ./keygen/keygen_$ARCH $BUILD_DIR/option-root/bin/keygen
chmod +x $BUILD_DIR/option-root/bin/keygen
install -m 755 ./busybox/busybox_$ARCH $BUILD_DIR/option-root/bin/busybox
install -m 755 ./keygen/keygen_$ARCH $BUILD_DIR/option-root/bin/keygen
chmod +x ./busybox/busybox_x86
COMMANDS=$(./busybox/busybox_x86 --list)
for cmd in $COMMANDS; do
@@ -341,7 +251,7 @@ jobs:
rm -rf $BUILD_DIR/all_packages
- name: Cache NetInstall ${{ env.VERSION }}
if: matrix.arch == 'x86' && needs.Prepare_Patch.outputs.RELEASE == 'true'
if: matrix.arch == 'x86' && env.RELEASE == 'true'
id: cache-netinstall
uses: actions/cache@v5
with:
@@ -351,12 +261,12 @@ jobs:
- name: Get netinstall ${{ env.VERSION }}
if: |
steps.cache-netinstall.outputs.cache-hit != 'true' &&
matrix.arch == 'x86' && needs.Prepare_Patch.outputs.RELEASE == 'true'
matrix.arch == 'x86' && env.RELEASE == 'true'
run: |
wget -nv -O $BUILD_DIR/netinstall-$VERSION.zip https://download.mikrotik.com/routeros/$VERSION/netinstall-$VERSION.zip
- name: Patch netinstall ${{ env.VERSION }}
if: matrix.arch == 'x86' && needs.Prepare_Patch.outputs.RELEASE == 'true'
if: matrix.arch == 'x86' && env.RELEASE == 'true'
run: |
unzip $BUILD_DIR/netinstall-$VERSION.zip -d $BUILD_DIR/
python3 patch.py netinstall $BUILD_DIR/netinstall.exe
@@ -375,7 +285,114 @@ jobs:
if: matrix.arch == 'x86' && steps.cache-refind.outputs.cache-hit != 'true'
run: wget -nv -O $BUILD_DIR/refind-bin-0.14.2.zip https://downloads.sourceforge.net/project/refind/0.14.2/refind-bin-0.14.2.zip
- name: Create ISO & INSTALL image files
- name: Build Alpine LiveCD
if: matrix.arch == 'x86'
run: |
set -e
YAML_URL="https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/latest-releases.yaml"
ROOTFS_FILE=$(curl -sL "$YAML_URL" | grep -m1 'alpine-minirootfs.*\.tar\.gz' | awk '{print $NF}' | tr -d '"')
echo "$ROOTFS_FILE"
ROOTFS_URL="https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/$ROOTFS_FILE"
ROOTFS_DIR=$BUILD_DIR/rootfs
mkdir -p $ROOTFS_DIR
curl -# -L "$ROOTFS_URL" | tar -xzC $ROOTFS_DIR
sudo mount -v --bind /dev $ROOTFS_DIR/dev
sudo mount -vt sysfs sysfs $ROOTFS_DIR/sys
sudo mount -vt proc proc $ROOTFS_DIR/proc
cat << 'EOF' > $ROOTFS_DIR/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
cat << 'EOF' > $ROOTFS_DIR/etc/inittab
# /etc/inittab
::sysinit:/sbin/openrc sysinit
::sysinit:/sbin/openrc boot
::wait:/sbin/openrc default
tty1::respawn:/sbin/agetty --autologin root tty1 linux
tty2::respawn:/sbin/agetty tty2 linux
tty3::respawn:/sbin/agetty tty3 linux
tty4::respawn:/sbin/agetty tty4 linux
ttyS0::respawn:/sbin/agetty ttyS0 linux
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/openrc shutdown
EOF
install -m 755 ./setup-routeros.sh $ROOTFS_DIR/usr/local/bin/setup-routeros
install -m 755 ./npkextract/npkextract $ROOTFS_DIR/usr/local/bin/npkextract
cat << 'EOF' > $ROOTFS_DIR/root/.zprofile
if command -v setup-routeros >/dev/null 2>&1; then
setup-routeros
fi
EOF
cat << 'EOF' | sudo chroot $ROOTFS_DIR /usr/bin/env PATH=/usr/bin:/bin:/usr/sbin:/sbin /bin/sh
set -e
echo "nameserver 1.1.1.1" > /etc/resolv.conf
apk update
apk upgrade
apk add alpine-base openrc busybox-mdev-openrc dhcpcd curl ca-certificates linux-lts linux-firmware-none
apk add bash dialog sgdisk dosfstools e2fsprogs util-linux parted
apk add zsh zsh-syntax-highlighting zsh-autosuggestions coreutils ncurses iproute2
rc-update add devfs sysinit
rc-update add dmesg sysinit
rc-update add mdev sysinit
rc-update add hwdrivers sysinit
rc-update add acpid boot
rc-update add hostname boot
rc-update add hwclock boot
rc-update add modules boot
rc-update add sysctl boot
rc-update add bootmisc boot
rc-update add dhcpcd boot
rc-update add networking default
curl -o /root/.zshrc https://gitlab.com/kalilinux/packages/kali-defaults/-/raw/kali/master/etc/skel/.zshrc
sed -i 's/^PROMPT_ALTERNATIVE=twoline/PROMPT_ALTERNATIVE=oneline/' /root/.zshrc
sed -i 's/^NEWLINE_BEFORE_PROMPT=yes/NEWLINE_BEFORE_PROMPT=no/' /root/.zshrc
sed -i 's|/usr/share/zsh-syntax-highlighting|/usr/share/zsh/plugins/zsh-syntax-highlighting|g' /root/.zshrc
sed -i 's|/usr/share/zsh-autosuggestions|/usr/share/zsh/plugins/zsh-autosuggestions|g' /root/.zshrc
sed -i 's|^root:\(.*\):/bin/sh$|root:\1:/bin/zsh|' /etc/passwd
sed -i 's/^root:.*/root:::0:::::/' /etc/shadow
printf 'Welcome to Alpine!\n\nTo start the RouterOS installation wizard, run: setup-routeros\n\n' > /etc/motd
sed -i 's/^features=.*/features="ata base cdrom network scsi nvme ext2 usb virtio"/' /etc/mkinitfs/mkinitfs.conf
KERNEL_VERSION=$(ls /lib/modules | head -1)
mkinitfs -k -t /tmp "$KERNEL_VERSION"
rm -rf /lib/modules
mv /tmp/lib/modules /lib
depmod "$KERNEL_VERSION"
ln -sf sbin/init /init
apk cache clean
EOF
sudo umount -v $ROOTFS_DIR/dev
sudo umount -v $ROOTFS_DIR/sys
sudo umount -v $ROOTFS_DIR/proc
cp $ROOTFS_DIR/boot/vmlinuz-* $BUILD_DIR/vmlinuz
sudo rm -rf $ROOTFS_DIR/tmp/*
sudo rm -rf $ROOTFS_DIR/boot/*
sudo rm -rf $ROOTFS_DIR/var/cache/*
(cd "$ROOTFS_DIR" && sudo find . -print0 | sudo cpio --owner=root:root --null -H newc -o 2>/dev/null | xz -C crc32 -v9eT0 > $BUILD_DIR/initramfs.xz)
sudo rm -rf $ROOTFS_DIR
size=$(stat -c %s "$BUILD_DIR/vmlinuz")
printf "vmlinuz size : %d bytes (%.1f MB)\n" "$size" "$(echo "scale=1; $size/1024/1024" | bc)"
size=$(stat -c %s "$BUILD_DIR/initramfs.xz")
printf "initramfs size : %d bytes (%.1f MB)\n" "$size" "$(echo "scale=1; $size/1024/1024" | bc)"
- name: Build ISO & INSTALL image files
run: |
set -e
sudo modprobe nbd
@@ -386,15 +403,33 @@ jobs:
if [ "$ARCH" == "x86" ]; then
echo "Creating x86 ISO..."
mkdir -p $BUILD_DIR/new_iso/isolinux
cp /usr/lib/ISOLINUX/isolinux.bin $BUILD_DIR/new_iso/isolinux/
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 $BUILD_DIR/new_iso/isolinux/
echo -e 'default system\n\nlabel system\n\tkernel linux\n\tappend load_ramdisk=1 root=/dev/ram0 -install -cdrom' | tee $BUILD_DIR/new_iso/isolinux/isolinux.cfg
cp -v /usr/lib/ISOLINUX/isolinux.bin $BUILD_DIR/new_iso/isolinux/
cp -v /usr/lib/syslinux/modules/bios/ldlinux.c32 $BUILD_DIR/new_iso/isolinux/
cp -v /usr/lib/syslinux/modules/bios/libutil.c32 $BUILD_DIR/new_iso/isolinux/
cp -v /usr/lib/syslinux/modules/bios/menu.c32 $BUILD_DIR/new_iso/isolinux/
tee $BUILD_DIR/new_iso/isolinux/isolinux.cfg > /dev/null << 'EOF'
UI menu.c32
MENU TITLE MikroTik RouterOS Install CDROM
MENU CLEAR
DEFAULT system
TIMEOUT 0
LABEL system
MENU LABEL Install RouterOS
KERNEL linux
APPEND load_ramdisk=1 root=/dev/ram0 -install -cdrom
LABEL alpine
MENU LABEL Boot Alpine Linux
KERNEL vmlinuz
APPEND initrd=initramfs.xz
EOF
cp -v $BUILD_DIR/vmlinuz $BUILD_DIR/new_iso/isolinux/vmlinuz
cp -v $BUILD_DIR/initramfs.xz $BUILD_DIR/new_iso/isolinux/initramfs.xz
sudo mount -o loop $BUILD_DIR/new_iso/efiboot.img $BUILD_DIR/efiboot
python3 patch.py kernel $BUILD_DIR/efiboot/linux.x86_64 -O $BUILD_DIR/new_iso/isolinux/linux
sudo umount $BUILD_DIR/efiboot
#修改为16M,减小镜像体积
rm -f $BUILD_DIR/new_iso/efiboot.img
truncate --size 16M $BUILD_DIR/new_iso/efiboot.img
truncate --size 64M $BUILD_DIR/new_iso/efiboot.img
mkfs.vfat -n "Boot" $BUILD_DIR/new_iso/efiboot.img
sudo mount -o loop,uid=$(id -u),gid=$(id -g) $BUILD_DIR/new_iso/efiboot.img $BUILD_DIR/efiboot
mkdir -p $BUILD_DIR/efiboot/EFI/BOOT
@@ -409,11 +444,18 @@ jobs:
loader /linux.x86_64
options "load_ramdisk=1 root=/dev/ram0 -install -cdrom debug"
}
menuentry "Alpine Linux" {
loader /vmlinuz
initrd /initramfs.xz
}
default_selection /EFI/BOOT/BOOTX64.EFI
EOF
cp -v $BUILD_DIR/new_iso/isolinux/linux $BUILD_DIR/efiboot/linux.x86_64
cp -v $BUILD_DIR/vmlinuz $BUILD_DIR/efiboot/vmlinuz
cp -v $BUILD_DIR/initramfs.xz $BUILD_DIR/efiboot/initramfs.xz
sync
sudo umount $BUILD_DIR/efiboot
xorriso -as mkisofs -o $PUBLISH_DIR/mikrotik-$VERSION$ARCH_EXT.iso \
-V 'MikroTik' \
-publisher "WWW.MIKROTIK.COM" \
@@ -460,9 +502,9 @@ jobs:
EOF
tee $BUILD_DIR/install/syslinux.cfg > /dev/null << 'EOF'
default system
LABEL system
KERNEL linux
APPEND load_ramdisk=1 -install -hdd
label system
kernel linux
append load_ramdisk=1 -install -hdd
EOF
NPK_FILES=($(find $BUILD_DIR/new_iso/*.npk))
for ((i=1; i<=${#NPK_FILES[@]}; i++))
@@ -507,13 +549,13 @@ jobs:
-input-charset utf-8 \
-iso-level 3 \
$BUILD_DIR/new_iso
echo "✅ ISO created: "
echo "✅ arm64 ISO created: "
ls -la $PUBLISH_DIR/mikrotik-$VERSION$ARCH_EXT.iso
fi
rm -rf $BUILD_DIR/new_iso
rm -rf $BUILD_DIR/efiboot
- name: Create CHR image files
- name: Build CHR image files
run: |
set -e
OVF_TEMPLATE='<?xml version="1.0" encoding="UTF-8"?>
@@ -611,245 +653,150 @@ jobs:
</Envelope>'
sudo apt-get install -y parted > /dev/null
mkdir -p $BUILD_DIR/chr/{boot,routeros}
prepare_image(){
local IMAGE="$1"
local BOOT_MODE="$2"
truncate --size 128M "$IMAGE"
local END=$(( ($(stat -c '%s' "$IMAGE") / 512 - 4096) / 8 * 8 - 1 ))
sgdisk --set-alignment=1 \
--new=1:34:65535 --typecode=1:EF00 --change-name=1:"RouterOS Boot" \
--new=2:65536:$END --typecode=2:8300 --change-name=2:"RouterOS" \
--hybrid=1:2:EE \
"$IMAGE"
# Active CHR mode
printf '\x01' | dd of="$IMAGE" bs=1 seek=336 conv=notrunc status=none
# Active boot partition
printf '\x80' | dd of="$IMAGE" bs=1 seek=446 conv=notrunc status=none
# Must be 0x83, otherwise "ERROR: could not find disk!"
printf '\x83' | dd of="$IMAGE" bs=1 seek=450 conv=notrunc status=none
if [[ "$BOOT_MODE" == "bios" ]]; then
echo "FA31C08ED0BC007C89E65007501FFBFCBF0006B90001F2A5EA1D060000BEBE07B304803C807423803C00750983C610FECB75EFCD18BE9B06AC3C00740B56BB0700B40ECD105EEBF0EBFE8B148B4C0289F5BF0500BB007CB8010257CD135F730C31C0CD134F75EDBE7C06EBCCBFFE7D813D55AA75C289EEEA007C00004572726F72206C6F6164696E67206F7065726174696E672073797374656D004D697373696E67206F7065726174696E672073797374656D0000000000" |
xxd -r -p |
sudo dd of="$IMAGE" bs=1 conv=notrunc status=none
fi
}
build_image() {
local IMAGE="$1"
local BOOT_MODE="$2"
prepare_image $IMAGE $BOOT_MODE
sudo qemu-nbd -d /dev/nbd0 2>/dev/null || true
sudo qemu-nbd -c /dev/nbd0 -f raw "$IMAGE"
sudo partprobe /dev/nbd0
# Boot partition
if [[ "$BOOT_MODE" == "bios" ]]; then
sudo mkfs.ext2 -F -m 0 -L "RouterOS Boot" /dev/nbd0p1
elif [[ "$BOOT_MODE" == "efi" ]]; then
sudo mkfs.vfat -F 16 -n "BOOT" /dev/nbd0p1
else
echo "ERROR: unsupported boot mode: $BOOT_MODE" >&2
return 1
fi
sudo mount /dev/nbd0p1 "$BUILD_DIR/chr/boot"
sudo mkdir -p "$BUILD_DIR/chr/boot/EFI/BOOT"
if [ "$ARCH" == "x86" ]; then
sudo cp -vf "$BUILD_DIR/chr/BOOTX64.EFI" "$BUILD_DIR/chr/boot/EFI/BOOT/BOOTX64.EFI"
elif [ "$ARCH" == "arm64" ]; then
sudo cp -vf $BUILD_DIR/chr/BOOTAA64.EFI $BUILD_DIR/chr/boot/EFI/BOOT/BOOTAA64.EFI
fi
if [[ "$BOOT_MODE" == "bios" ]]; then
sudo "$BUILD_DIR/chr/milo" "$BUILD_DIR/chr/boot"
fi
sudo umount "$BUILD_DIR/chr/boot"
# RouterOS partition
sudo mkfs.ext4 -F -m 0 -L "RouterOS" /dev/nbd0p2
sudo mount /dev/nbd0p2 "$BUILD_DIR/chr/routeros"
sudo mkdir -p $BUILD_DIR/chr/routeros/{var/pdb/{system,option},boot,bin,rw/disk}
sudo install -m 0755 "$BUILD_DIR/chr/milo" "$BUILD_DIR/chr/routeros/bin/milo"
sudo install -m 0755 "$BUILD_DIR/chr/bash" "$BUILD_DIR/chr/routeros/bin/bash"
sudo cp -v $PUBLISH_DIR/option-$VERSION$ARCH_EXT.npk $BUILD_DIR/chr/routeros/var/pdb/option/image
sudo cp -v $PUBLISH_DIR/routeros-$VERSION$ARCH_EXT.npk $BUILD_DIR/chr/routeros/var/pdb/system/image
printf '%s\n' \
'#!/bin/sh' \
'# This script will be executed *before* RouterOS *loader* start.' \
'# You can put your own initialization stuff in here' |
sudo tee "$BUILD_DIR/chr/routeros/rw/disk/rc.local" >/dev/null
sudo umount /dev/nbd0p2
sudo qemu-nbd -d /dev/nbd0
echo "Image built: $IMAGE"
local IMAGE_PREFIX="${IMAGE%.img}"
qemu-img convert -f raw -O qcow2 $IMAGE $IMAGE_PREFIX.qcow2
qemu-img convert -f raw -O vmdk $IMAGE $IMAGE_PREFIX.vmdk
qemu-img convert -f raw -O vpc $IMAGE $IMAGE_PREFIX.vhd
qemu-img convert -f raw -O vhdx $IMAGE $IMAGE_PREFIX.vhdx
qemu-img convert -f raw -O vdi $IMAGE $IMAGE_PREFIX.vdi
local IMAGE_NAME="${IMAGE_PREFIX##*/}"
local VMDK_FILE="$IMAGE_NAME-disk1.vmdk"
local OVF_FILE="$IMAGE_NAME.ovf"
local OVA_FILE="$IMAGE_NAME.ova"
qemu-img convert -f raw -O vmdk -o subformat=streamOptimized "$IMAGE" "$BUILD_DIR/$VMDK_FILE"
local FILE_SIZE=$(stat -c %s "$BUILD_DIR/$VMDK_FILE")
echo "$OVF_TEMPLATE" |
sed -e "s|{VMDK_FILE}|$VMDK_FILE|g" \
-e "s|{FILE_SIZE}|$FILE_SIZE|g" \
-e "s|{FIRMWARE_TYPE}|$BOOT_MODE|g" \
> "$BUILD_DIR/$OVF_FILE"
(cd $BUILD_DIR && tar -cvf "$OVA_FILE" "$OVF_FILE" "$VMDK_FILE")
rm -f "$BUILD_DIR/$VMDK_FILE"
rm -f "$BUILD_DIR/$OVF_FILE"
echo "✅ Generated images:"
ls -lh "$IMAGE_PREFIX".*
(cd $BUILD_DIR && \
zip $PUBLISH_DIR/$IMAGE_NAME.ova.zip $IMAGE_NAME.ova && \
zip $PUBLISH_DIR/$IMAGE_NAME.qcow2.zip $IMAGE_NAME.qcow2 && \
zip $PUBLISH_DIR/$IMAGE_NAME.vmdk.zip $IMAGE_NAME.vmdk && \
zip $PUBLISH_DIR/$IMAGE_NAME.vhd.zip $IMAGE_NAME.vhd && \
zip $PUBLISH_DIR/$IMAGE_NAME.vhdx.zip $IMAGE_NAME.vhdx && \
zip $PUBLISH_DIR/$IMAGE_NAME.vdi.zip $IMAGE_NAME.vdi && \
zip $PUBLISH_DIR/$IMAGE_NAME.img.zip $IMAGE_NAME.img )
rm -f "$IMAGE_PREFIX".*
}
if [ "$ARCH" == "x86" ]; then
echo "Creating x86 uefi CHR..."
echo "🚀 Creating CHR image for x86..."
python3 npk.py extract $PUBLISH_DIR/routeros-$VERSION$ARCH_EXT.npk boot/EFI/BOOT/BOOTX64.EFI $BUILD_DIR/chr/BOOTX64.EFI
python3 npk.py extract $PUBLISH_DIR/routeros-$VERSION$ARCH_EXT.npk bin/milo $BUILD_DIR/chr/milo
python3 npk.py extract $PUBLISH_DIR/routeros-$VERSION$ARCH_EXT.npk bin/bash $BUILD_DIR/chr/bash
chmod +x $BUILD_DIR/chr/milo
#要求MBR分区表第一个分区类型必须为0x8300,否则ERROR: could not find disk!
truncate --size 128M $BUILD_DIR/chr-$VERSION$ARCH_EXT.img
sgdisk \
--zap-all \
--set-alignment=1 \
--new=1:34:+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" \
--new=2:0:0 --typecode=2:8300 --change-name=2:"RouterOS" \
--gpttombr=1:2 \
$BUILD_DIR/chr-$VERSION$ARCH_EXT.img
dd if=$BUILD_DIR/chr-$VERSION$ARCH_EXT.img of=$BUILD_DIR/mbr.bin bs=1 count=512 conv=notrunc
printf '\x01' | dd of=$BUILD_DIR/mbr.bin bs=1 count=1 seek=336 conv=notrunc
sgdisk \
--zap-all \
--set-alignment=1 \
--new=1:34:+32M --typecode=1:EF00 --change-name=1:"RouterOS Boot" \
--new=2:0:0 --typecode=2:8300 --change-name=2:"RouterOS" \
$BUILD_DIR/chr-$VERSION$ARCH_EXT.img
dd if=$BUILD_DIR/mbr.bin of=$BUILD_DIR/chr-$VERSION$ARCH_EXT.img bs=1 count=512 conv=notrunc
rm $BUILD_DIR/mbr.bin
sudo qemu-nbd -d /dev/nbd0
sudo qemu-nbd -c /dev/nbd0 -f raw $BUILD_DIR/chr-$VERSION$ARCH_EXT.img
sudo partprobe /dev/nbd0
sudo mkfs.vfat -n "Boot" /dev/nbd0p1
sudo mkfs.ext4 -F -L "RouterOS" -m 0 /dev/nbd0p2
sudo mount -o uid=$(id -u),gid=$(id -g) /dev/nbd0p1 $BUILD_DIR/chr/boot
sudo mkdir -p $BUILD_DIR/chr/boot/EFI/BOOT
sudo cp -v $BUILD_DIR/chr/BOOTX64.EFI $BUILD_DIR/chr/boot/EFI/BOOT/BOOTX64.EFI
sudo umount /dev/nbd0p1
sudo mount /dev/nbd0p2 $BUILD_DIR/chr/routeros
sudo mkdir -p $BUILD_DIR/chr/routeros/{var/pdb/{system,option},boot,bin,rw/disk}
# cmdStartVerify bin/milo
sudo cp -v $BUILD_DIR/chr/milo $BUILD_DIR/chr/routeros/bin/milo
sudo cp -v $PUBLISH_DIR/option-$VERSION$ARCH_EXT.npk $BUILD_DIR/chr/routeros/var/pdb/option/image
sudo cp -v $PUBLISH_DIR/routeros-$VERSION$ARCH_EXT.npk $BUILD_DIR/chr/routeros/var/pdb/system/image
echo -e '#!/bin/sh\n# This script will be executed *before* RouterOS *loader* start.\n# You can put your own initialization stuff in here\n' |sudo tee $BUILD_DIR/chr/routeros/rw/disk/rc.local
sudo umount /dev/nbd0p2
sudo qemu-nbd -d /dev/nbd0
qemu-img convert -f raw -O qcow2 $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.qcow2
qemu-img convert -f raw -O vmdk $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.vmdk
qemu-img convert -f raw -O vpc $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.vhd
qemu-img convert -f raw -O vhdx $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.vhdx
qemu-img convert -f raw -O vdi $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.vdi
VMDK_FILE=chr-$VERSION$ARCH_EXT-disk1.vmdk
qemu-img convert -f raw -O vmdk -o subformat=streamOptimized \
$BUILD_DIR/chr-$VERSION$ARCH_EXT.img \
$BUILD_DIR/$VMDK_FILE
FILE_SIZE=$(stat -c %s "$BUILD_DIR/$VMDK_FILE")
OVF_FILE=chr-$VERSION$ARCH_EXT.ovf
OVA_FILE=chr-$VERSION$ARCH_EXT.ova
echo "$OVF_TEMPLATE" | sed -e "s|{VMDK_FILE}|$VMDK_FILE|g" \
-e "s|{FILE_SIZE}|$FILE_SIZE|g" \
-e "s|{FIRMWARE_TYPE}|efi|g" | tee $BUILD_DIR/$OVF_FILE
(cd $BUILD_DIR && tar -cvf "$OVA_FILE" "$OVF_FILE" "$VMDK_FILE")
rm $BUILD_DIR/$VMDK_FILE
rm $BUILD_DIR/$OVF_FILE
echo "✅ UEFI CHR created: "
ls -la $BUILD_DIR/chr-$VERSION$ARCH_EXT.*
(cd $BUILD_DIR && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.ova.zip chr-$VERSION$ARCH_EXT.ova && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.qcow2.zip chr-$VERSION$ARCH_EXT.qcow2 && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.vmdk.zip chr-$VERSION$ARCH_EXT.vmdk && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.vhd.zip chr-$VERSION$ARCH_EXT.vhd && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.vhdx.zip chr-$VERSION$ARCH_EXT.vhdx && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.vdi.zip chr-$VERSION$ARCH_EXT.vdi &&
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.img.zip chr-$VERSION$ARCH_EXT.img )
rm $BUILD_DIR/chr-$VERSION$ARCH_EXT.*
FIRMWARE_TYPE="bios"
echo "Creating x86 legacy bios CHR..."
truncate --size 128M $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img
sgdisk \
--zap-all \
--set-alignment=1 \
--new=1:34:+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" --attributes=1:set:2 \
--new=2:0:-4096 --typecode=2:8300 --change-name=2:"RouterOS" \
--gpttombr=1:2 \
$BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img
dd if=$BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img of=$BUILD_DIR/mbr.bin bs=1 count=512 conv=notrunc
echo "FA31C08ED0BC007C89E65007501FFBFCBF0006B90001F2A5EA1D060000BEBE07B304803C807423803C00750983C610FECB75EFCD18BE9B06AC3C00740B56BB0700B40ECD105EEBF0EBFE8B148B4C0289F5BF0500BB007CB8010257CD135F730C31C0CD134F75EDBE7C06EBCCBFFE7D813D55AA75C289EEEA007C00004572726F72206C6F6164696E67206F7065726174696E672073797374656D004D697373696E67206F7065726174696E672073797374656D0000000000" | xxd -r -p | sudo dd of=$BUILD_DIR/mbr.bin bs=1 count=440 conv=notrunc
printf '\x01' | sudo dd of=$BUILD_DIR/mbr.bin bs=1 count=1 seek=336 conv=notrunc
printf '\x80' | sudo dd of=$BUILD_DIR/mbr.bin bs=1 count=1 seek=446 conv=notrunc
sgdisk \
--zap-all \
--set-alignment=1 \
--new=1:34:+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" --attributes=1:set:2 \
--new=2:0:-4096 --typecode=2:8300 --change-name=2:"RouterOS" \
$BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img
dd if=$BUILD_DIR/mbr.bin of=$BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img bs=1 count=512 conv=notrunc
sudo rm $BUILD_DIR/mbr.bin
sudo qemu-nbd -d /dev/nbd0
sudo qemu-nbd -c /dev/nbd0 -f raw $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img
sudo partprobe /dev/nbd0
sudo mkfs.ext2 -F -m 0 -L "RouterOS Boot" /dev/nbd0p1
sudo mkfs.ext4 -F -m 0 -L "RouterOS" /dev/nbd0p2
sudo mount /dev/nbd0p1 $BUILD_DIR/chr/boot
sudo mkdir -p $BUILD_DIR/chr/boot/EFI/BOOT
sudo cp -vf $BUILD_DIR/chr/BOOTX64.EFI $BUILD_DIR/chr/boot/EFI/BOOT/BOOTX64.EFI
sudo $BUILD_DIR/chr/milo $BUILD_DIR/chr/boot
sudo umount /dev/nbd0p1
sudo mount /dev/nbd0p2 $BUILD_DIR/chr/routeros
sudo mkdir -p $BUILD_DIR/chr/routeros/{var/pdb/{system,option},boot,bin,rw/disk}
sudo cp -v $BUILD_DIR/chr/milo $BUILD_DIR/chr/routeros/bin/milo
sudo cp -v $PUBLISH_DIR/option-$VERSION$ARCH_EXT.npk $BUILD_DIR/chr/routeros/var/pdb/option/image
sudo cp -v $PUBLISH_DIR/routeros-$VERSION$ARCH_EXT.npk $BUILD_DIR/chr/routeros/var/pdb/system/image
echo -e '#!/bin/sh\n# This script will be executed *before* RouterOS *loader* start.\n# You can put your own initialization stuff in here\n' | sudo tee $BUILD_DIR/chr/routeros/rw/disk/rc.local
sudo umount /dev/nbd0p2
sudo qemu-nbd -d /dev/nbd0
qemu-img convert -f raw -O qcow2 $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.qcow2
qemu-img convert -f raw -O vmdk $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.vmdk
qemu-img convert -f raw -O vpc $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.vhd
qemu-img convert -f raw -O vhdx $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.vhdx
qemu-img convert -f raw -O vdi $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.vdi
VMDK_FILE=chr-$VERSION$ARCH_EXT-disk1.vmdk
qemu-img convert -f raw -O vmdk -o subformat=streamOptimized \
$BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img \
$BUILD_DIR/$VMDK_FILE
FILE_SIZE=$(stat -c %s "$BUILD_DIR/$VMDK_FILE")
OVF_FILE=chr-$VERSION$ARCH_EXT-legacy-bios.ovf
OVA_FILE=chr-$VERSION$ARCH_EXT-legacy-bios.ova
echo "$OVF_TEMPLATE" | sed -e "s|{VMDK_FILE}|$VMDK_FILE|g" \
-e "s|{FILE_SIZE}|$FILE_SIZE|g" \
-e "s|{FIRMWARE_TYPE}|bios|g" | tee $BUILD_DIR/$OVF_FILE
(cd $BUILD_DIR && tar -cvf "$OVA_FILE" "$OVF_FILE" "$VMDK_FILE")
rm $BUILD_DIR/$VMDK_FILE
rm $BUILD_DIR/$OVF_FILE
echo "✅ legacy BIOS CHR created: "
ls -la $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.*
(cd $BUILD_DIR && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.ova.zip chr-$VERSION$ARCH_EXT-legacy-bios.ova && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.qcow2.zip chr-$VERSION$ARCH_EXT-legacy-bios.qcow2 && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.vmdk.zip chr-$VERSION$ARCH_EXT-legacy-bios.vmdk && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.vhd.zip chr-$VERSION$ARCH_EXT-legacy-bios.vhd && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.vhdx.zip chr-$VERSION$ARCH_EXT-legacy-bios.vhdx && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.vdi.zip chr-$VERSION$ARCH_EXT-legacy-bios.vdi && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img.zip chr-$VERSION$ARCH_EXT-legacy-bios.img )
rm $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.*
rm $BUILD_DIR/chr/BOOTX64.EFI
rm $BUILD_DIR/chr/milo
echo "🔄 Creating CHR image for x86 UEFI ..."
if ! build_image "$BUILD_DIR/chr-$VERSION$ARCH_EXT.img" efi; then
echo "❌ failed to build x86 UEFI image"
exit 1
fi
echo "Creating CHR image for x86 legacy BIOS ..."
if ! build_image "$BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img" bios; then
echo "❌ failed to build x86 legacy BIOS image"
exit 1
fi
elif [ "$ARCH" == "arm64" ]; then
echo "Creating arm64 CHR..."
echo "🚀 Creating CHR image for arm64..."
python3 npk.py extract $PUBLISH_DIR/routeros-$VERSION$ARCH_EXT.npk boot/kernel $BUILD_DIR/chr/kernel
python3 patch.py buildefi $BUILD_DIR/chr/kernel $BUILD_DIR/chr/BOOTAA64.EFI
rm -r $BUILD_DIR/chr/kernel
#要求MBR分区表第一个分区类型必须为0x8300,否则ERROR: could not find disk!
truncate --size 128M $BUILD_DIR/chr-$VERSION$ARCH_EXT.img
sgdisk \
--zap-all \
--set-alignment=1 \
--new=1:34:+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" \
--new=2:0:0 --typecode=2:8300 --change-name=2:"RouterOS" \
--gpttombr=1:2 \
$BUILD_DIR/chr-$VERSION$ARCH_EXT.img
dd if=$BUILD_DIR/chr-$VERSION$ARCH_EXT.img of=$BUILD_DIR/mbr.bin bs=1 count=512 conv=notrunc
printf '\x01' | dd of=$BUILD_DIR/mbr.bin bs=1 count=1 seek=336 conv=notrunc
sgdisk \
--zap-all \
--set-alignment=1 \
--new=1:34:+32M --typecode=1:EF00 --change-name=1:"RouterOS Boot" \
--new=2:0:0 --typecode=2:8300 --change-name=2:"RouterOS" \
$BUILD_DIR/chr-$VERSION$ARCH_EXT.img
dd if=$BUILD_DIR/mbr.bin of=$BUILD_DIR/chr-$VERSION$ARCH_EXT.img bs=1 count=512 conv=notrunc
rm $BUILD_DIR/mbr.bin
sudo qemu-nbd -d /dev/nbd0
sudo qemu-nbd -c /dev/nbd0 -f raw $BUILD_DIR/chr-$VERSION$ARCH_EXT.img
sudo partprobe /dev/nbd0
sudo mkfs.vfat -n "Boot" "/dev/nbd0p1"
sudo mkfs.ext4 -F -m 0 -L "RouterOS" "/dev/nbd0p2"
sudo mount -o uid=$(id -u),gid=$(id -g) /dev/nbd0p1 $BUILD_DIR/chr/boot
sudo mkdir -p $BUILD_DIR/chr/boot/EFI/BOOT
sudo mv -v $BUILD_DIR/chr/BOOTAA64.EFI $BUILD_DIR/chr/boot/EFI/BOOT/BOOTAA64.EFI
sudo umount /dev/nbd0p1
sudo mount /dev/nbd0p2 $BUILD_DIR/chr/routeros
sudo mkdir -p $BUILD_DIR/chr/routeros/{var/pdb/{system,option},boot,rw/disk}
sudo cp -v $PUBLISH_DIR/option-$VERSION$ARCH_EXT.npk $BUILD_DIR/chr/routeros/var/pdb/option/image
sudo cp -v $PUBLISH_DIR/routeros-$VERSION$ARCH_EXT.npk $BUILD_DIR/chr/routeros/var/pdb/system/image
echo -e '#!/bin/sh\n# This script will be executed *before* RouterOS *loader* start.\n# You can put your own initialization stuff in here\n' | sudo tee $BUILD_DIR/chr/routeros/rw/disk/rc.local
sudo umount /dev/nbd0p2
sudo qemu-nbd -d /dev/nbd0
qemu-img convert -f raw -O qcow2 $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.qcow2
qemu-img convert -f raw -O vmdk $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.vmdk
qemu-img convert -f raw -O vpc $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.vhd
qemu-img convert -f raw -O vhdx $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.vhdx
qemu-img convert -f raw -O vdi $BUILD_DIR/chr-$VERSION$ARCH_EXT.img $BUILD_DIR/chr-$VERSION$ARCH_EXT.vdi
VMDK_FILE=chr-$VERSION$ARCH_EXT-disk1.vmdk
qemu-img convert -f raw -O vmdk -o subformat=streamOptimized \
$BUILD_DIR/chr-$VERSION$ARCH_EXT.img \
$BUILD_DIR/$VMDK_FILE
FILE_SIZE=$(stat -c %s "$BUILD_DIR/$VMDK_FILE")
OVF_FILE=chr-$VERSION$ARCH_EXT.ovf
OVA_FILE=chr-$VERSION$ARCH_EXT.ova
echo "$OVF_TEMPLATE" | sed -e "s|{VMDK_FILE}|$VMDK_FILE|g" \
-e "s|{FILE_SIZE}|$FILE_SIZE|g" \
-e "s|{FIRMWARE_TYPE}|efi|g" | tee $BUILD_DIR/$OVF_FILE
(cd $BUILD_DIR && tar -cvf "$OVA_FILE" "$OVF_FILE" "$VMDK_FILE")
rm $BUILD_DIR/$VMDK_FILE
rm $BUILD_DIR/$OVF_FILE
echo "✅ CHR created: "
ls -la $BUILD_DIR/chr-$VERSION$ARCH_EXT.*
(cd $BUILD_DIR && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.ova.zip chr-$VERSION$ARCH_EXT.ova && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.qcow2.zip chr-$VERSION$ARCH_EXT.qcow2 && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.vmdk.zip chr-$VERSION$ARCH_EXT.vmdk && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.vhd.zip chr-$VERSION$ARCH_EXT.vhd && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.vhdx.zip chr-$VERSION$ARCH_EXT.vhdx && \
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.vdi.zip chr-$VERSION$ARCH_EXT.vdi &&
zip $PUBLISH_DIR/chr-$VERSION$ARCH_EXT.img.zip chr-$VERSION$ARCH_EXT.img )
rm $BUILD_DIR/chr-$VERSION$ARCH_EXT.*
echo "🔄Creating CHR image for arm64 UEFI ..."
if ! build_image "$BUILD_DIR/chr-$VERSION$ARCH_EXT.img" efi; then
echo "❌ failed to build arm64 UEFI image"
exit 1
fi
fi
rm -rf $BUILD_DIR/chr
- name: Upload Files as Artifact (No Release)
if: needs.Prepare_Patch.outputs.RELEASE == 'false'
if: env.RELEASE == 'false'
uses: actions/upload-artifact@v7
with:
name: mikrotik-${{ env.VERSION }}${{ env.ARCH_EXT }}
@@ -858,7 +805,7 @@ jobs:
${{ env.PUBLISH_DIR }}/*.iso
- name: Generate SHA256 checksum files
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
run: |
(
cd $PUBLISH_DIR
@@ -871,9 +818,8 @@ jobs:
)
- name: Delete Release tag ${{ env.VERSION }}${{ env.ARCH_EXT }}
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
run: |
sed -i "1i Build Time:$BUILD_TIME" $PUBLISH_DIR/CHANGELOG
HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
RELEASE_INFO=$(curl -s -H "$HEADER" https://api.github.com/repos/${{ github.repository }}/releases/tags/$VERSION$ARCH_EXT)
RELEASE_ID=$(echo $RELEASE_INFO | jq -r '.id')
@@ -889,27 +835,111 @@ jobs:
echo "Release not found for tag: $VERSION$ARCH_EXT)"
fi
- name: Generate Release Body
if: env.RELEASE == 'true'
run: |
RELEASE_BODY="$BUILD_DIR/RELEASE_BODY.md"
BASE_URL="https://github.com/${{ github.repository }}/releases/download/$VERSION$ARCH_EXT"
BUILD_TIME_UTC=$(date -u -d "@$BUILD_TIME" "+%Y-%m-%d %H:%M:%S UTC" 2>/dev/null || echo "Invalid timestamp")
link_file() {
local file="$1"
if [ -f "$file" ]; then
local basename=$(basename "$file")
echo "[$basename]($BASE_URL/$basename)"
else
echo "N/A"
fi
}
cat > "$RELEASE_BODY" << EOF
**Build Time**: $BUILD_TIME_UTC ($BUILD_TIME)
**Architecture**: $ARCH
**Channel**: $CHANNELS
<details open><summary><strong>RouterOS</strong></summary>
| Type | File |
|------|------|
EOF
echo "| Main package | $(link_file "$PUBLISH_DIR/routeros-${VERSION}${ARCH_EXT}.npk") |" >> "$RELEASE_BODY"
echo "| Extra packages | $(link_file "$PUBLISH_DIR/all_packages-$ARCH-$VERSION.zip") |" >> "$RELEASE_BODY"
if [ "$ARCH" == "x86" ] || [ "$ARCH" == "arm64" ]; then
echo "| ISO Image | $(link_file "$PUBLISH_DIR/mikrotik-${VERSION}${ARCH_EXT}.iso") |" >> "$RELEASE_BODY"
fi
if [ "$ARCH" == "x86" ]; then
echo "| Install Image | $(link_file "$PUBLISH_DIR/install-image-$VERSION.zip") |" >> "$RELEASE_BODY"
echo "| Netinstall | $(link_file "$PUBLISH_DIR/netinstall-$VERSION.zip") |" >> "$RELEASE_BODY"
fi
echo "</details>" >> "$RELEASE_BODY"
echo "" >> "$RELEASE_BODY"
if [ "$ARCH" == "x86" ] || [ "$ARCH" == "arm64" ]; then
echo "<details open><summary><strong>Cloud Hosted Router (CHR)</strong></summary>" >> "$RELEASE_BODY"
echo "" >> "$RELEASE_BODY"
if [ "$ARCH" == "x86" ]; then
echo "| Platform | UEFI | Legacy BIOS |" >> "$RELEASE_BODY"
echo "|--------|------|-------------|" >> "$RELEASE_BODY"
else
echo "| Platform | UEFI |" >> "$RELEASE_BODY"
echo "|--------|------|" >> "$RELEASE_BODY"
fi
formats=("img" "ova" "qcow2" "vdi" "vhd" "vhdx" "vmdk")
declare -A FORMAT_PLATFORM=(
["img"]="Raw disk image"
["ova"]="Open Virtual Appliance"
["qcow2"]="QEMU/KVM"
["vdi"]="VirtualBox"
["vhd"]="Hyper-V (legacy)"
["vhdx"]="Hyper-V"
["vmdk"]="VMware"
)
for fmt in "${formats[@]}"; do
platform="${FORMAT_PLATFORM[$fmt]}"
uefi_link=$(link_file "$PUBLISH_DIR/chr-$VERSION$ARCH_EXT.$fmt.zip")
if [ "$ARCH" == "x86" ]; then
legacy_link=$(link_file "$PUBLISH_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.$fmt.zip")
echo "| $platform | $uefi_link | $legacy_link |" >> "$RELEASE_BODY"
else
echo "| $platform | $uefi_link |" >> "$RELEASE_BODY"
fi
done
echo "</details>" >> "$RELEASE_BODY"
echo "" >> "$RELEASE_BODY"
fi
echo "<details><summary><strong>Changelog</strong></summary>" >> "$RELEASE_BODY"
echo "" >> "$RELEASE_BODY"
echo "<pre>" >> "$RELEASE_BODY"
cat "$PUBLISH_DIR/CHANGELOG" >> "$RELEASE_BODY"
echo "</pre>" >> "$RELEASE_BODY"
echo "</details>" >> "$RELEASE_BODY"
echo "📄 Release body content:"
cat "$RELEASE_BODY"
- name: Create Release tag ${{ env.VERSION }}${{ env.ARCH_EXT }}
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
uses: softprops/action-gh-release@v3
with:
name: "RouterOS ${{ env.VERSION }}${{ env.ARCH_EXT }}"
repository: ${{ github.repository }}
token: ${{ secrets.GITHUB_TOKEN }}
body_path: ${{env.PUBLISH_DIR}}/CHANGELOG
body_path: ${{env.BUILD_DIR}}/RELEASE_BODY.md
tag_name: ${{ env.VERSION }}${{ env.ARCH_EXT }}
make_latest: ${{ env.CHANNEL == 'stable' && matrix.arch == 'x86'}}
prerelease: ${{ env.CHANNEL == 'testing'}}
make_latest: ${{ contains(env.CHANNELS, 'stable') && matrix.arch == 'x86' }}
prerelease: ${{ contains(env.CHANNELS,'development') || contains(env.CHANNELS,'testing') }}
files: |
${{env.PUBLISH_DIR}}/*.zip
${{env.PUBLISH_DIR}}/*.iso
${{env.PUBLISH_DIR}}/routeros*.npk
${{env.PUBLISH_DIR}}/*.zip.sha256
${{env.PUBLISH_DIR}}/*.iso
${{env.PUBLISH_DIR}}/*.iso.sha256
${{env.PUBLISH_DIR}}/routeros*.npk
${{env.PUBLISH_DIR}}/routeros*.npk.sha256
- name: Upload Files
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
run: |
sudo apt-get install -y knockd lftp > /dev/null
knock -4 ${{ secrets.SSH_SERVER }} ${{ secrets.SSH_KNOCK_PORT }}
@@ -929,9 +959,11 @@ jobs:
rm -f $PUBLISH_DIR/*.iso
rm -f $PUBLISH_DIR/*.zip.sha256
rm -f $PUBLISH_DIR/*.iso.sha256
sed -i '1d' $PUBLISH_DIR/CHANGELOG
echo $VERSION $BUILD_TIME | tee $PUBLISH_DIR/info
touch $PUBLISH_DIR/$CHANNEL
echo "$CHANNELS" | jq -r '.[]' | while read -r CHANNEL
do
touch "$PUBLISH_DIR/$CHANNEL"
done
REMOTE_PATH=${{ secrets.SSH_DIRECTORY }}/$VERSION
SERVER=${{ secrets.SSH_SERVER }}
USER=${{ secrets.SSH_USERNAME }}
@@ -945,7 +977,7 @@ jobs:
EOF
- name: Clear Cloudflare cache
if: needs.Prepare_Patch.outputs.RELEASE == 'true'
if: env.RELEASE == 'true'
run: |
curl --request POST --url "https://api.cloudflare.com/client/v4/zones/fe6831ed6dc9e6235e69ef2a31f2e7fe/purge_cache" \
--header "Authorization: Bearer 9GDQkzU51QXaqzp1qMjyFKpyeJyOdnNoG9GZQaGP" \
@@ -953,15 +985,12 @@ jobs:
--data '{"purge_everything": true}'
Update_Release:
needs: [Prepare_Patch,Patch_RouterOS]
if: |
needs.Prepare_Patch.outputs.SKIP_BUILD == 'false' &&
needs.Patch_RouterOS.result == 'success' &&
needs.Prepare_Patch.outputs.RELEASE == 'true'
needs: [Patch_RouterOS]
if: needs.Patch_RouterOS.result == 'success' && inputs.release == true
runs-on: ubuntu-24.04
env:
CHANNEL: ${{ inputs.channel }}
VERSION: ${{ needs.Prepare_Patch.outputs.VERSION }}
CHANNELS: ${{ inputs.channels }}
VERSION: ${{ inputs.version }}
steps:
- name: Update Release
run: |
@@ -984,9 +1013,21 @@ jobs:
USER=${{ secrets.SSH_USERNAME }}
PASS=${{ secrets.SSH_PASSWORD }}
PORT=${{ secrets.SSH_PORT }}
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no -p $PORT $USER@$SERVER \
"bash /rw/disk/$REMOTE_PATH/packages.sh /rw/disk/$REMOTE_PATH/$VERSION; \
ln -sf /root/$REMOTE_PATH/$VERSION/info /rw/disk/$REMOTE_PATH/NEWESTa7.$CHANNEL; \
chown -R 32768:32768 /rw/disk/$REMOTE_PATH"
REMOTE_CMD="
set -e
bash /rw/disk/$REMOTE_PATH/packages.sh /rw/disk/$REMOTE_PATH/$VERSION
"
while read -r CHANNEL
do
REMOTE_CMD="$REMOTE_CMD
ln -sfn /root/$REMOTE_PATH/$VERSION/info /rw/disk/$REMOTE_PATH/NEWESTa7.$CHANNEL"
done < <(echo "$CHANNELS" | jq -r '.[]')
REMOTE_CMD="$REMOTE_CMD
chown -R 32768:32768 /rw/disk/$REMOTE_PATH
"
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no -p $PORT $USER@$SERVER "$REMOTE_CMD"
echo "✅ Updated: packages.csv"

141
README.md
View File

@@ -1,71 +1,104 @@
# MikroTik RouterOS Patch
[![Patch Mikrotik RouterOS](https://github.com/elseif/MikroTikPatch/actions/workflows/main.yml/badge.svg)](https://github.com/elseif/MikroTikPatch/actions/workflows/main.yml)
![Cloud Status](https://img.shields.io/endpoint?url=https://mikrotik.ltd/status/cloud)
### 感谢赞助
[![DigitalOcean Referral Badge](https://web-platforms.sfo2.cdn.digitaloceanspaces.com/WWW/Badge%201.svg)](https://www.digitalocean.com/?refcode=dbf6ed365068&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge)
[DartNode(aff)](https://dartnode.com?aff=SnazzyLobster067) | [ZMTO(aff)](https://console.zmto.com/?affid=1588) | [Vultr(aff)](https://www.vultr.com/?ref=9807160-9J)
**重要提示:** 仅用于**测试目的**。使用风险自负。生产环境请使用官方授权版本。
继续操作即表示您确认:
- 您已阅读并理解所涉及的法律风险和影响
- 这些工具将仅在非生产测试环境中使用
- 生产部署将使用官方授权软件
# MikroTik RouterOS Patch [[English](README_EN.md)]
[![License: WTFPL](https://img.shields.io/badge/License-WTFPL-brightgreen.svg)](./LICENSE)
[![CoC:WTFCoC](https://img.shields.io/badge/CoC-WTFCoC-brightgreen.svg)](./CODE_OF_CONDUCT.md)
### [[Discord](https://discord.gg/keV6MWQFtX)] [[Telegram](https://telegram.me/mikrotikpatch)] [[Keygen(Telegram Bot)](https://telegram.me/ROS_Keygen_Bot)]
**English** | [中文](./README_CN.md)
支持:在线更新、在线授权、云备份、DDNS
> ## ⚠️ Important Notice
>
> **This project and its tools are for testing purposes only. Use at your own risk. Please use the officially licensed version for production environments.**
![Cloud Status](https://img.shields.io/endpoint?url=https://mikrotik.ltd/status/cloud)
## 🏗️ Architecture Support
### x86 / arm64 (This Project)
- **Homepage:** https://mikrotik.ltd/
- **Demo:** https://demo.mikrotik.ltd/
- **License: Installing `option.npk` will automatically grant the highest-level license.**
- **License Bot:** https://t.me/ROS_Keygen_Bot
- **Docker** `docker run -d --privileged --name chr ghcr.io/elseif/chr:latest`
*如果云服务或部署云服务的虚拟主机都不在线那么在线更新、在线授权、云备份、DDNS以及ROS_Keygen_Bot都暂时不能使用*
### arm64, arm, mipsbe, mmips, ppc, smips, x86
- **Homepage:** https://routeros.ltd/
- **License: Sponsorship required.** *CHR versions (x86/Arm64) support online direct licensing.*
- **Features:** Supports online custom brand package creation.
---
### 从7.19.4和7.20beta8开始安装option包以后会自动激活授权如果有rc.local文件会自动加载运行。
```mermaid
graph TD
A[启动] --> B[检查 keygen 文件是否存在 ]
B -->|是| C[fork 执行 keygen]
B -->|否| D[检查 rc.local 文件是否存在]
C --> D
D -->|是| E[fork 执行 /bin/sh rc.local]
D -->|否| F[启动服务]
E --> F
## 🔧 Feature Guide
> All features below require the `option.npk` package to be installed first.
### 1. Enable Container Mode (No Physical Reboot Required)
```bash
# Step 1: Enable container mode
/system/device-mode/update container=yes
# Step 2: Force reboot (execute in a new terminal)
/system/shell cmd="reboot -f"
```
![](image/install.png)
![](image/routeros.png)
### 2. Shell Access
#### A. Via Terminal
```bash
/system/shell
# or shorthand
/sh
```
#### B. Via SSH / Telnet
```bash
# Username: devel
# Password: Same as the admin password
ssh devel@<router-ip>
```
### 3. x86 Architecture: CHR ↔ x86 Mode Switch
### x86模式在线授权(v6.x)
![](image/renew_v6.png)
### Chr模式在线授权
![](image/renew.png)
```bash
# Execute after entering shell
keygen chr # Switch to CHR mode
keygen x86 # Switch to x86 mode
```
### 4. Boot Auto-Run Script
![](image/arm.png)
![](image/mips.png)
1. Create or edit the `/rw/disk/rc.local` file.
2. Write your script content, for example
## 如何使用Shell
安装 option-{version}.npk 包
在终端执行 /sh 进入shell
## 如何授权许可
安装 option-{version}.npk 包后,重启设备,会自动激活授权许可
Chr镜像支持在线授权许可
## 如何使用Python
安装 python3-{version}.npk 包
在终端执行 /sh 进入shell
运行 python -V
### npk.py
对npk文件进行解包修改创建签名和验证
### patch.py
替换公钥并签名
### 如何在不物理重启的情况下启用容器模式
1. 安装 option.npk 包。
2. 打开终端并执行:`system/device-mode/update container=yes`
3. 打开一个新终端并执行: `system/shell cmd="reboot -f"`
```bash
#!/bin/sh
# This script will be executed *before* RouterOS *loader* start.
# You can put your own initialization stuff in here
echo "Hello, world!"
```
3. You will see the output during boot: `Starting rc.local...`
4. After boot, check the output:
```bash
# Enter shell
cat /ram/startup.catlog | grep 'Hello'
```
---
## ☁️ Cloud Services
| Feature | Command |
|------|------|
| Online Upgrade | `system/package/update/install` |
| Dynamic DNS | `ip/cloud/set ddns-enabled=yes` |
| Cloud Backup | `/system/backup/cloud/upload-file action=create-and-upload password=any` |
| Internet Detection | `/interface/detect-internet/set detect-interface-list=all` |
---
## 📚 Resources
- [MikroTik Official Documentation](https://manual.mikrotik.com/)
- [Telegram Group](https://t.me/+99Mw06p3K7NlMmNl)
- [GitHub Source Code](https://github.com/elseif/MikroTikPatch)
---
## 💖 Sponsors
[![Powered by DartNode](https://dartnode.com/branding/DN-Open-Source-sm.png)](https://dartnode.com "Powered by DartNode - Free VPS for Open Source")
[DartNode(aff)](https://dartnode.com?aff=SnazzyLobster067) | [ZMTO(aff)](https://console.zmto.com/?affid=1588) | [Vultr(aff)](https://www.vultr.com/?ref=9807160-9J)

115
README_CN.md Normal file
View File

@@ -0,0 +1,115 @@
# MikroTik RouterOS Patch
[![Patch Mikrotik RouterOS](https://github.com/elseif/MikroTikPatch/actions/workflows/main.yml/badge.svg)](https://github.com/elseif/MikroTikPatch/actions/workflows/main.yml)
![Cloud Status](https://img.shields.io/endpoint?url=https://mikrotik.ltd/status/cloud)
[![License: WTFPL](https://img.shields.io/badge/License-WTFPL-brightgreen.svg)](./LICENSE)
[![CoC:WTFCoC](https://img.shields.io/badge/CoC-WTFCoC-brightgreen.svg)](./CODE_OF_CONDUCT.md)
[English](./README.md) | **中文**
>## ⚠️ 重要声明
>
>**此项目及工具仅供测试用途。使用风险自负。生产环境请使用官方授权版本。**
## 🏗️ 架构支持
### x86 / arm64 (本项目)
- **主页:** https://mikrotik.ltd/
- **演示:** https://demo.mikrotik.ltd/
- **授权: 安装option.npk后将自动授予最高级别许可证。**
- **授权BOT** https://t.me/ROS_Keygen_Bot
- **Docker** `docker run -d --privileged --name chr ghcr.io/elseif/chr:latest`
### arm64, arm, mipsbe, mmips, ppc, smips, x86
- **主页:** https://routeros.ltd/
- **授权: 需要赞助***CHR版本(x86/Arm64)支持在线直接获取授权*
- **功能:** 支持在线自定义制作品牌包
---
## 🔧 功能指南
> 以下功能均需先安装 `option.npk` 包。
### 1. 启用容器模式(无需物理重启)
```bash
# 步骤 1启用容器模式
/system/device-mode/update container=yes
# 步骤 2强制重启在新终端中执行
/system/shell cmd="reboot -f"
```
### 2. Shell 访问
#### A. 通过终端
```bash
/system/shell
# 或简写
/sh
```
#### B. 通过 SSH / Telnet
```bash
# 用户名: devel
# 密码: 与 admin 密码相同
ssh devel@<router-ip>
```
### 3. x86 架构CHR ↔ x86 模式切换
```bash
# 进入 shell 后执行
keygen chr # 切换为 CHR 模式
keygen x86 # 切换为 x86 模式
```
### 4. 开机自动运行脚本
1. 创建或编辑 `/rw/disk/rc.local` 文件
2. 写入脚本内容,例如:
```bash
#!/bin/sh
# This script will be executed *before* RouterOS *loader* start.
# You can put your own initialization stuff in here
echo "Hello, world!"
```
3. 开机启动时将看到输出:`Starting rc.local...`
4. 启动后查看输出:
```bash
# 进入 shell
cat /ram/startup.catlog | grep 'Hello'
```
---
## ☁️ 云服务
| 功能 | 命令 |
|------|------|
| 在线升级 | `system/package/update/install` |
| 动态域名 | `ip/cloud/set ddns-enabled=yes` |
| 云备份 | `/system/backup/cloud/upload-file action=create-and-upload password=any` |
| 网络检测 | `/interface/detect-internet/set detect-interface-list=all` |
---
## 📚 相关资源
- [MikroTik 官方文档](https://manual.mikrotik.com/)
- [Telegram 群组](https://t.me/+99Mw06p3K7NlMmNl)
- [GitHub 源码](https://github.com/elseif/MikroTikPatch)
---
## 💖 感谢赞助
[![Powered by DartNode](https://dartnode.com/branding/DN-Open-Source-sm.png)](https://dartnode.com "Powered by DartNode - Free VPS for Open Source")
[DartNode(aff)](https://dartnode.com?aff=SnazzyLobster067) | [ZMTO(aff)](https://console.zmto.com/?affid=1588) | [Vultr(aff)](https://www.vultr.com/?ref=9807160-9J)

View File

@@ -1,57 +0,0 @@
[![Patch Mikrotik RouterOS](https://github.com/elseif/MikroTikPatch/actions/workflows/main.yml/badge.svg)](https://github.com/elseif/MikroTikPatch/actions/workflows/main.yml)
**IMPORTANT:** For **testing purposes only**. Use at your own risk. Production environments require official licenses.
By proceeding, you acknowledge that:
- You have reviewed and comprehend the legal implications and risks involved
- These tools will be used exclusively in non-production, test environments
- Production deployments shall utilize officially licensed software
# MikroTik RouterOS Patch [[中文](README.md)]
[![License: WTFPL](https://img.shields.io/badge/License-WTFPL-brightgreen.svg)](./LICENSE)
[![CoC:WTFCoC](https://img.shields.io/badge/CoC-WTFCoC-brightgreen.svg)](./CODE_OF_CONDUCT.md)
### [[Discord](https://discord.gg/keV6MWQFtX)] [[Telegram](https://telegram.me/mikrotikpatch)] [[Keygen(Telegram Bot)](https://telegram.me/ROS_Keygen_Bot)]
### Download [Latest Patched](https://github.com/elseif/MikroTikPatch/releases/latest) iso file,install it and enjoy.
### CHR image is both support BIOS and UEFI boot mode.
### Support online upgrade,online license,cloud backup,cloud DDNS
![](image/install.png)
![](image/routeros.png)
### Renew license for x86 v6.x
![](image/renew_v6.png)
### Renew license for chr
![](image/renew.png)
![](image/arm.png)
![](image/mips.png)
## How to use shell
install option-{version}.npk package
Enter the shell by executing /sh in the terminal.
## How to license RouterOS
After installing the option-{version}.npk package, reboot the device. The license will be activated automatically.
CHR images support online license activation
## How to use python3
install python3-{version}.npk package
Enter the shell by executing /sh in the terminal.
run python -V
### npk.py
SignVerifyCreate, Extract npk file.
### patch.py
Patch public key and sign NPK files
### How to Enable Container Mode Without Physical Reboot
1. Install the option.npk package.
2. Open a terminal and run: `system/device-mode/update container=yes`
3. Open a new terminal and run: `system/shell cmd="reboot -f"`
## all patches are applied automatically with [Github Action](https://github.com/elseif/MikroTikPatch/blob/main/.github/workflows/).

View File

@@ -1,64 +0,0 @@
[![Patch Mikrotik RouterOS](https://github.com/elseif/MikroTikPatch/actions/workflows/main.yml/badge.svg)](https://github.com/elseif/MikroTikPatch/actions/workflows/main.yml)
# Patch para MikroTik RouterOS [[中文](README.md)]
[![License: WTFPL](https://img.shields.io/badge/License-WTFPL-brightgreen.svg)](./LICENSE)
[![CoC:WTFCoC](https://img.shields.io/badge/CoC-WTFCoC-brightgreen.svg)](./CODE_OF_CONDUCT.md)
### [[Discord](https://discord.gg/keV6MWQFtX)] [[Telegram](https://telegram.me/mikrotikpatch)] [[Keygen (Bot do Telegram)](https://telegram.me/ROS_Keygen_Bot)]
### Baixe a [ISO modificada mais recente](https://github.com/elseif/MikroTikPatch/releases/latest), instale e aproveite.
### A imagem CHR suporta modo de boot tanto BIOS quanto UEFI.
### Suporte a atualização online, licença online, backup em nuvem e DDNS em nuvem
![](image/install.png)
![](image/routeros.png)
### Renovar a licença para x86 v6.x
![](image/renew_v6.png)
### Renovar a licença para CHR
![](image/renew.png)
![](image/arm.png)
![](image/mips.png)
## Como usar o shell
```bash
instale o pacote option-{versão}.npk
Execute `/sh` no terminal para entrar no Shell.
```
## Como licenciar o RouterOS
```bash
Após instalar o pacote `option-{version}.npk`, reinicie o dispositivo. A licença será ativada automaticamente.
Imagens CHR suportam ativação de licença online.
```
## Como usar o Python 3
```bash
instale o pacote python3-{versão}.npk
Execute `/sh` no terminal para entrar no Shell.
execute `python -V`
```
### npk.py
```bash
Assina, verifica, cria e extrai arquivos .npk
```
### patch.py
```bash
Altera a chave pública e assina arquivos .npk
```
### Como ativar o modo container sem reiniciar fisicamente
```bash
1. Instale o pacote `option.npk`.
2. Abra o terminal e execute: `system/device-mode/update container=yes`
3. Abra um novo terminal e execute: `system/shell cmd="reboot -f"`
```
## Thanks for sponsoring
[ZMTO](https://console.zmto.com/)
## Todos os patches são aplicados automaticamente com [GitHub Actions](https://github.com/elseif/MikroTikPatch/blob/main/.github/workflows/)

Binary file not shown.

Binary file not shown.

28
chr.sh
View File

@@ -61,9 +61,9 @@ select_language() {
MSG_GATEWAY="Gateway:"
MSG_DNS="Domain Name Server:"
MSG_SELECT_VERSION="Select the version you want to install:"
MSG_LTS="long-term (v7)"
MSG_STABLE="stable (v7)"
MSG_TEST="testing (v7)"
MSG_LTS="long-term (v6)"
MSG_LTS6="long-term (v6)"
MSG_STABLE6="stable (v6)"
MSG_PLEASE_CHOOSE="Please choose an option:"
MSG_UNSUPPORTED_ARCH="Error: Unsupported architecture: "
@@ -92,9 +92,9 @@ select_language() {
MSG_GATEWAY="网关地址:"
MSG_DNS="DNS服务器:"
MSG_SELECT_VERSION="请选择您要安装的版本:"
MSG_LTS="长期支持版 (v7)"
MSG_STABLE="稳定版 (v7)"
MSG_TEST="测试版 (v7)"
MSG_LTS="长期支持版 (v6)"
MSG_LTS6="长期支持版 (v6)"
MSG_STABLE6="稳定版 (v6)"
MSG_PLEASE_CHOOSE="请选择一个选项:"
MSG_UNSUPPORTED_ARCH="错误: 不支持的架构: "
@@ -207,15 +207,15 @@ select_version() {
x86_64|i386|i486|i586|i686)
echo "$MSG_SELECT_VERSION"
echo "1. $MSG_STABLE"
echo "2. $MSG_TEST"
echo "3. $MSG_LTS"
echo "4. $MSG_STABLE6"
echo "2. $MSG_LTS"
echo "3. $MSG_STABLE6"
echo "4. $MSG_LTS6"
read -p "$MSG_PLEASE_CHOOSE [1-4]" version_choice
;;
aarch64)
echo "$MSG_SELECT_VERSION"
echo "1. $MSG_STABLE"
echo "2. $MSG_TEST"
echo "2. $MSG_LTS"
read -p "$MSG_PLEASE_CHOOSE [1-2]" version_choice
;;
*)
@@ -229,7 +229,7 @@ select_version() {
V7=1
;;
2)
VERSION=$(http_get "https://upgrade.mikrotik.ltd/routeros/NEWESTa7.testing" | cut -d' ' -f1)
VERSION=$(http_get "https://upgrade.mikrotik.ltd/routeros/NEWESTa7.long-term" | cut -d' ' -f1)
V7=1
;;
3)
@@ -237,7 +237,7 @@ select_version() {
echo "$MSG_ARM64_NOT_SUPPORT_V6"
continue
fi
VERSION=$(http_get "https://upgrade.mikrotik.ltd/routeros/NEWEST6.long-term" | cut -d' ' -f1)
VERSION=$(http_get "https://upgrade.mikrotik.ltd/routeros/NEWEST6.stable" | cut -d' ' -f1)
V7=0
;;
4)
@@ -245,7 +245,7 @@ select_version() {
echo "$MSG_ARM64_NOT_SUPPORT_V6"
continue
fi
VERSION=$(http_get "https://upgrade.mikrotik.ltd/routeros/NEWEST6.stable" | cut -d' ' -f1)
VERSION=$(http_get "https://upgrade.mikrotik.ltd/routeros/NEWEST6.long-term" | cut -d' ' -f1)
V7=0
;;
*)
@@ -294,6 +294,12 @@ create_autorun() {
ask_until "$MSG_ADMIN_PASSWORD" "$RANDOM_ADMIN_PASS"
RANDOM_ADMIN_PASS=$resp
cat <<EOF > "$MNT/rw/autorun.scr"
/tool mac-server set allowed-interface-list=none
/tool mac-server mac-winbox set allowed-interface-list=none
/tool mac-server ping set enabled=no
/ip neighbor discovery-settings set discover-interface-list=none
/tool bandwidth-server set enabled=no
/ip dns set allow-remote-requests=no
/user set admin password="$RANDOM_ADMIN_PASS"
/ip dns set servers=$DNS
/ip address add address=$ADDRESS interface=[/interface ethernet get [find mac-address=$MAC] name]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 464 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 725 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 607 KiB

View File

@@ -196,11 +196,6 @@
<div class="w-11 h-6 bg-slate-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
</label>
</div>
<!-- Clear cache button -->
<div>
<button data-i18n="clearCache" id="clear-cache" class="w-full text-sm font-semibold bg-slate-100 hover:bg-slate-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-slate-700 dark:text-slate-200 py-2 px-4 rounded-lg transition-colors flex items-center justify-center gap-2"></button>
</div>
</div>
</div>
</div>
@@ -285,24 +280,6 @@
</footer>
</div>
<!-- URLs modal for cache clearing -->
<div id="urls-pannel" class="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4 hidden" tabindex="-1">
<div class="bg-white dark:bg-gray-800 rounded-xl shadow-2xl w-full max-w-2xl max-h-[90vh] flex flex-col transform transition-all opacity-0 scale-95" id="modal-content">
<header class="p-4 border-b border-slate-200 dark:border-gray-700 flex justify-between items-center">
<h3 class="text-lg font-semibold text-slate-800 dark:text-white" data-i18n="copyUrlsClearCache"></h3>
<button id="urls-close" class="p-1 rounded-full text-slate-400 hover:bg-slate-100 dark:hover:bg-gray-700">
<span class="sr-only">Close modal</span>
<span class="iconify text-2xl" data-icon="ph:x-bold"></span>
</button>
</header>
<!-- URLs list display area -->
<div id="urls-list" class="p-6 text-sm text-slate-600 dark:text-slate-400 overflow-y-auto custom-scrollbar flex-grow bg-slate-50 dark:bg-gray-900/50 rounded-b-xl whitespace-pre-wrap break-all"></div>
<footer class="p-4 border-t border-slate-200 dark:border-gray-700">
<button id="copy-to-clear-cache" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 focus:ring-offset-white dark:focus:ring-offset-gray-800 flex items-center justify-center gap-2" data-i18n="copyUrlsClearCache" href="#"></button>
</footer>
</div>
</div>
<!-- Changelog popup modal -->
<div id="changelog-modal" class="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4 hidden" tabindex="-1">
@@ -366,8 +343,6 @@
infoLabel2:`For more information about <b>install and upgrade</b> see the <a href="https://help.mikrotik.com/docs/" target="_blank" class="text-blue-500 dark:text-blue-400 hover:underline">Documentation</a>. For more information about <b>patch</b> see the <a href="https://github.com/elseif/MikroTikPatch" target="_blank" class="text-blue-500 dark:text-blue-400 hover:underline">MikroTikPatch</a>.`,
installCmdLabel:"Install Command",
proxyLabel:"Enable GitHub Proxy Accelerator",
clearCache:"Clear gh-proxy Cache",
copyUrlsClearCache:"Copy URLs & Open Clear Cache Page",
loading:"Loading latest versions...",
quickInformation:"Quick Information",
settings:"Settings",
@@ -382,8 +357,6 @@
infoLabel2:`有关<b>安装和升级</b>的更多信息,请参阅<a href="https://help.mikrotik.com/docs/" target="_blank" class="text-blue-500 dark:text-blue-400 hover:underline">文档</a><br>有关<b>Patch</b>的更多信息,请参阅<a href="https://github.com/elseif/MikroTikPatch" target="_blank" class="text-blue-500 dark:text-blue-400 hover:underline">MikroTikPatch</a>`,
installCmdLabel:"安装命令",
proxyLabel:"启用GitHub代理加速",
clearCache:"清除gh-proxy缓存",
copyUrlsClearCache:"复制链接并打开缓存清除页面",
loading:"正在加载最新版本...",
quickInformation:"快速信息",
settings:"设置",
@@ -400,11 +373,7 @@
const key = el.getAttribute("data-i18n");
if (i18n[lang] && i18n[lang][key]) {
// Special handling for buttons that need icons
if (key === 'clearCache') {
el.innerHTML = `<span class="iconify" data-icon="${ICONS.trash}"></span> ${i18n[lang][key]}`;
} else if (key === 'copyUrlsClearCache' && el.id === 'copy-to-clear-cache') {
el.innerHTML = `<span class="iconify" data-icon="${ICONS.copyAndOpen}"></span> ${i18n[lang][key]}`;
} else if (key === 'installCmdLabel') {
if (key === 'installCmdLabel') {
el.innerHTML = `<span class="iconify mr-2 text-blue-500" data-icon="ph:terminal-window-bold"></span>${i18n[lang][key]}`;
}
else {
@@ -473,9 +442,9 @@
// Fetch latest version numbers from MikroTik servers
const loadingOverlay = document.getElementById("loading");
const [routeros7_stable, routeros7_testing, routeros6_longterm, routeros6_stable] = await Promise.all([
const [routeros7_stable, routeros7_longterm, routeros6_longterm, routeros6_stable] = await Promise.all([
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWESTa7.stable?ts=${Date.now()}`, "7.19.4"),
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWESTa7.testing?ts=${Date.now()}`, "7.20rc1"),
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWESTa7.long-term?ts=${Date.now()}`, "7.20rc1"),
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWEST6.long-term?ts=${Date.now()}`, "6.49.18"),
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWEST6.stable?ts=${Date.now()}`, "6.49.19"),
]);
@@ -487,7 +456,7 @@
const downloads =[
{
title:"RouterOS v7",
versions:[ { title:"Stable", version:routeros7_stable }, { title:"Testing", version:routeros7_testing } ],
versions:[ { title:"Long-Term", version:routeros7_longterm },{ title:"Stable", version:routeros7_stable } ],
groups: [
{ title:"ARM64 / AMPERE", arch:"arm64", downloads:[ { title:"Main package", type:"main" }, { title:"Extra packages", type:"extra" }, { title:"ISO image for AMPERE", type:"iso" } ] },
{ title:"X86", arch:"x86", downloads:[ { title:"Main package", type:"main" }, { title:"Extra packages", type:"extra" }, { title:"CD Image", type:"iso" }, { title:"Install image", type:"install" } ] },
@@ -503,7 +472,7 @@
},
{
title:"Cloud Hosted Router",
versions:[ { title:"Long-Term", version:routeros6_longterm }, { title:"Stable", version:routeros6_stable }, { title:"Stable", version:routeros7_stable }, { title:"Testing", version:routeros7_testing } ],
versions:[ { title:"Long-Term", version:routeros6_longterm }, { title:"Stable", version:routeros6_stable }, { title:"Long-Term", version:routeros7_longterm }, { title:"Stable", version:routeros7_stable } ],
groups:[
{ title:"X86", arch:"x86", downloads:[ { title:"Main package", type:"main" }, { title:"Extra packages", type:"extra" }, { title:"VHDX image", type:"vhdx" }, { title:"VMDK image", type:"vmdk" }, { title:"VDI image", type:"vdi" }, { title:"VirtualPC image", type:"vhd" }, { title:"Raw disk image", type:"img" }, { title:"OVA template", type:"ova" } ] },
{ title:"ARM64 / AMPERE", arch:"arm64", downloads:[ { title:"Main package", type:"main" }, { title:"Extra packages", type:"extra" }, { title:"VHDX image", type:"vhdx" }, { title:"VMDK image", type:"vmdk" }, { title:"VDI image", type:"vdi" }, { title:"VirtualPC image", type:"vhd" }, { title:"Raw disk image", type:"img" } ] }
@@ -618,13 +587,11 @@
// GitHub proxy functionality
const ghProxyCheckbox = document.getElementById("gh-proxy");
const clearCacheBtn = document.getElementById("clear-cache");
if (localStorage.getItem("gh-proxy-enabled") === null && navigator.language.startsWith("zh")) {
// Enable GitHub proxy by default for Chinese users
localStorage.setItem("gh-proxy-enabled", "true");
}
ghProxyCheckbox.checked = localStorage.getItem("gh-proxy-enabled") === "true";
clearCacheBtn.style.display = ghProxyCheckbox.checked ? "inline-flex" : "none";
// Update all download links with/without GitHub proxy
function updateAllDownloadLinks() {
@@ -646,33 +613,9 @@
// GitHub proxy toggle event listener
ghProxyCheckbox.addEventListener("change", () => {
localStorage.setItem("gh-proxy-enabled", ghProxyCheckbox.checked ? "true" : "false");
clearCacheBtn.style.display = ghProxyCheckbox.checked ? "inline-flex" : "none";
updateAllDownloadLinks();
});
// Cache clearing modal functionality
const modal = document.getElementById("urls-pannel");
const modalContent = document.getElementById("modal-content");
clearCacheBtn.addEventListener("click", () => {
const links = document.querySelectorAll('a[href^="https://gh-proxy.com/https://github.com/elseif/MikroTikPatch/"]');
document.getElementById("urls-list").innerText = Array.from(links).map(a => a.href).filter(href => !href.includes(".yml")).join("\n");
modal.classList.remove('hidden');
setTimeout(() => { modalContent.classList.add('opacity-100', 'scale-100'); modalContent.classList.remove('opacity-0', 'scale-95'); }, 10);
});
// Modal close functionality
document.getElementById("urls-close").addEventListener("click", () => {
modalContent.classList.remove('opacity-100', 'scale-100');
modalContent.classList.add('opacity-0', 'scale-95');
setTimeout(() => modal.classList.add('hidden'), 200);
});
// Copy URLs and open cache clearing page
document.getElementById("copy-to-clear-cache").addEventListener("click", () => {
navigator.clipboard.writeText(document.getElementById("urls-list").innerText);
window.open("https://cache.gh-proxy.com/", "_blank");
document.getElementById("urls-close").click();
});
// Changelog modal functionality
const changelogModal = document.getElementById("changelog-modal");
@@ -766,8 +709,8 @@
// Generate version selection buttons
versionBtnsContainer.innerHTML = `
<button data-version="${routeros7_longterm}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v7 Long-Term</button>
<button data-version="${routeros7_stable}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v7 Stable</button>
<button data-version="${routeros7_testing}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v7 Testing</button>
<button data-version="${routeros6_longterm}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v6 Long-Term</button>
<button data-version="${routeros6_stable}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v6 Stable</button>
`;

Binary file not shown.

Binary file not shown.

39
npkextract/Makefile Normal file
View File

@@ -0,0 +1,39 @@
TOOLCHAIN_DIR ?= $(HOME)/musl-toolchains/i686-linux-musl-cross
CROSS_COMPILE ?= $(TOOLCHAIN_DIR)/bin/i686-linux-musl-
CC = $(CROSS_COMPILE)gcc
STRIP = $(CROSS_COMPILE)strip
TARGET = npkextract
SRC = npkextract.c
OBJ = $(SRC:.c=.o)
CFLAGS ?= -O2 -Wall -Wextra -D_GNU_SOURCE
CFLAGS += -static -m32
LDFLAGS += -static -s
.PHONY: all clean info
all: $(TARGET)
$(TARGET): $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
@$(STRIP) --strip-all $(TARGET) 2>/dev/null || true
@echo "=========================================================="
@echo " Successfully built static binary: $(TARGET)"
@ls -lh $(TARGET)
@file $(TARGET) 2>/dev/null || true
@echo "=========================================================="
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
info:
@echo "Compiler: $(CC)"
@echo "Strip: $(STRIP)"
@echo "CFLAGS: $(CFLAGS)"
@echo "LDFLAGS: $(LDFLAGS)"
clean:
rm -f $(TARGET) $(OBJ)

BIN
npkextract/npkextract Normal file

Binary file not shown.

426
npkextract/npkextract.c Normal file
View File

@@ -0,0 +1,426 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <utime.h>
typedef struct {
const unsigned char *source;
size_t source_len;
size_t tag;
unsigned int bitcount;
unsigned char *dest;
size_t dest_len;
size_t dest_cap;
} TINF_DATA;
typedef struct {
unsigned short table[16];
unsigned short trans[288];
} TINF_TREE;
static const unsigned char tinf_default_length_bits[30] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 127
};
static const unsigned short tinf_default_length_base[30] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0
};
static const unsigned char tinf_default_dist_bits[30] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13
};
static const unsigned short tinf_default_dist_base[30] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577
};
static const unsigned char tinf_clcidx[19] = {
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
};
static unsigned int tinf_getbit(TINF_DATA *d) {
if (!d->bitcount--) {
d->tag = d->source_len ? *d->source++ : 0;
if (d->source_len) d->source_len--;
d->bitcount = 7;
}
unsigned int bit = d->tag & 1;
d->tag >>= 1;
return bit;
}
static unsigned int tinf_read_bits(TINF_DATA *d, int num, int base) {
unsigned int val = 0;
if (num) {
unsigned int limit = 1 << num;
unsigned int mask;
for (mask = 1; mask < limit; mask <<= 1) {
if (tinf_getbit(d)) val += mask;
}
}
return val + base;
}
static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned int num) {
unsigned short offs[16];
unsigned int i, sum = 0;
for (i = 0; i < 16; ++i) t->table[i] = 0;
for (i = 0; i < num; ++i) t->table[lengths[i]]++;
t->table[0] = 0;
for (i = 0; i < 16; ++i) {
offs[i] = sum;
sum += t->table[i];
}
for (i = 0; i < num; ++i) {
if (lengths[i]) t->trans[offs[lengths[i]]++] = i;
}
}
static int tinf_decode_symbol(TINF_DATA *d, const TINF_TREE *t) {
int sum = 0, cur = 0, len = 0;
do {
cur = 2 * cur + tinf_getbit(d);
len++;
sum += t->table[len];
cur -= t->table[len];
} while (cur >= 0);
return t->trans[sum + cur];
}
static void tinf_build_fixed_trees(TINF_TREE *lt, TINF_TREE *dt) {
unsigned char lengths[288];
int i;
for (i = 0; i <= 143; ++i) lengths[i] = 8;
for (; i <= 255; ++i) lengths[i] = 9;
for (; i <= 279; ++i) lengths[i] = 7;
for (; i <= 287; ++i) lengths[i] = 8;
tinf_build_tree(lt, lengths, 288);
for (i = 0; i < 32; ++i) lengths[i] = 5;
tinf_build_tree(dt, lengths, 32);
}
static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) {
while (1) {
int sym = tinf_decode_symbol(d, lt);
if (sym == 256) return 0;
if (sym < 256) {
if (d->dest_len >= d->dest_cap) {
size_t ncap = d->dest_cap ? d->dest_cap * 2 : 1024 * 1024;
unsigned char *nd = realloc(d->dest, ncap);
if (!nd) return -1;
d->dest = nd;
d->dest_cap = ncap;
}
d->dest[d->dest_len++] = (unsigned char)sym;
} else {
sym -= 257;
int length = tinf_read_bits(d, tinf_default_length_bits[sym], tinf_default_length_base[sym]);
int dist_sym = tinf_decode_symbol(d, dt);
int dist = tinf_read_bits(d, tinf_default_dist_bits[dist_sym], tinf_default_dist_base[dist_sym]);
if (d->dest_len + length > d->dest_cap) {
size_t ncap = (d->dest_len + length) * 2 + 1024 * 1024;
unsigned char *nd = realloc(d->dest, ncap);
if (!nd) return -1;
d->dest = nd;
d->dest_cap = ncap;
}
unsigned char *src = d->dest + d->dest_len - dist;
while (length--) {
d->dest[d->dest_len++] = *src++;
}
}
}
}
static int tinf_inflate_uncompressed_block(TINF_DATA *d) {
d->bitcount = 0;
if (d->source_len < 4) return -1;
unsigned int length = d->source[0] | (d->source[1] << 8);
d->source += 4;
d->source_len -= 4;
if (d->source_len < length) return -1;
if (d->dest_len + length > d->dest_cap) {
size_t ncap = d->dest_len + length + 1024 * 1024;
unsigned char *nd = realloc(d->dest, ncap);
if (!nd) return -1;
d->dest = nd;
d->dest_cap = ncap;
}
memcpy(d->dest + d->dest_len, d->source, length);
d->dest_len += length;
d->source += length;
d->source_len -= length;
return 0;
}
static int tinf_inflate_dynamic_block(TINF_DATA *d) {
TINF_TREE lt, dt, ct;
unsigned char lengths[288 + 32];
unsigned int hlit = tinf_read_bits(d, 5, 257);
unsigned int hdist = tinf_read_bits(d, 5, 1);
unsigned int hclen = tinf_read_bits(d, 4, 4);
unsigned int i, num;
unsigned char clen[19];
memset(clen, 0, sizeof(clen));
for (i = 0; i < hclen; ++i) clen[tinf_clcidx[i]] = tinf_read_bits(d, 3, 0);
tinf_build_tree(&ct, clen, 19);
for (num = 0; num < hlit + hdist;) {
int sym = tinf_decode_symbol(d, &ct);
if (sym < 16) {
lengths[num++] = sym;
} else if (sym == 16) {
unsigned char prev = lengths[num - 1];
for (i = tinf_read_bits(d, 2, 3); i; --i) lengths[num++] = prev;
} else if (sym == 17) {
for (i = tinf_read_bits(d, 3, 3); i; --i) lengths[num++] = 0;
} else {
for (i = tinf_read_bits(d, 7, 11); i; --i) lengths[num++] = 0;
}
}
tinf_build_tree(&lt, lengths, hlit);
tinf_build_tree(&dt, lengths + hlit, hdist);
return tinf_inflate_block_data(d, &lt, &dt);
}
static unsigned char *zlib_decompress(const unsigned char *src, size_t src_len, size_t *out_len) {
if (src_len < 2) return NULL;
size_t offset = 0;
// Check zlib header (RFC 1950)
if ((src[0] * 256 + src[1]) % 31 == 0 && (src[0] & 0x0F) == 8) {
offset = 2;
if (src[1] & 0x20) offset += 4;
}
TINF_DATA d;
memset(&d, 0, sizeof(d));
d.source = src + offset;
d.source_len = src_len > offset ? src_len - offset : 0;
d.dest_cap = src_len * 4 + 1024 * 1024;
d.dest = malloc(d.dest_cap);
if (!d.dest) return NULL;
int bfinal;
do {
bfinal = tinf_getbit(&d);
int btype = tinf_read_bits(&d, 2, 0);
if (btype == 0) {
if (tinf_inflate_uncompressed_block(&d) < 0) { free(d.dest); return NULL; }
} else if (btype == 1) {
TINF_TREE lt, dt;
tinf_build_fixed_trees(&lt, &dt);
if (tinf_inflate_block_data(&d, &lt, &dt) < 0) { free(d.dest); return NULL; }
} else if (btype == 2) {
if (tinf_inflate_dynamic_block(&d) < 0) { free(d.dest); return NULL; }
} else {
free(d.dest);
return NULL;
}
} while (!bfinal);
*out_len = d.dest_len;
return d.dest;
}
static void mkdir_p(const char *dir) {
char tmp[1024];
snprintf(tmp, sizeof(tmp), "%s", dir);
for (char *p = tmp + 1; *p; p++) {
if (*p == '/') {
*p = '\0';
mkdir(tmp, 0755);
*p = '/';
}
}
mkdir(tmp, 0755);
}
const char *get_part_name(uint32_t id) {
switch (id) {
case 0x01: return "NAME_INFO";
case 0x02: return "DESCRIPTION";
case 0x03: return "DEPENDENCIES";
case 0x04: return "FILE_CONTAINER";
case 0x07: return "INSTALL_SCRIPT";
case 0x08: return "UNINSTALL_SCRIPT";
case 0x09: return "SIGNATURE";
case 0x10: return "ARCHITECTURE";
case 0x11: return "PKG_CONFLICTS";
case 0x12: return "PKG_INFO";
case 0x13: return "FEATURES";
case 0x14: return "PKG_FEATURES";
case 0x15: return "SQUASHFS";
case 0x16: return "NULL_BLOCK";
case 0x17: return "GIT_COMMIT";
case 0x18: return "CHANNEL";
case 0x19: return "HEADER";
default: return "UNKNOWN";
}
}
int main(int argc, char *argv[]) {
if (argc < 3) {
fprintf(stderr, "Usage: %s <package.npk> <output_directory>\n", argv[0]);
return 1;
}
const char *npk_path = argv[1];
const char *out_dir = argv[2];
FILE *fp = fopen(npk_path, "rb");
if (!fp) {
fprintf(stderr, "Error: Failed to open NPK file '%s'\n", npk_path);
return 1;
}
fseek(fp, 0, SEEK_END);
long file_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
printf("Parsing NPK: '%s' (%ld bytes)\n", npk_path, file_size);
mkdir_p(out_dir);
int total_extracted = 0;
long offset = 0;
while (offset + 6 <= file_size) {
fseek(fp, offset, SEEK_SET);
uint16_t id16;
uint32_t size32;
if (fread(&id16, 2, 1, fp) != 1 || fread(&size32, 4, 1, fp) != 1) {
break;
}
if (id16 > 0 && id16 <= 0x20 && size32 <= (uint32_t)(file_size - offset - 6)) {
printf(" [Part 0x%02X: %-15s] offset=%ld, size=%u\n", id16, get_part_name(id16), offset, size32);
if (id16 == 0x04) { // FILE_CONTAINER
unsigned char *zbuf = malloc(size32);
if (zbuf && fread(zbuf, 1, size32, fp) == size32) {
size_t decomp_len = 0;
unsigned char *decomp = zlib_decompress(zbuf, size32, &decomp_len);
if (decomp) {
printf(" -> Decompressed FILE_CONTAINER: %zu bytes\n", decomp_len);
unsigned char *p = decomp;
unsigned char *end = decomp + decomp_len;
int item_idx = 0;
while (p + 30 <= end) {
uint32_t fmode = *(uint32_t *)(p + 0);
uint32_t fmtime = *(uint32_t *)(p + 8);
uint32_t fsize = *(uint32_t *)(p + 24);
uint16_t name_len = *(uint16_t *)(p + 28);
p += 30;
if (p + name_len > end) {
printf(" -> Header overrun: name_len=%u exceeds buffer\n", name_len);
break;
}
char fname[512] = {0};
if (name_len >= sizeof(fname)) name_len = sizeof(fname) - 1;
memcpy(fname, p, name_len);
fname[name_len] = '\0';
p += name_len;
if (p + fsize > end) {
printf(" -> Data overrun: '%s' size=%u exceeds buffer\n", fname, fsize);
break;
}
char full_path[1024];
snprintf(full_path, sizeof(full_path), "%s/%s", out_dir, fname);
char dir_path[1024];
snprintf(dir_path, sizeof(dir_path), "%s", full_path);
char *slash = strrchr(dir_path, '/');
if (slash) { *slash = '\0'; mkdir_p(dir_path); }
if (S_ISDIR(fmode)) {
mkdir_p(full_path);
printf(" -> [%d] [DIR] %s/\n", ++item_idx, fname);
} else if (S_ISLNK(fmode)) {
char target[1024] = {0};
size_t tlen = fsize < sizeof(target) ? fsize : sizeof(target) - 1;
memcpy(target, p, tlen);
unlink(full_path);
symlink(target, full_path);
printf(" -> [%d] [LINK] %s -> %s\n", ++item_idx, fname, target);
total_extracted++;
} else {
FILE *out = fopen(full_path, "wb");
if (out) {
fwrite(p, 1, fsize, out);
fclose(out);
chmod(full_path, fmode ? (fmode & 07777) : 0644);
if (fmtime) {
struct utimbuf ut;
ut.actime = fmtime;
ut.modtime = fmtime;
utime(full_path, &ut);
}
printf(" -> [%d] [FILE] %s (%u bytes, mode=%04o)\n", ++item_idx, fname, fsize, fmode & 07777);
total_extracted++;
} else {
fprintf(stderr, "Warning: Failed to create file '%s'\n", full_path);
}
}
p += fsize;
}
free(decomp);
} else {
printf(" -> ZLIB decompression failed for FILE_CONTAINER\n");
}
}
if (zbuf) free(zbuf);
} else if (id16 == 0x15) {
char sq_file[1024];
snprintf(sq_file, sizeof(sq_file), "%s/image.squashfs", out_dir);
FILE *out = fopen(sq_file, "wb");
if (out) {
unsigned char buf[65536];
uint32_t remaining = size32;
while (remaining > 0) {
size_t to_read = remaining > sizeof(buf) ? sizeof(buf) : remaining;
size_t n = fread(buf, 1, to_read, fp);
if (n == 0) break;
fwrite(buf, 1, n, out);
remaining -= n;
}
fclose(out);
printf(" -> Extracted SQUASHFS image: %s (%u bytes)\n", sq_file, size32);
total_extracted++;
}
}
offset += 6 + size32;
continue;
}
offset++;
}
fclose(fp);
printf("\nExtraction complete: %d item(s) extracted from NPK to '%s'.\n", total_extracted, out_dir);
return 0;
}

View File

@@ -340,6 +340,7 @@ def patch_squashfs(path,key_dict):
os.environ.get('MIKRO_LICENCE_URL', '').encode(): os.environ.get('CUSTOM_LICENCE_URL', '').encode(),
os.environ.get('MIKRO_UPGRADE_URL', '').encode(): os.environ.get('CUSTOM_UPGRADE_URL', '').encode(),
os.environ.get('MIKRO_CLOUD_URL', '').encode(): os.environ.get('CUSTOM_CLOUD_URL', '').encode(),
os.environ.get('MIKRO_CLOUD2_URL', '').encode(): os.environ.get('CUSTOM_CLOUD2_URL', '').encode(),
os.environ.get('MIKRO_CLOUD_PUBLIC_KEY', '').encode(): os.environ.get('CUSTOM_CLOUD_PUBLIC_KEY', '').encode(),
}
url_replacements = {k: v for k, v in url_replacements.items() if k and v}
@@ -357,12 +358,10 @@ def patch_squashfs(path,key_dict):
if old_url in data:
print(f'{file_path} url patched {old_url.decode()[:7]}...')
data = data.replace(old_url,new_url)
modified = False
for old_public_key,new_public_key in key_dict.items():
new_data = replace_key(old_public_key,new_public_key,data,file_path)
if new_data != data:
data = new_data
modified = True
with open(f'{file_path}_', 'wb') as f:
f.write(data)
if 'loader' in files and os.path.isfile(os.path.join(root, 'loader')):

1169
setup-routeros.sh Normal file

File diff suppressed because it is too large Load Diff