#!/bin/sh # Cloudverg agent installer. Read it before you run it; it is short on purpose. # # curl -fsSL https://api.cloudverg.com/install.sh | sudo sh -s -- --token vgm_... # # It installs the WireGuard tools, nftables and curl from your distribution's own packages, downloads the agent # (one shell script, checked against its published SHA-256) to /usr/local/sbin/verg-agent, and joins the network. set -eu API="https://api.cloudverg.com" BIN=/usr/local/sbin/verg-agent say() { printf 'verg: %s\n' "$*" >&2; } die() { say "$*"; exit 1; } has() { command -v "$1" >/dev/null 2>&1; } [ "$(id -u)" = 0 ] || die "run this as root: add sudo before sh" [ "$(uname -s)" = Linux ] || die "the agent runs on Linux. For other devices, add the node as set up by hand in the console." case " $* " in *" --token "*) ;; *) die "pass the token from the console: --token vgm_..." ;; esac need="" has wg || need="$need wireguard-tools" has nft || need="$need nftables" has curl || need="$need curl" has ip || need="$need iproute2" has bash || need="$need bash" has flock || need="$need util-linux" has ping || need="$need iputils-ping" if [ -n "$need" ]; then say "installing:$need" if has apt-get; then export DEBIAN_FRONTEND=noninteractive apt-get update -qq >/dev/null 2>&1 || true # shellcheck disable=SC2086 apt-get install -y -qq $need >/dev/null || die "apt could not install:$need" elif has dnf; then # shellcheck disable=SC2086 dnf install -y -q $(printf '%s' "$need" | sed 's/iproute2/iproute/; s/iputils-ping/iputils/') >/dev/null || die "dnf could not install:$need" elif has yum; then # shellcheck disable=SC2086 yum install -y -q $(printf '%s' "$need" | sed 's/iproute2/iproute/; s/iputils-ping/iputils/') >/dev/null || die "yum could not install:$need" elif has zypper; then # shellcheck disable=SC2086 zypper -n -q install $(printf '%s' "$need" | sed 's/iputils-ping/iputils/') >/dev/null || die "zypper could not install:$need" elif has apk; then # shellcheck disable=SC2086 apk add -q $(printf '%s' "$need" | sed 's/iputils-ping/iputils/') >/dev/null || die "apk could not install:$need" elif has pacman; then # shellcheck disable=SC2086 pacman -Sy --noconfirm --needed $(printf '%s' "$need" | sed 's/iputils-ping/iputils/') >/dev/null || die "pacman could not install:$need" else die "install these packages yourself, then run this again:$need" fi fi tmp="$(mktemp)" trap 'rm -f "$tmp" "$tmp.sum"' EXIT curl -fsSL --max-time 60 "$API/agent/verg-agent.sh" -o "$tmp" || die "could not download the agent from $API" curl -fsSL --max-time 30 "$API/agent/verg-agent.sh.sha256" -o "$tmp.sum" || die "could not download the agent's checksum" want="$(cut -d' ' -f1 "$tmp.sum")" if has sha256sum; then got="$(sha256sum "$tmp" | cut -d' ' -f1)"; else got="$(openssl dgst -sha256 "$tmp" | awk '{print $NF}')"; fi [ -n "$want" ] && [ "$want" = "$got" ] || die "the downloaded agent does not match its checksum; nothing was installed" install -m 0755 "$tmp" "$BIN" exec "$BIN" enroll "$@"