#!/bin/sh# =============================================================# ZeroTier installer per UDM-Pro / UCG (Unifi)# Uso: curl -fsSL https://iotashare.myftp.org/Software/Utilities/zerotier-unifi.sh | bash# =============================================================ZEROTIER_DEB_URL="https://download.zerotier.com/dist/debian/bullseye/zerotier-one_1.16.0-2_arm64.deb"INSTALL_DIR="/config/data/firstboot/install-packages"DEB_PATH="$INSTALL_DIR/zerotier-one_arm64.deb"# --- Chiedi il Network ID ---if [ -z "$1" ]; then    printf "Inserisci il ZeroTier Network ID: "    read NETWORK_IDelse    NETWORK_ID="$1"fiif [ -z "$NETWORK_ID" ]; then    echo "[ERRORE] Network ID non specificato. Uscita."    exit 1fi# --- 1. Crea directory e scarica il .deb direttamente da ZeroTier ---echo "[*] Download pacchetto ZeroTier..."mkdir -p "$INSTALL_DIR"curl -fsSL "$ZEROTIER_DEB_URL" --output "$DEB_PATH"if [ $? -ne 0 ]; then    echo "[ERRORE] Download fallito. Controlla la connessione."    exit 1fi# --- 2. Installa ---echo "[*] Installazione ZeroTier..."dpkg -i "$DEB_PATH"if [ $? -ne 0 ]; then    echo "[ERRORE] Installazione dpkg fallita."    exit 1fi# --- 3. Avvia il servizio ---echo "[*] Avvio zerotier-one.service..."systemctl start zerotier-one.servicesleep 2systemctl status zerotier-one.service --no-pager# --- 4. Join alla rete ---echo "[*] Join alla rete $NETWORK_ID..."zerotier-cli join "$NETWORK_ID"# --- 5. Script di reinstallazione al boot ---echo "[*] Creazione script di boot..."cat > "$INSTALL_DIR/install.sh" << BOOTSCRIPT#!/bin/shif ! command -v zerotier-cli >/dev/null 2>&1; then    dpkg -i $DEB_PATHfiif ! systemctl is-active --quiet zerotier-one.service; then    systemctl start zerotier-one.servicefiBOOTSCRIPTchmod +x "$INSTALL_DIR/install.sh"# --- 6. Servizio systemd per sopravvivere ai reboot ---echo "[*] Configurazione servizio systemd..."tee /etc/systemd/system/zerotier-reinstall.service > /dev/null << 'EOF'[Unit]Description=Install and start ZeroTier if not presentAfter=network.target[Service]Type=oneshotExecStart=/config/data/firstboot/install-packages/install.shRemainAfterExit=true[Install]WantedBy=multi-user.targetEOFsystemctl daemon-reloadsystemctl enable zerotier-reinstall.service# --- 7. Riepilogo finale ---echo ""echo "============================================="echo "[OK] Installazione ZeroTier completata!"echo "[!] Vai su https://my.zerotier.com e autorizza"echo "    il nodo nella rete $NETWORK_ID"echo "============================================="echo ""zerotier-cli listnetworks