-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·106 lines (92 loc) · 3.56 KB
/
setup.sh
File metadata and controls
executable file
·106 lines (92 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
#
# Distributed Team Setup
#
# This script initializes the token database, creates role-based tokens,
# and prints connection instructions for team members.
#
# Prerequisites:
# - Tokenomics binary built (make build)
# - Environment variables set (source .env)
#
# Usage:
# chmod +x examples/distributed-team/setup.sh
# ./examples/distributed-team/setup.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BIN="${BIN:-./bin/tokenomics}"
PROXY_HOST="${PROXY_HOST:-localhost}"
PROXY_PORT="${PROXY_PORT:-8443}"
# ── Colors ──────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m'
info() { echo -e "${BLUE}[info]${NC} $*"; }
ok() { echo -e "${GREEN}[ok]${NC} $*"; }
warn() { echo -e "${YELLOW}[warn]${NC} $*"; }
err() { echo -e "${RED}[error]${NC} $*" >&2; }
# ── Preflight checks ───────────────────────────────────────────────
if [ ! -f "$BIN" ]; then
err "Binary not found at $BIN. Run 'make build' first."
exit 1
fi
if [ -z "${TOKENOMICS_HASH_KEY:-}" ]; then
err "TOKENOMICS_HASH_KEY is not set. Source your .env file first."
exit 1
fi
echo ""
echo -e "${BOLD}Tokenomics Distributed Team Setup${NC}"
echo "======================================"
echo ""
# ── Copy configs ───────────────────────────────────────────────────
info "Copying central config..."
cp "$SCRIPT_DIR/central-config.yaml" config.yaml
cp "$SCRIPT_DIR/providers.yaml" providers.yaml
ok "Config files in place."
# ── Create tokens ──────────────────────────────────────────────────
echo ""
echo -e "${BOLD}Creating role-based tokens...${NC}"
echo ""
create_token() {
local role="$1"
local expires="$2"
local policy_file="$SCRIPT_DIR/policies/${role}.json"
if [ ! -f "$policy_file" ]; then
err "Policy file not found: $policy_file"
return 1
fi
echo -e "${YELLOW}--- $role ---${NC}"
$BIN token create --policy "$(cat "$policy_file")" --expires "$expires"
echo ""
}
create_token "lead-engineer" "1y"
create_token "developer" "90d"
create_token "contractor" "30d"
create_token "ci-pipeline" "1y"
# ── Print instructions ─────────────────────────────────────────────
echo ""
echo -e "${BOLD}Setup complete.${NC}"
echo ""
echo "Next steps:"
echo ""
echo " 1. Save each token above. They cannot be recovered."
echo ""
echo " 2. Start the central config server:"
echo " $BIN remote --addr :9090 --api-key \"\$TOKENOMICS_REMOTE_KEY\""
echo ""
echo " 3. On each proxy machine, copy proxy-config.yaml and start:"
echo " cp $SCRIPT_DIR/proxy-config.yaml config.yaml"
echo " cp $SCRIPT_DIR/providers.yaml providers.yaml"
echo " $BIN serve"
echo ""
echo " 4. Give team members their token and connection command:"
echo " eval \$($BIN init --token tkn_<TOKEN> --host $PROXY_HOST --port $PROXY_PORT --insecure)"
echo ""
echo " 5. List and manage tokens:"
echo " $BIN token list"
echo " $BIN token update --hash <HASH> --expires 180d"
echo " $BIN token delete --hash <HASH>"
echo ""