Add onboard script for agent onboarding workflow
This commit is contained in:
82
scripts/onboard
Executable file
82
scripts/onboard
Executable file
@@ -0,0 +1,82 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
NAME=""
|
||||||
|
ROLE=""
|
||||||
|
POSITION=""
|
||||||
|
GENDER=""
|
||||||
|
BOT_TOKEN=""
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: onboard --name <name> --role <role> --position <position> --gender <gender> --bot-token <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."
|
||||||
Reference in New Issue
Block a user