mirror of
https://github.com/elseif/MikroTikPatch
synced 2026-07-17 10:39:40 +00:00
Compare commits
6 Commits
5bfb3ce1d0
...
22fefaf3f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22fefaf3f4 | ||
|
|
dc5e2e0ac8 | ||
|
|
1f552fcd84 | ||
|
|
73c149696f | ||
|
|
8955a366fb | ||
|
|
eb5926ac6f |
10
.github/workflows/main.yml
vendored
10
.github/workflows/main.yml
vendored
@ -7,35 +7,35 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Patch_Stable:
|
Patch_Stable:
|
||||||
uses: ./.github/workflows/build_v7.yml
|
uses: ./.github/workflows/patch_v7.yml
|
||||||
with:
|
with:
|
||||||
channel: stable
|
channel: stable
|
||||||
release: true
|
release: true
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
Patch_LongTerm:
|
Patch_LongTerm:
|
||||||
uses: ./.github/workflows/build_v7.yml
|
uses: ./.github/workflows/patch_v7.yml
|
||||||
with:
|
with:
|
||||||
channel: long-term
|
channel: long-term
|
||||||
release: true
|
release: true
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
Patch_Testing:
|
Patch_Testing:
|
||||||
uses: ./.github/workflows/build_v7.yml
|
uses: ./.github/workflows/patch_v7.yml
|
||||||
with:
|
with:
|
||||||
channel: testing
|
channel: testing
|
||||||
release: true
|
release: true
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
Patch_Stable_V6:
|
Patch_Stable_V6:
|
||||||
uses: ./.github/workflows/build_v6.yml
|
uses: ./.github/workflows/patch_v6.yml
|
||||||
with:
|
with:
|
||||||
channel: stable
|
channel: stable
|
||||||
release: true
|
release: true
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
Patch_LongTerm_V6:
|
Patch_LongTerm_V6:
|
||||||
uses: ./.github/workflows/build_v6.yml
|
uses: ./.github/workflows/patch_v6.yml
|
||||||
with:
|
with:
|
||||||
channel: long-term
|
channel: long-term
|
||||||
release: true
|
release: true
|
||||||
|
|||||||
12
.github/workflows/patch_v6.yml
vendored
12
.github/workflows/patch_v6.yml
vendored
@ -108,7 +108,7 @@ jobs:
|
|||||||
echo "Version: $VERSION, Archs: $ARCHS"
|
echo "Version: $VERSION, Archs: $ARCHS"
|
||||||
|
|
||||||
|
|
||||||
Build_RouterOS:
|
Patch_RouterOS:
|
||||||
needs: Prepare_Patch
|
needs: Prepare_Patch
|
||||||
if: needs.Prepare_Patch.outputs.SKIP_BUILD == 'false'
|
if: needs.Prepare_Patch.outputs.SKIP_BUILD == 'false'
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
@ -530,10 +530,10 @@ jobs:
|
|||||||
|
|
||||||
|
|
||||||
Update_Release:
|
Update_Release:
|
||||||
needs: [Prepare_Patch,Build_RouterOS]
|
needs: [Prepare_Patch,Patch_RouterOS]
|
||||||
if: |
|
if: |
|
||||||
needs.Prepare_Patch.outputs.SKIP_BUILD == 'false' &&
|
needs.Prepare_Patch.outputs.SKIP_BUILD == 'false' &&
|
||||||
needs.Build_RouterOS.result == 'success' &&
|
needs.Patch_RouterOS.result == 'success' &&
|
||||||
needs.Prepare_Patch.outputs.RELEASE == 'true'
|
needs.Prepare_Patch.outputs.RELEASE == 'true'
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
env:
|
env:
|
||||||
@ -562,7 +562,7 @@ jobs:
|
|||||||
PASS=${{ secrets.SSH_PASSWORD }}
|
PASS=${{ secrets.SSH_PASSWORD }}
|
||||||
PORT=${{ secrets.SSH_PORT }}
|
PORT=${{ secrets.SSH_PORT }}
|
||||||
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no -p $PORT $USER@$SERVER \
|
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/NEWEST6.$CHANNEL; \
|
||||||
ln -sf /root/$REMOTE_PATH/$VERSION/info /rw/disk/$REMOTE_PATH/NEWESTa6.$CHANNEL; \
|
ln -sf /root/$REMOTE_PATH/$VERSION/info /rw/disk/$REMOTE_PATH/NEWESTa6.$CHANNEL; \
|
||||||
chown -R 32768:32768 /rw/disk/$REMOTE_PATH/"
|
chown -R 32768:32768 /rw/disk/$REMOTE_PATH"
|
||||||
echo "✅ Updated release info."
|
echo "✅ Updated release info."
|
||||||
|
|||||||
13
.github/workflows/patch_v7.yml
vendored
13
.github/workflows/patch_v7.yml
vendored
@ -127,7 +127,7 @@ jobs:
|
|||||||
echo "RELEASE=$RELEASE" >> $GITHUB_OUTPUT
|
echo "RELEASE=$RELEASE" >> $GITHUB_OUTPUT
|
||||||
echo "Version: $VERSION, Archs: $ARCHS"
|
echo "Version: $VERSION, Archs: $ARCHS"
|
||||||
|
|
||||||
Build_RouterOS:
|
Patch_RouterOS:
|
||||||
needs: Prepare_Patch
|
needs: Prepare_Patch
|
||||||
if: needs.Prepare_Patch.outputs.SKIP_BUILD == 'false'
|
if: needs.Prepare_Patch.outputs.SKIP_BUILD == 'false'
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
@ -938,10 +938,10 @@ jobs:
|
|||||||
--data '{"purge_everything": true}'
|
--data '{"purge_everything": true}'
|
||||||
|
|
||||||
Update_Release:
|
Update_Release:
|
||||||
needs: [Prepare_Patch,Build_RouterOS]
|
needs: [Prepare_Patch,Patch_RouterOS]
|
||||||
if: |
|
if: |
|
||||||
needs.Prepare_Patch.outputs.SKIP_BUILD == 'false' &&
|
needs.Prepare_Patch.outputs.SKIP_BUILD == 'false' &&
|
||||||
needs.Build_RouterOS.result == 'success' &&
|
needs.Patch_RouterOS.result == 'success' &&
|
||||||
needs.Prepare_Patch.outputs.RELEASE == 'true'
|
needs.Prepare_Patch.outputs.RELEASE == 'true'
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
env:
|
env:
|
||||||
@ -970,7 +970,8 @@ jobs:
|
|||||||
PASS=${{ secrets.SSH_PASSWORD }}
|
PASS=${{ secrets.SSH_PASSWORD }}
|
||||||
PORT=${{ secrets.SSH_PORT }}
|
PORT=${{ secrets.SSH_PORT }}
|
||||||
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no -p $PORT $USER@$SERVER \
|
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no -p $PORT $USER@$SERVER \
|
||||||
"bash /rw/disk/$REMOTE_PATH/packages.sh /rw/disk/$REMOTE_PATH/$VERSION; \
|
"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; \
|
ln -sf /root/$REMOTE_PATH/$VERSION/info /rw/disk/$REMOTE_PATH/NEWESTa7.$CHANNEL; \
|
||||||
chown -R 32768:32768 /rw/disk/$REMOTE_PATH/"
|
chown -R 32768:32768 /rw/disk/$REMOTE_PATH"
|
||||||
|
|
||||||
echo "✅ Updated: packages.csv"
|
echo "✅ Updated: packages.csv"
|
||||||
|
|||||||
40
patch.py
40
patch.py
@ -106,40 +106,6 @@ def patch_bzimage(data:bytes,key_dict:dict):
|
|||||||
new_data = new_data.replace(vmlinux_xz,new_vmlinux_xz)
|
new_data = new_data.replace(vmlinux_xz,new_vmlinux_xz)
|
||||||
return new_data
|
return new_data
|
||||||
|
|
||||||
def patch_block(dev:str,file:str,key_dict):
|
|
||||||
BLOCK_SIZE = 4096
|
|
||||||
#sudo debugfs /dev/nbd0p1 -R 'stats' | grep "Block size" | sed -n '1p' | cut -d ':' -f 2
|
|
||||||
|
|
||||||
#sudo debugfs /dev/nbd0p1 -R 'stat boot/initrd.rgz' 2> /dev/null | sed -n '11p'
|
|
||||||
stdout,_ = run_shell_command(f"debugfs {dev} -R 'stat {file}' 2> /dev/null | sed -n '11p' ")
|
|
||||||
#(0-11):1592-1603, (IND):1173, (12-15):1604-1607, (16-26):1424-1434
|
|
||||||
blocks_info = stdout.decode().strip().split(',')
|
|
||||||
print(f'blocks_info : {blocks_info}')
|
|
||||||
blocks = []
|
|
||||||
ind_block_id = None
|
|
||||||
for block_info in blocks_info:
|
|
||||||
_tmp = block_info.strip().split(':')
|
|
||||||
if _tmp[0].strip() == '(IND)':
|
|
||||||
ind_block_id = int(_tmp[1])
|
|
||||||
else:
|
|
||||||
print(f'block_info : {block_info}')
|
|
||||||
id_range = _tmp[0].strip().replace('(','').replace(')','').split('-')
|
|
||||||
block_range = _tmp[1].strip().replace('(','').replace(')','').split('-')
|
|
||||||
blocks += [id for id in range(int(block_range[0]),int(block_range[1])+1)]
|
|
||||||
print(f' blocks : {len(blocks)} ind_block_id : {ind_block_id}')
|
|
||||||
|
|
||||||
#sudo debugfs /dev/nbd0p1 -R 'cat boot/initrd.rgz' > data
|
|
||||||
data,stderr = run_shell_command(f"debugfs {dev} -R 'cat {file}' 2> /dev/null")
|
|
||||||
new_data = patch_kernel(data,key_dict)
|
|
||||||
print(f'write block {len(blocks)} : [',end="")
|
|
||||||
with open(dev,'wb') as f:
|
|
||||||
for index,block_id in enumerate(blocks):
|
|
||||||
print('#',end="")
|
|
||||||
f.seek(block_id*BLOCK_SIZE)
|
|
||||||
f.write(new_data[index*BLOCK_SIZE:(index+1)*BLOCK_SIZE])
|
|
||||||
f.flush()
|
|
||||||
print(']')
|
|
||||||
|
|
||||||
def patch_initrd_xz(initrd_xz:bytes,key_dict:dict,ljust=True):
|
def patch_initrd_xz(initrd_xz:bytes,key_dict:dict,ljust=True):
|
||||||
try:
|
try:
|
||||||
initrd = lzma.decompress(initrd_xz)
|
initrd = lzma.decompress(initrd_xz)
|
||||||
@ -495,9 +461,6 @@ if __name__ == '__main__':
|
|||||||
kernel_parser = subparsers.add_parser('kernel',help='patch kernel file')
|
kernel_parser = subparsers.add_parser('kernel',help='patch kernel file')
|
||||||
kernel_parser.add_argument('input',type=str, help='Input file')
|
kernel_parser.add_argument('input',type=str, help='Input file')
|
||||||
kernel_parser.add_argument('-O','--output',type=str,help='Output file')
|
kernel_parser.add_argument('-O','--output',type=str,help='Output file')
|
||||||
block_parser = subparsers.add_parser('block',help='patch block file')
|
|
||||||
block_parser.add_argument('dev',type=str, help='block device')
|
|
||||||
block_parser.add_argument('file',type=str, help='file path')
|
|
||||||
buildefi_parser = subparsers.add_parser('buildefi',help='build efi file')
|
buildefi_parser = subparsers.add_parser('buildefi',help='build efi file')
|
||||||
buildefi_parser.add_argument('input',type=str, help='kernel file')
|
buildefi_parser.add_argument('input',type=str, help='kernel file')
|
||||||
buildefi_parser.add_argument('output',type=str,help='Output to file')
|
buildefi_parser.add_argument('output',type=str,help='Output to file')
|
||||||
@ -518,9 +481,6 @@ if __name__ == '__main__':
|
|||||||
print(f'patching {args.input} ...')
|
print(f'patching {args.input} ...')
|
||||||
data = patch_kernel(open(args.input,'rb').read(),key_dict)
|
data = patch_kernel(open(args.input,'rb').read(),key_dict)
|
||||||
open(args.output or args.input,'wb').write(data)
|
open(args.output or args.input,'wb').write(data)
|
||||||
elif args.command == 'block':
|
|
||||||
print(f'patching {args.file} in {args.dev} ...')
|
|
||||||
patch_block(args.dev,args.file,key_dict)
|
|
||||||
elif args.command == 'buildefi':
|
elif args.command == 'buildefi':
|
||||||
print(f'building EFI from {args.input} ...')
|
print(f'building EFI from {args.input} ...')
|
||||||
build_efi(args.input,args.output)
|
build_efi(args.input,args.output)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user