forked from azadrahorg/Install-MikroTik-CHR-on-VPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmik-6.sh
55 lines (43 loc) · 1.46 KB
/
mik-6.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash -e
export PATH=$PATH:/usr/bin:/bin
echo
echo "=== hwhost.fr ==="
echo "=== MikroTik Installer ==="
echo
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get -y install gzip
# Construct the download URL for the latest version
download_url="https://download.mikrotik.com/routeros/6.49.17/chr-6.49.17.img.zip"
# Download and extract the image file
wget "$download_url" -O chr.img.zip
gunzip -c chr.img.zip > chr.img && \
kpartx -av chr.img
mount /dev/mapper/loop3p2 /mnt/ && \
# Find the primary network interface with an IP address
interface=$(ip -o -4 addr show up primary scope global | awk '{print $2}' | head -n 1)
# Retrieve network information
ADDRESS=$(ip addr show $interface | grep global | cut -d' ' -f 6 | head -n 1)
GATEWAY=$(ip route list | grep default | cut -d' ' -f 3)
HOSTNAME=$(hostname)
# Create autorun script
echo "/ip address add address=$ADDRESS interface=[/interface ethernet find where name=ether1]
/ip route add gateway=$GATEWAY
/ip service disable telnet
/system identity set name=$HOSTNAME
/user set 0 name=root password=123456789
" > /mnt/rw/autorun.scr && \
# Unmount and clean up
sudo umount /mnt/ && \
# Sync and write image to disk
echo u > /proc/sysrq-trigger && \
sudo dd if=chr.img bs=1024 of=/dev/sda && \
echo "sync disk" && \
echo s > /proc/sysrq-trigger && \
echo "Waiting 5 seconds..." && \
#Waiting
end_time=$((SECONDS + 5))
while [ $SECONDS -lt $end_time ]; do
:
done && \
echo "Reboot OS" && \
echo b > /proc/sysrq-trigger