ros-install

From nat, 5 Years ago, written in Bash, viewed 298 times.
URL https://code.nat.moe/view/ad60ec19 Embed
Download Paste or View Raw
  1. wget http://download2.mikrotik.com/routeros/6.36.4/chr-6.36.4.img.zip -O chr.img.zip  && \
  2. gunzip -c chr.img.zip > chr.img  && \
  3. apt-get update && \
  4. apt install -y qemu-utils pv && \
  5. qemu-img convert chr.img -O qcow2 chr.qcow2 && \
  6. qemu-img resize chr.qcow2 `fdisk /dev/vda -l | head -n 1 | cut -d',' -f 2 | cut -d' ' -f 2` && \
  7. modprobe nbd && \
  8. qemu-nbd -c /dev/nbd0 chr.qcow2 && \
  9. echo "Give some time for qemu-nbd to be ready" && \
  10. sleep 2 && \
  11. mount /dev/nbd0p2 /mnt && \
  12. ADDRESS=`ip addr show eth0 | grep global | cut -d' ' -f 6 | head -n 1` && \
  13. GATEWAY=`ip route list | grep default | cut -d' ' -f 3` && \
  14. echo "/ip address add address=$ADDRESS interface=[/interface ethernet find where name=ether1]
  15. /ip route add gateway=$GATEWAY
  16. /ip service disable telnet
  17. /user set 0 name=root password=xxxxxx
  18. " > /mnt/rw/autorun.scr && \
  19. umount /mnt && \
  20. echo "Magic constant is 65537 (second partition address). You can check it with fdisk before appliyng this" && \
  21. echo "This scary sequence removes seconds partition on nbd0 and creates new, but bigger one" && \
  22. echo -e 'd\n2\nn\np\n2\n65537\n\nw\n' | fdisk /dev/nbd0 && \
  23. e2fsck -f -y /dev/nbd0p2 || true && \
  24. resize2fs /dev/nbd0p2 && \
  25. sleep 1 && \
  26. echo "Compressing to gzip, this can take several minutes" && \
  27. mount -t tmpfs tmpfs /mnt && \
  28. pv /dev/nbd0 | gzip > /mnt/chr-extended.gz && \
  29. sleep 1 && \
  30. killall qemu-nbd && \
  31. sleep 1 && \
  32. echo u > /proc/sysrq-trigger && \
  33. echo "Warming up sleep" && \
  34. sleep 1 && \
  35. echo "Writing raw image, this will take time" && \
  36. zcat /mnt/chr-extended.gz | pv > /dev/vda && \
  37. echo "Sleep 5 seconds (if lucky)" && \
  38. sleep 5 || true && \
  39. echo "sync disk" && \
  40. echo s > /proc/sysrq-trigger && \
  41. echo "Ok, reboot" && \
  42. echo b > /proc/sysrq-trigger

Reply to "ros-install"

Here you can reply to the paste above

captcha