#!/bin/bash # Install (or upgrade) the wxch agent and make it start at boot. Re-running upgrades the binary. . "$(dirname "$0")/lib.sh" TOKEN="${WXCH_TOKEN:-}" if [ -z "$TOKEN" ] && [ -s /etc/wxch-agent.env ]; then say "keeping the existing agent token" elif [ -z "$TOKEN" ]; then die "no agent token (WXCH_TOKEN). Create one on the server with: wxch-server -add-agent " fi # the agent user owns its folder so the agent can replace itself when updated from the web UI mkdir -p "$AGENT_DIR" say "downloading the agent ($ARCH)" fetch "$BASE/dl/wxch-agent-$ARCH" "$AGENT_DIR/wxch-agent.new" chmod 755 "$AGENT_DIR/wxch-agent.new" "$AGENT_DIR/wxch-agent.new" -version >/dev/null || { rm -f "$AGENT_DIR/wxch-agent.new"; die "the downloaded agent does not run on this machine"; } mv "$AGENT_DIR/wxch-agent.new" "$AGENT_BIN" chown -R "$OWNER" "$AGENT_DIR" fix_selinux "$AGENT_DIR" rm -f /usr/local/bin/wxch-agent # location used by very old installs SERVER_URL="$(echo "$BASE" | sed 's#^https#wss#; s#^http#ws#')/ws/agent" if [ -n "$TOKEN" ]; then ( umask 077; echo "WXCH_TOKEN=$TOKEN" > /etc/wxch-agent.env ) fi node_json_set server "$SERVER_URL" mkdir -p /etc/systemd/system cat > /etc/systemd/system/wxch-agent.service </dev/null 2>&1 systemctl restart wxch-agent i=0 until journalctl -u wxch-agent --since "-1min" --no-pager 2>/dev/null | grep -q "connected to"; do i=$((i+1)); [ "$i" -lt 30 ] || { warn "the agent started but has not connected to $SERVER_URL yet (check the token and the network: journalctl -u wxch-agent)"; exit 0; } sleep 1 done say "agent $("$AGENT_BIN" -version) is connected to $BASE"