#!/bash/bash # --- 1. PRE-FLIGHT CHECK --- clear echo "==========================================================" echo " EVE-NG AUTOMATION & NODE INSTALLER" echo "==========================================================" echo "Welcome! This script will help you configure your EVE-NG." echo "Please prepare the following before proceeding:" echo "1. ZeroTier Network ID (for remote access)." echo "2. Google Drive File ID for the Node (ZIP/TAR.GZ)." echo " *Ensure the file is set to 'Anyone with the link can view'*" echo "----------------------------------------------------------" # Check KVM / Virtualization echo "Checking KVM/Virtualization status..." if [[ $(kvm-ok 2>&1) == *"CANNOT"* ]]; then echo -e "\n[!] WARNING: KVM/Virtualization is NOT ACTIVE!" echo "QEMU Nodes (Cisco, Mikrotik, etc.) will not be able to start." echo "Please enable VT-x/AMD-V in BIOS or VM settings." read -p "Continue anyway? [Y/n]: " run_anyway < /dev/tty [[ "$run_anyway" =~ ^[Nn]$ ]] && exit 1 else echo "STATUS: KVM/Virtualization is Active [OK]" fi echo "----------------------------------------------------------" read -p "Are you ready to start the process? [Y/n]: " proceed < /dev/tty [[ "$proceed" =~ ^[Nn]$ ]] && exit 1 # --- 2. SYSTEM UPDATE & INSTALL DEPENDENCIES --- echo -e "\n[1/5] Updating System & Installing Dependencies..." apt update -y apt install -y curl wget python3-pip openssh-server ufw unzip tar file # --- 3. FIREWALL SETUP (UFW) --- echo -e "\n[2/5] Configuring Firewall (UFW)..." ufw allow ssh ufw allow http ufw allow https echo "y" | ufw enable systemctl enable ufw systemctl start ufw echo "UFW is Active. SSH, HTTP, and HTTPS are allowed." # --- 4. ZEROTIER SETUP --- echo -e "\n[3/5] Installing & Connecting ZeroTier..." if ! command -v zerotier-cli &> /dev/null; then curl -s https://install.zerotier.com | bash fi join_zt() { read -p "Enter your ZeroTier Network ID: " ZT_ID < /dev/tty zerotier-cli join $ZT_ID } join_zt while true; do echo -e "\n----------------------------------------------------------" echo "Your ZeroTier Network Status:" # Show the actual table zerotier-cli listnetworks | grep -oE "OK|ONLINE|OFFLINE|REQUESTING_CONFIGURATION|ACCESS_DENIED|NOT_FOUND|PORT_ERROR" echo "----------------------------------------------------------" echo "Options:" echo "1. Check status (Ensure status is OK)" echo "2. Re-enter Network ID" echo "3. Skip / Manual Continue" read -p "Your choice [1-3]: " zt_choice < /dev/tty case $zt_choice in 1) # Get only the status string (OK, ACCESS_DENIED, etc.) STATUS=$(zerotier-cli listnetworks | grep "$ZT_ID" | awk '{print $6}') if [ "$STATUS" == "OK" ]; then echo -e "\n[V] Status is OK! Proceeding to the next step..." sleep 2 break else echo -e "\n[!] Current Status: $STATUS" echo "Please 'Authorize' this member in your ZeroTier Dashboard first." echo "Then select option 1 again to verify." fi ;; 2) join_zt ;; 3) break ;; *) echo "Invalid choice." ;; esac done # --- 5. DOWNLOAD & NODE INSTALLATION --- echo -e "\n[4/5] Preparing gdown & Downloading Node..." pip3 install gdown --upgrade read -p "Enter Google Drive File ID (e.g., 1unjq...): " GDrive_ID < /dev/tty echo "Downloading file to temporary directory..." gdown $GDrive_ID -O /tmp/node_archive # Detect file type FILE_TYPE=$(file --mime-type -b /tmp/node_archive) case $FILE_TYPE in application/zip) echo "ZIP file detected. Extracting directly to QEMU addons..." unzip -o /tmp/node_archive -d /opt/unetlab/addons/qemu/ ;; application/x-gzip | application/gzip | application/x-compressed-tar) echo "TAR.GZ file detected. Extracting directly to QEMU addons..." tar -xvf /tmp/node_archive -C /opt/unetlab/addons/qemu/ ;; *) echo "Not a compressed file. Assuming single image file (qcow2)..." read -p "Enter node folder name (e.g., mikrotik-7.1): " FOLDER_NAME < /dev/tty mkdir -p /opt/unetlab/addons/qemu/$FOLDER_NAME mv /tmp/node_archive /opt/unetlab/addons/qemu/$FOLDER_NAME/virtioa.qcow2 ;; esac # Fix Permissions echo -e "\n[5/5] Running Fix Permissions..." /opt/unetlab/wrappers/unl_wrapper -a fixpermissions # --- 6. SUMMARY --- IP_ZT=$(ip addr | grep 'inet ' | grep 'zt' | awk '{print $2}' | cut -d'/' -f1) if [ -z "$IP_ZT" ]; then IP_ZT="[NOT DETECTED / NOT AUTHORIZED]" fi clear echo "==========================================================" echo " INSTALLATION SUMMARY" echo "==========================================================" echo "1. SSH Access (via ZeroTier): ssh root@$IP_ZT" echo "2. ZeroTier Network Status : " zerotier-cli listnetworks | grep "$ZT_ID" echo "" echo " *REMEMBER: Install & Join ZeroTier on your LAPTOP too!*" echo "3. Node Status : Successfully added to EVE-NG." echo "----------------------------------------------------------" echo -e "**Now you can refresh your EVE-NG**" echo "==========================================================" # Cleanup rm -f /tmp/node_archive