#!/bin/sh set -e # Tunl node installer # Usage: curl -fsSL https://tunl.gg | sudo sh -s -- --server URL --key KEY BASE_URL="https://tunl.gg" INSTALL_DIR="/usr/local/bin" SERVER="" KEY="" HOSTNAME="" while [ $# -gt 0 ]; do case "$1" in --server) SERVER="$2"; shift 2 ;; --key) KEY="$2"; shift 2 ;; --hostname) HOSTNAME="$2"; shift 2 ;; *) echo "Unknown option: $1"; exit 1 ;; esac done OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) case "$ARCH" in x86_64|amd64) ARCH="amd64" ;; arm64|aarch64) ARCH="arm64" ;; *) echo "Unsupported: $ARCH"; exit 1 ;; esac PLATFORM="${OS}-${ARCH}" echo "" echo " Tunl Node — ${PLATFORM}" echo "" if [ "$(id -u)" -ne 0 ]; then echo "Re-run with sudo:" echo " curl -fsSL https://tunl.gg | sudo sh -s -- --server URL --key KEY" exit 1 fi # Download binaries TMPDIR=$(mktemp -d) trap 'rm -rf "$TMPDIR"' EXIT for bin in tunl tunld; do printf " downloading %-10s" "${bin}..." curl -fsSL "${BASE_URL}/bin/${PLATFORM}/${bin}" -o "${TMPDIR}/${bin}" chmod +x "${TMPDIR}/${bin}" echo "done" done for bin in tunl tunld; do cp "${TMPDIR}/${bin}" "${INSTALL_DIR}/${bin}" done echo "" echo " installed to ${INSTALL_DIR}" # State directory mkdir -p /root/.tunl 2>/dev/null || mkdir -p "${HOME}/.tunl" chmod 700 /root/.tunl 2>/dev/null || chmod 700 "${HOME}/.tunl" # Install service case "$OS" in darwin) cat > /Library/LaunchDaemons/com.tunl.tunld.plist << 'PLIST' Label com.tunl.tunld ProgramArguments /usr/local/bin/tunld RunAtLoad KeepAlive SuccessfulExit StandardOutPath /tmp/tunl.log StandardErrorPath /tmp/tunl.err PLIST ;; linux) cat > /etc/systemd/system/tunld.service << 'UNIT' [Unit] Description=Tunl Daemon After=network-online.target Wants=network-online.target [Service] Type=simple ExecStartPre=-/sbin/modprobe wireguard ExecStart=/usr/local/bin/tunld Restart=always RestartSec=5 AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE LimitNOFILE=65535 [Install] WantedBy=multi-user.target UNIT systemctl daemon-reload systemctl enable tunld >/dev/null 2>&1 ;; esac if [ -z "$SERVER" ] || [ -z "$KEY" ]; then echo "" echo " Binaries installed. To join a network:" echo " curl -fsSL https://tunl.gg | sudo sh -s -- --server URL --key KEY" exit 0 fi # Register and start echo "" echo " Registering..." HOSTNAME_FLAG="" [ -n "$HOSTNAME" ] && HOSTNAME_FLAG="--hostname $HOSTNAME" "${INSTALL_DIR}/tunl" login --server "$SERVER" --key "$KEY" $HOSTNAME_FLAG echo "" echo " Starting tunnel..." case "$OS" in darwin) launchctl load /Library/LaunchDaemons/com.tunl.tunld.plist 2>/dev/null || true ;; linux) systemctl start tunld ;; esac sleep 1 echo "" echo " Tunl is running!" echo "" echo " tunl status — connection info" echo " tunl peers — list peers" if [ "$OS" = "darwin" ]; then echo " tail -f /tmp/tunl.log — daemon logs" else echo " journalctl -u tunld -f — daemon logs" fi