Skip to content

Instantly share code, notes, and snippets.

@cjamcu
Last active June 1, 2025 01:00
Show Gist options
  • Save cjamcu/c956eb86331e6800b9d8b718d768fabb to your computer and use it in GitHub Desktop.
Save cjamcu/c956eb86331e6800b9d8b718d768fabb to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to install RouterOS without VNC requirement
# WARNING: This script will COMPLETELY REMOVE Ubuntu
set -e
echo "=== RouterOS Automated Installation Script ==="
echo "⚠️ WARNING: This will completely replace Ubuntu!"
echo "Press Ctrl+C now to cancel or any key to continue..."
read -n 1 -s
# Install required tools
echo "πŸ“¦ Installing required tools..."
apt update -qq
apt install -y unzip wget
# Get current system information
MAIN_INTERFACE=$(ip route | grep default | awk '{print $5}' | head -n1)
CURRENT_IP=$(ip addr show $MAIN_INTERFACE | grep 'inet ' | awk '{print $2}' | head -n1)
GATEWAY=$(ip route | grep default | awk '{print $3}' | head -n1)
MAIN_DISK=$(lsblk -dn -o NAME | head -n1)
echo "Detected configuration:"
echo "- Interface: $MAIN_INTERFACE"
echo "- Current IP: $CURRENT_IP"
echo "- Gateway: $GATEWAY"
echo "- Main disk: /dev/$MAIN_DISK"
# Validate that we have the necessary information
if [ -z "$CURRENT_IP" ] || [ -z "$GATEWAY" ] || [ -z "$MAIN_DISK" ]; then
echo "❌ Error: Could not detect network configuration"
exit 1
fi
# Download RouterOS
echo "πŸ“₯ Downloading RouterOS..."
cd /tmp
wget -q https://download.mikrotik.com/routeros/7.16/chr-7.16.img.zip -O chr.img.zip
# Extract image
echo "πŸ“¦ Extracting RouterOS image..."
unzip -q chr.img.zip
# Final message before installation
echo "🚨 LAST WARNING: Ubuntu will be completely replaced!"
echo "Network config: $CURRENT_IP via $GATEWAY"
echo "πŸ’Ύ Writing RouterOS to disk..."
# Write image to disk
dd if=/tmp/chr-7.16.img of=/dev/$MAIN_DISK bs=1M status=progress
# Sync disk
echo "πŸ”„ Syncing disk..."
sync
echo "βœ… RouterOS installation completed!"
echo "πŸ“‹ Access information:"
echo " IP: ${CURRENT_IP%/*}"
echo " Default user: admin (no password)"
echo " SSH: ssh admin@${CURRENT_IP%/*}"
echo ""
echo "πŸ”„ Rebooting now..."
# Restart system
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment