# 🧩 Cloud Install

# Debian

cat /etc/debian_version
mkdir /boot/ub && cd /boot/ub

wget https://mirrors.aliyun.com/debian/dists/buster/main/installer-amd64/current/images/netboot/debian-installer/amd64/linux
wget https://mirrors.aliyun.com/debian/dists/buster/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz

# Reboot and access grub in vnc
# Type "c" to attach grub shell

root=(hd0,1)
linux /boot/ub/linux
initrd /boot/ub/initrd.gz
boot

# Start Install

# RouterOS

VERSION=6.45.9
INTERFACE=ens5
ADDRESS=`ip addr show ${INTERFACE} | grep global | cut -d' ' -f 6 | head -n 1`
GATEWAY=`ip route list | grep default | cut -d' ' -f 3`
PASSWORD=password
DISK_NAME=/dev/vda

echo "${ADDRESS} - ${GATEWAY}"

wget "https://download.mikrotik.com/routeros/${VERSION}/chr-${VERSION}.img.zip" -O /tmp/chr.img.zip

gunzip -c /tmp/chr.img.zip > /tmp/chr.img

mount -o loop,offset=512 /tmp/chr.img /mnt

tee /mnt/rw/autorun.scr >/dev/null <<END
/ip address add address=$ADDRESS interface=[/interface ethernet find where name=ether1]
/ip route add gateway=$GATEWAY
/ip service disable telnet
/user set 0 name=root password=$PASSWORD
END

umount /mnt

echo u > /proc/sysrq-trigger
dd if=/tmp/chr.img bs=1024 of=$DISK_NAME
echo "sync disk"
echo s > /proc/sysrq-trigger
echo "Sleep 5 seconds"
sleep 5
echo "Ok, reboot"
echo b > /proc/sysrq-trigger