131 lines
3.9 KiB
Bash
Executable File
131 lines
3.9 KiB
Bash
Executable File
#!/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
|
|
|
|
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"
|
|
|
|
BINDINGS_LOCK="$HOME/.openclaw/states/bindings.lock"
|
|
STATE_DIR="$HOME/.openclaw/states"
|
|
|
|
# Wait for bindings.lock to disappear
|
|
while [[ -f "$BINDINGS_LOCK" ]]; do
|
|
echo "bindings locked, waiting..."
|
|
sleep 10
|
|
done
|
|
|
|
# Create bindings.lock and update bindings
|
|
mkdir -p "$STATE_DIR"
|
|
touch "$BINDINGS_LOCK"
|
|
|
|
CURRENT_BINDINGS=$(openclaw config get bindings 2>/dev/null || echo "[]")
|
|
|
|
# Replace accountId "interviewee" -> "{name}" for this agent
|
|
UPDATED_BINDINGS=$(echo "$CURRENT_BINDINGS" | python3 -c "
|
|
import sys, json
|
|
bindings = json.load(sys.stdin)
|
|
for b in bindings:
|
|
if b.get('agentId') == '$AGENT_ID' and b.get('match', {}).get('accountId') == 'interviewee':
|
|
b['match']['accountId'] = '$NAME'
|
|
print(json.dumps(bindings))
|
|
" 2>/dev/null)
|
|
|
|
openclaw config set bindings "$UPDATED_BINDINGS"
|
|
|
|
rm -f "$BINDINGS_LOCK"
|
|
|
|
# Configure discord account for {name}
|
|
openclaw config set channels.discord.accounts."$NAME".enabled true
|
|
openclaw config set channels.discord.accounts."$NAME".commands.native true
|
|
openclaw config set channels.discord.accounts."$NAME".commands.nativeSkills true
|
|
openclaw config set channels.discord.accounts."$NAME".token "$BOT_TOKEN"
|
|
openclaw config set channels.discord.accounts."$NAME".allowBots true
|
|
openclaw config set channels.discord.accounts."$NAME".groupPolicy "open"
|
|
openclaw config set channels.discord.accounts."$NAME".streaming.mode "off"
|
|
openclaw config set channels.discord.accounts."$NAME".actions.messages true
|
|
openclaw config set channels.discord.accounts."$NAME".actions.search true
|
|
openclaw config set channels.discord.accounts."$NAME".actions.roles true
|
|
openclaw config set channels.discord.accounts."$NAME".actions.channelInfo true
|
|
openclaw config set channels.discord.accounts."$NAME".actions.events true
|
|
openclaw config set channels.discord.accounts."$NAME".actions.channels true
|
|
openclaw config set channels.discord.accounts."$NAME".dmPolicy "open"
|
|
openclaw config set channels.discord.accounts."$NAME".allowFrom '["*"]'
|
|
openclaw config set channels.discord.accounts."$NAME".dm.enabled true
|
|
openclaw config set channels.discord.accounts."$NAME".execApprovals.enabled false
|
|
openclaw config set channels.discord.accounts."$NAME".execApprovals.approvers '["*"]'
|
|
|
|
~/.openclaw/skills/keycloak-hangman-lab/scripts/create-keycloak-account
|
|
~/.openclaw/skills/git-hangman-lab/scripts/create-git-account
|
|
~/.openclaw/skills/git-hangman-lab/scripts/link-keycloak
|
|
|
|
echo "Onboarding complete for $NAME."
|