From cd884403614b4f8c666070d0391ec92c2e9ec1ad Mon Sep 17 00:00:00 2001 From: lyn Date: Sun, 12 Apr 2026 14:59:09 +0000 Subject: [PATCH] Add onboard script for agent onboarding workflow --- scripts/onboard | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 scripts/onboard diff --git a/scripts/onboard b/scripts/onboard new file mode 100755 index 0000000..dd0100f --- /dev/null +++ b/scripts/onboard @@ -0,0 +1,82 @@ +#!/bin/bash +set -e + +NAME="" +ROLE="" +POSITION="" +GENDER="" +BOT_TOKEN="" + +usage() { + echo "Usage: onboard --name --role --position --gender --bot-token " + exit 1 +} + +while [[ $# -gt 0 ]]; do + case $1 in + --name) + NAME="$2" + shift 2 + ;; + --role) + ROLE="$2" + shift 2 + ;; + --position) + POSITION="$2" + shift 2 + ;; + --gender) + GENDER="$2" + shift 2 + ;; + --bot-token) + BOT_TOKEN="$2" + shift 2 + ;; + *) + usage + ;; + esac +done + +if [[ -z "$NAME" ]] || [[ -z "$ROLE" ]] || [[ -z "$POSITION" ]] || [[ -z "$GENDER" ]] || [[ -z "$BOT_TOKEN" ]]; then + usage +fi + +if [[ "$PCEXEC_PROXIED" != "true" ]]; then + echo "Error: this script must be executed with tool proxy-pcexec" >&2 + exit 1 +fi + +SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)" +TODAY=$(date +%Y-%m-%d) + +# Resolve discord-id from bot token +DISCORD_ID=$(curl -s "https://discord.com/api/v10/users/@me" \ + -H "Authorization: Bot $BOT_TOKEN" \ + -H "Content-Type: application/json" | \ + python3 -c "import sys,json; print(json.load(sys.stdin).get('id', ''))" 2>/dev/null) + +if [[ -z "$DISCORD_ID" ]]; then + echo "Error: failed to resolve discord-id from bot token" >&2 + exit 1 +fi + +AGENT_ID="agent-$NAME" + +ego-mgr set name "$NAME" +ego-mgr set default-username "$NAME" +ego-mgr set discord-id "$DISCORD_ID" +ego-mgr set role "$ROLE" +ego-mgr set position "$POSITION" +ego-mgr set gender "$GENDER" +ego-mgr set email "${NAME}@${ROLE}.hangman-lab.top" +ego-mgr set agent-id "$AGENT_ID" +ego-mgr set date-of-birth "$TODAY" + +"$SCRIPT_PATH/../../keycloak-hangman-lab/scripts/create-keycloak-account" +"$SCRIPT_PATH/../../git-hangman-lab/scripts/create-git-account" +"$SCRIPT_PATH/../../git-hangman-lab/scripts/link-keycloak" + +echo "Onboarding complete for $NAME."