-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchr_install
35 lines (33 loc) · 1.33 KB
/
chr_install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
#ADDRESS=xxx.xxx.xxx.xxx/24
ADDRESS=`ip addr show enp0s3 | grep global | cut -d' ' -f 6 | head -n 1`
#GATEWAY=xxx.xxx.xxx.1
GATEWAY=`ip route list | grep default | cut -d' ' -f 3`
# Raw disk image https://mikrotik.com/download#chr
#VERSIONCHR=7.10.2
VERSIONCHR=7.14.3
apt update
apt install -y pwgen coreutils unzip
wget -4 https://download.mikrotik.com/routeros/$VERSIONCHR/chr-$VERSIONCHR.img.zip -O chr.img.zip
gunzip -c chr.img.zip > chr.img
mount -o loop,offset=33571840 chr.img /mnt
PASSWORD=$(pwgen 12 1)
echo "Username: admin"
echo "Password: $PASSWORD"
echo "/ip address add address=$ADDRESS interface=[/interface ethernet find where name=ether1]" > /mnt/rw/autorun.scr
echo "/ip route add gateway=$GATEWAY" >> /mnt/rw/autorun.scr
echo "/ip service disable telnet" >> /mnt/rw/autorun.scr
echo "/user set 0 name=admin password=$PASSWORD" >> /mnt/rw/autorun.scr
echo "/ip dns set server=8.8.8.8,1.1.1.1" >> /mnt/rw/autorun.scr
# remount all mounted filesystems to read-only mode
echo u > /proc/sysrq-trigger
dd if=chr.img bs=1024 of=/dev/vda
echo "sync disk"
# synchronize all mounted filesystems
echo s > /proc/sysrq-trigger
echo "Sleep 10 seconds"
#/usr/bin/sleep 10
read -t 10 -u 1
echo "Ok, reboot"
# perform an immediate OS reboot similar to the RESET button (without synchronising and unmounting file systems)
echo b > /proc/sysrq-trigger