Compare commits

...

14 Commits

Author SHA1 Message Date
elseif
e028fdd880 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 05:14:47 +08:00
elseif
88ff1f7130 Update chr.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 05:07:35 +08:00
elseif
92f26c270e Update chr.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 04:59:06 +08:00
elseif
c1163894f3 Update chr.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 04:45:03 +08:00
elseif
5196f20043 Update chr.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 04:43:38 +08:00
elseif
bba676a2d6 Rename chr_busybox.sh to chr.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 04:40:23 +08:00
elseif
259051906c Update chr_busybox.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 04:40:09 +08:00
elseif
2162e76e64 Update chr_busybox.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 04:19:30 +08:00
elseif
7c22877423 Update chr_busybox.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 04:14:22 +08:00
elseif
6a486adfc6 Update chr_busybox.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 04:11:51 +08:00
elseif
49608606f2 Update and rename chr.sh to chr_busybox.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 04:08:09 +08:00
elseif
85a2526bcd Update chr.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 03:58:06 +08:00
elseif
b5049c0ebb Update chr.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 03:56:41 +08:00
elseif
15273578e8 Update chr.sh
Signed-off-by: elseif <elseif@live.cn>
2025-08-23 03:31:43 +08:00
2 changed files with 58 additions and 17 deletions

View File

@@ -326,14 +326,14 @@ jobs:
sudo modprobe nbd
sudo apt-get install -y qemu-utils > /dev/null
truncate --size 128M chr-$LATEST_VERSION$ARCH.img
sgdisk --clear --set-alignment=8 \
sgdisk --clear --set-alignment=2 \
--new=1::+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" --attributes=1:set:2 \
--new=2::-0 --typecode=2:8300 --change-name=2:"RouterOS" \
--gpttombr=1:2 \
chr-$LATEST_VERSION$ARCH.img
dd if=chr-$LATEST_VERSION$ARCH.img of=pt.bin bs=1 count=66 skip=446
echo -e "\x80" | dd of=pt.bin bs=1 count=1 conv=notrunc
sgdisk --mbrtogpt --clear --set-alignment=8 \
sgdisk --mbrtogpt --clear --set-alignment=2 \
--new=1::+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" --attributes=1:set:2 \
--new=2::-0 --typecode=2:8300 --change-name=2:"RouterOS" \
chr-$LATEST_VERSION$ARCH.img

71
chr.sh
View File

@@ -1,15 +1,56 @@
curl -# -L https://github.com/elseif/MikroTikPatch/releases/download/7.19.3/chr-7.19.3-legacy-bios.img.zip -o /tmp/chr.img.zip && cd /tmp && \
gunzip -c chr.img.zip > chr.img && \
STORAGE=`lsblk | grep disk | cut -d ' ' -f 1 | head -n 1` && \
echo STORAGE is $STORAGE && \
ETH=`ip route show default | sed -n 's/.* dev \([^\ ]*\) .*/\1/p'` && \
echo ETH is $ETH && \
ADDRESS=`ip addr show $ETH | grep global | cut -d' ' -f 6 | head -n 1` && \
echo ADDRESS is $ADDRESS && \
GATEWAY=`ip route list | grep default | cut -d' ' -f 3` && \
echo GATEWAY is $GATEWAY && \
sleep 5 && \
dd if=chr.img of=/dev/$STORAGE bs=4M oflag=sync && \
echo "Ok, reboot" && \
echo 1 > /proc/sys/kernel/sysrq && \
echo b > /proc/sysrq-trigger
#!/bin/sh
set -e
if [ -d /sys/firmware/efi ]; then
echo "System boot mode: UEFI"
wget --no-check-certificate -O /tmp/chr.img.zip https://github.com/elseif/MikroTikPatch/releases/download/7.19.4/chr-7.19.4.img.zip
else
echo "System boot mode: BIOS/MBR"
wget --no-check-certificate -O /tmp/chr.img.zip https://github.com/elseif/MikroTikPatch/releases/download/7.19.4/chr-7.19.4-legacy-bios.img.zip
fi
cd /tmp
unzip -p chr.img.zip > chr.img
STORAGE=$(for d in /sys/block/*; do
case $(basename $d) in
loop*|ram*|sr*) continue ;;
*) echo $(basename $d); break ;;
esac
done)
echo "STORAGE is $STORAGE"
ETH=$(ip route show default | grep '^default' | sed -n 's/.* dev \([^\ ]*\) .*/\1/p')
echo "ETH is $ETH"
ADDRESS=$(ip addr show $ETH | grep global | cut -d' ' -f 6 | head -n 1)
echo "ADDRESS is $ADDRESS"
GATEWAY=$(ip route list | grep default | cut -d' ' -f 3)
echo "GATEWAY is $GATEWAY"
if LOOP=$(losetup -Pf --show chr.img 2>/dev/null); then
echo "LOOP device is $LOOP"
sleep 3
MNT=/tmp/chr
mkdir -p $MNT
if mount ${LOOP}p2 $MNT 2>/dev/null; then
cat <<EOF | tee $MNT/rw/autorun.scr
/ip address add address=$ADDRESS interface=ether1
/ip route add gateway=$GATEWAY
EOF
echo "autorun.scr file created."
umount $MNT
else
echo "Failed to mount partition 2, skipping autorun.scr creation."
fi
losetup -d $LOOP
fi
echo "WARNING: All data on /dev/$STORAGE will be lost!"
read -p "Do you want to continue? [Y/n]: " confirm
[ "$confirm" = "n" ] && echo "Operation aborted." && exit 1
dd if=chr.img of=/dev/$STORAGE bs=4M conv=fsync
echo "Ok, rebooting..."
echo 1 > /proc/sys/kernel/sysrq 2>/dev/null || true
echo b > /proc/sysrq-trigger 2>/dev/null || true
reboot -f