···
3
+
# Script: setup-kagi-aggregator.sh
4
+
# Purpose: Complete setup script for Kagi News RSS aggregator
6
+
# This is a reference implementation showing automated setup for a specific aggregator.
7
+
# Other aggregator developers can use this as a template.
11
+
echo "================================================"
12
+
echo "Kagi News RSS Aggregator - Automated Setup"
13
+
echo "================================================"
16
+
# Configuration for Kagi aggregator
17
+
AGGREGATOR_NAME="kagi-news-bot"
18
+
DISPLAY_NAME="Kagi News RSS"
19
+
DESCRIPTION="Aggregates tech news from Kagi RSS feeds and posts to relevant communities"
20
+
SOURCE_URL="https://github.com/coves-social/kagi-aggregator"
22
+
# Check if config already exists
23
+
if [ -f "kagi-aggregator-config.env" ]; then
24
+
echo "Configuration file already exists. Loading existing configuration..."
25
+
source kagi-aggregator-config.env
26
+
SKIP_ACCOUNT_CREATION=true
28
+
SKIP_ACCOUNT_CREATION=false
31
+
# Get runtime configuration
32
+
if [ "$SKIP_ACCOUNT_CREATION" = false ]; then
33
+
read -p "Enter PDS URL (default: https://bsky.social): " PDS_URL
34
+
PDS_URL=${PDS_URL:-https://bsky.social}
36
+
read -p "Enter email for bot account: " EMAIL
37
+
read -sp "Enter password for bot account: " PASSWORD
41
+
TIMESTAMP=$(date +%s)
42
+
HANDLE="$AGGREGATOR_NAME-$TIMESTAMP.bsky.social"
45
+
echo "Creating PDS account..."
46
+
echo "Handle: $HANDLE"
49
+
RESPONSE=$(curl -s -X POST "$PDS_URL/xrpc/com.atproto.server.createAccount" \
50
+
-H "Content-Type: application/json" \
52
+
\"handle\": \"$HANDLE\",
53
+
\"email\": \"$EMAIL\",
54
+
\"password\": \"$PASSWORD\"
57
+
if echo "$RESPONSE" | jq -e '.error' > /dev/null 2>&1; then
58
+
echo "โ Error creating account:"
59
+
echo "$RESPONSE" | jq '.'
63
+
DID=$(echo "$RESPONSE" | jq -r '.did')
64
+
ACCESS_JWT=$(echo "$RESPONSE" | jq -r '.accessJwt')
65
+
REFRESH_JWT=$(echo "$RESPONSE" | jq -r '.refreshJwt')
67
+
echo "โ Account created: $DID"
69
+
# Save configuration
70
+
cat > kagi-aggregator-config.env <<EOF
71
+
# Kagi Aggregator Configuration
72
+
AGGREGATOR_DID="$DID"
73
+
AGGREGATOR_HANDLE="$HANDLE"
74
+
AGGREGATOR_PDS_URL="$PDS_URL"
75
+
AGGREGATOR_EMAIL="$EMAIL"
76
+
AGGREGATOR_PASSWORD="$PASSWORD"
77
+
AGGREGATOR_ACCESS_JWT="$ACCESS_JWT"
78
+
AGGREGATOR_REFRESH_JWT="$REFRESH_JWT"
81
+
echo "โ Configuration saved to kagi-aggregator-config.env"
84
+
# Get domain and Coves instance
85
+
read -p "Enter aggregator domain (e.g., kagi-news.example.com): " DOMAIN
86
+
read -p "Enter Coves instance URL (default: https://api.coves.social): " COVES_URL
87
+
COVES_URL=${COVES_URL:-https://api.coves.social}
91
+
echo "Setting up .well-known/atproto-did..."
92
+
mkdir -p .well-known
93
+
echo "$DID" > .well-known/atproto-did
94
+
echo "โ Created .well-known/atproto-did"
97
+
echo "================================================"
98
+
echo "IMPORTANT: Manual Step Required"
99
+
echo "================================================"
101
+
echo "Upload the .well-known directory to your web server at:"
102
+
echo " https://$DOMAIN/.well-known/atproto-did"
104
+
read -p "Press Enter when the file is uploaded and accessible..."
106
+
# Verify .well-known
108
+
echo "Verifying .well-known/atproto-did..."
109
+
WELLKNOWN_CONTENT=$(curl -s "https://$DOMAIN/.well-known/atproto-did" || echo "ERROR")
111
+
if [ "$WELLKNOWN_CONTENT" != "$DID" ]; then
112
+
echo "โ Error: .well-known/atproto-did not accessible or contains wrong DID"
113
+
echo " Expected: $DID"
114
+
echo " Got: $WELLKNOWN_CONTENT"
118
+
echo "โ .well-known/atproto-did verified"
120
+
# Register with Coves
122
+
echo "Registering with Coves instance..."
123
+
RESPONSE=$(curl -s -X POST "$COVES_URL/xrpc/social.coves.aggregator.register" \
124
+
-H "Content-Type: application/json" \
127
+
\"domain\": \"$DOMAIN\"
130
+
if echo "$RESPONSE" | jq -e '.error' > /dev/null 2>&1; then
131
+
echo "โ Registration failed:"
132
+
echo "$RESPONSE" | jq '.'
136
+
echo "โ Registered with Coves"
138
+
# Create service declaration
140
+
echo "Creating service declaration..."
141
+
SERVICE_RECORD=$(cat <<EOF
143
+
"\$type": "social.coves.aggregator.service",
145
+
"displayName": "$DISPLAY_NAME",
146
+
"description": "$DESCRIPTION",
147
+
"sourceUrl": "$SOURCE_URL",
148
+
"createdAt": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
153
+
RESPONSE=$(curl -s -X POST "$PDS_URL/xrpc/com.atproto.repo.createRecord" \
154
+
-H "Authorization: Bearer $ACCESS_JWT" \
155
+
-H "Content-Type: application/json" \
157
+
\"repo\": \"$DID\",
158
+
\"collection\": \"social.coves.aggregator.service\",
159
+
\"rkey\": \"self\",
160
+
\"record\": $SERVICE_RECORD
163
+
if echo "$RESPONSE" | jq -e '.error' > /dev/null 2>&1; then
164
+
echo "โ Failed to create service declaration:"
165
+
echo "$RESPONSE" | jq '.'
169
+
RECORD_URI=$(echo "$RESPONSE" | jq -r '.uri')
170
+
echo "โ Service declaration created: $RECORD_URI"
172
+
# Save final configuration
173
+
cat >> kagi-aggregator-config.env <<EOF
175
+
# Setup completed on $(date)
176
+
AGGREGATOR_DOMAIN="$DOMAIN"
177
+
COVES_INSTANCE_URL="$COVES_URL"
178
+
SERVICE_DECLARATION_URI="$RECORD_URI"
182
+
echo "================================================"
183
+
echo "โ Kagi Aggregator Setup Complete!"
184
+
echo "================================================"
186
+
echo "Configuration saved to: kagi-aggregator-config.env"
188
+
echo "Your aggregator is now registered and ready to use."
191
+
echo "1. Start your aggregator bot: npm start (or appropriate command)"
192
+
echo "2. Community moderators can authorize your aggregator"
193
+
echo "3. Once authorized, your bot can start posting"
195
+
echo "See docs/aggregators/SETUP_GUIDE.md for more information"