Author: Mike Swanson Machine: Mikes-MacBook-Air.local Timestamp: 2026-07-08 06:49:28
33 lines
1.4 KiB
Bash
33 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
# get-identity.sh — Read identity.json and export user/machine vars for attribution
|
|
#
|
|
# Source this at the start of any skill that needs attribution (bot alerts, commits,
|
|
# logs, RMM operations). Exports $USER_NAME, $USER_SHORT, $MACHINE, $USER_EMAIL.
|
|
#
|
|
# Usage:
|
|
# source .claude/scripts/get-identity.sh
|
|
# echo "[RMM] $USER_SHORT deployed to X machines..."
|
|
#
|
|
# Soft-fails: if identity.json is missing, exports "Unknown" values and returns 1
|
|
# (but does NOT exit, so the caller continues). This ensures skills never break on
|
|
# missing identity - they just attribute to "Unknown".
|
|
|
|
IDENTITY_FILE="${CLAUDETOOLS_ROOT:-.}/.claude/identity.json"
|
|
|
|
if [ ! -f "$IDENTITY_FILE" ]; then
|
|
echo "[WARNING] identity.json not found at $IDENTITY_FILE - attribution will be 'Unknown'" >&2
|
|
export USER_NAME="Unknown User"
|
|
export USER_SHORT="unknown"
|
|
export MACHINE="unknown-machine"
|
|
export USER_EMAIL="unknown@unknown.com"
|
|
return 1
|
|
fi
|
|
|
|
export USER_NAME=$(jq -r '.full_name // .user // "Unknown"' "$IDENTITY_FILE" 2>/dev/null || echo "Unknown")
|
|
export USER_SHORT=$(jq -r '.user // "unknown"' "$IDENTITY_FILE" 2>/dev/null || echo "unknown")
|
|
export MACHINE=$(jq -r '.machine // "unknown"' "$IDENTITY_FILE" 2>/dev/null || echo "unknown")
|
|
export USER_EMAIL=$(jq -r '.email // "unknown@unknown.com"' "$IDENTITY_FILE" 2>/dev/null || echo "unknown@unknown.com")
|
|
|
|
# Success
|
|
return 0
|