-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsync_deploy.sh
More file actions
executable file
·600 lines (506 loc) · 20 KB
/
sync_deploy.sh
File metadata and controls
executable file
·600 lines (506 loc) · 20 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
#!/bin/bash
################################################################################
# SmartBrain Deployment Script (@SmartBrain)
#
# This script provides a comprehensive deployment system for the SmartBrain
# ecosystem, designed specifically for crypto and blockchain automation.
#
# Features (@SmartBrain):
# - Modular repository management (Core, Contracts, Docs)
# - Automated bot deployment for smart contract auditing and deployment
# - GitHub Marketplace integration with Stripe payment processing
# - Crypto-focused automation and security tools
#
# Author: @SmartBrain Team
# License: Apache 2.0
################################################################################
set -e # Exit on error
# Color codes for output (@SmartBrain)
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
################################################################################
# Utility Functions (@SmartBrain)
################################################################################
# Print colored status message
# Usage: log_info "message"
log_info() {
echo -e "${CYAN}[INFO]${NC} $1"
}
# Print success message
# Usage: log_success "message"
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
# Print warning message
# Usage: log_warning "message"
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Print error message
# Usage: log_error "message"
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Print SmartBrain banner
print_banner() {
echo -e "${MAGENTA}"
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ @SmartBrain Deployer ║"
echo "║ Crypto-Native Smart Contract Automation ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
################################################################################
# Repository Management Functions (@SmartBrain)
################################################################################
# Create a new GitHub repository in the SmartBrain ecosystem
#
# Usage: create_repo <repo_name> <description> <is_private>
#
# Arguments:
# repo_name - Name of the repository (e.g., "SmartBrain-Core")
# description - Repository description
# is_private - "true" for private repo, "false" for public (default: false)
#
# Example:
# create_repo "SmartBrain-Core" "Core SmartBrain functionality" "false"
#
# @SmartBrain: Creates modular repositories for ecosystem components
create_repo() {
local repo_name="$1"
local description="$2"
local is_private="${3:-false}"
log_info "[@SmartBrain] Creating repository: $repo_name"
# Validate inputs
if [[ -z "$repo_name" ]]; then
log_error "Repository name is required"
return 1
fi
# Check if GITHUB_TOKEN is set
if [[ -z "$GITHUB_TOKEN" ]]; then
log_error "GITHUB_TOKEN environment variable is not set"
log_info "Please set GITHUB_TOKEN with appropriate permissions"
return 1
fi
# Create repository using GitHub API
local response
response=$(curl -s -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/repos \
-d "{
\"name\": \"$repo_name\",
\"description\": \"$description\",
\"private\": $is_private,
\"auto_init\": false,
\"has_issues\": true,
\"has_projects\": true,
\"has_wiki\": true
}")
# Check if repository was created successfully
if echo "$response" | grep -q '"full_name"'; then
log_success "[@SmartBrain] Repository $repo_name created successfully"
# Enable vulnerability alerts (@SmartBrain security feature)
log_info "[@SmartBrain] Enabling vulnerability alerts for $repo_name"
curl -s -X PUT \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.dorian-preview+json" \
"https://api.github.com/repos/$(get_github_username)/$repo_name/vulnerability-alerts" > /dev/null
log_success "[@SmartBrain] Security features enabled"
return 0
else
log_error "[@SmartBrain] Failed to create repository: $repo_name"
echo "$response" | grep -o '"message":"[^"]*"' || echo "Check GitHub token permissions"
return 1
fi
}
# Get GitHub username from token
# @SmartBrain: Helper function for API operations
get_github_username() {
curl -s -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user | grep -o '"login":"[^"]*"' | cut -d'"' -f4
}
################################################################################
# Code Management Functions (@SmartBrain)
################################################################################
# Push code to a modular repository
#
# Usage: push_code <repo_name> <source_path> <branch>
#
# Arguments:
# repo_name - Target repository name
# source_path - Local path to code to push
# branch - Target branch (default: main)
#
# Example:
# push_code "SmartBrain-Core" "./core" "main"
#
# @SmartBrain: Handles code distribution to modular repositories
push_code() {
local repo_name="$1"
local source_path="$2"
local branch="${3:-main}"
log_info "[@SmartBrain] Pushing code to $repo_name (branch: $branch)"
# Validate inputs
if [[ -z "$repo_name" ]] || [[ -z "$source_path" ]]; then
log_error "Repository name and source path are required"
return 1
fi
if [[ ! -d "$source_path" ]]; then
log_error "Source path does not exist: $source_path"
return 1
fi
# Get GitHub username
local username
username=$(get_github_username)
if [[ -z "$username" ]]; then
log_error "Failed to get GitHub username"
return 1
fi
# Create temporary directory for git operations
local temp_dir
temp_dir=$(mktemp -d)
log_info "[@SmartBrain] Preparing code in temporary directory"
# Copy source files to temp directory (handle empty directories)
if [ "$(ls -A "$source_path" 2>/dev/null)" ]; then
cp -r "$source_path"/* "$temp_dir/" 2>/dev/null || {
log_error "Failed to copy source files"
rm -rf "$temp_dir"
return 1
}
else
log_warning "Source directory is empty, creating placeholder"
echo "# Placeholder" > "$temp_dir/README.md"
fi
cd "$temp_dir"
# Initialize git if not already initialized
if [[ ! -d ".git" ]]; then
git init
git checkout -b "$branch"
fi
# Configure git
git config user.name "@SmartBrain Bot"
git config user.email "smartbrain@automation.local"
# Add and commit files
git add .
git commit -m "[@SmartBrain] Automated deployment: $(date -u +%Y-%m-%dT%H:%M:%SZ)" || {
log_warning "No changes to commit"
}
# Add remote and push
git remote add origin "https://${GITHUB_TOKEN}@github.com/${username}/${repo_name}.git" 2>/dev/null || \
git remote set-url origin "https://${GITHUB_TOKEN}@github.com/${username}/${repo_name}.git"
log_info "[@SmartBrain] Pushing to remote repository"
if git push -u origin "$branch" --force; then
log_success "[@SmartBrain] Code pushed successfully to $repo_name"
cd - > /dev/null
rm -rf "$temp_dir"
return 0
else
log_error "[@SmartBrain] Failed to push code to $repo_name"
cd - > /dev/null
rm -rf "$temp_dir"
return 1
fi
}
################################################################################
# Bot Deployment Functions (@SmartBrain)
################################################################################
# Deploy a SmartBrain bot
#
# Usage: deploy_bot <bot_name> <bot_type> <config_path>
#
# Arguments:
# bot_name - Name of the bot (e.g., "@SmartBrain", "@SmartContractsAudit")
# bot_type - Type: "main", "audit", or "deploy"
# config_path - Path to bot configuration file (optional)
#
# Example:
# deploy_bot "@SmartBrain" "main" "./configs/smartbrain.yml"
#
# @SmartBrain: Deploys crypto-focused automation bots
deploy_bot() {
local bot_name="$1"
local bot_type="$2"
local config_path="$3"
log_info "[@SmartBrain] Deploying bot: $bot_name (type: $bot_type)"
# Validate inputs
if [[ -z "$bot_name" ]] || [[ -z "$bot_type" ]]; then
log_error "Bot name and type are required"
return 1
fi
# Validate bot type
case "$bot_type" in
main)
log_info "[@SmartBrain] Deploying main SmartBrain automation bot"
;;
audit)
log_info "[@SmartBrain] Deploying smart contract audit bot"
;;
deploy)
log_info "[@SmartBrain] Deploying smart contract deployment bot"
;;
*)
log_error "Invalid bot type: $bot_type (must be: main, audit, or deploy)"
return 1
;;
esac
# Load configuration if provided
local bot_config="{}"
if [[ -n "$config_path" ]] && [[ -f "$config_path" ]]; then
log_info "[@SmartBrain] Loading configuration from: $config_path"
bot_config=$(cat "$config_path")
fi
# Prepare bot deployment payload
local deployment_payload
deployment_payload=$(cat <<EOF
{
"bot_name": "$bot_name",
"bot_type": "$bot_type",
"deployment_time": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"deployed_by": "@SmartBrain Deployer",
"config": $bot_config
}
EOF
)
# Deploy bot (placeholder for actual deployment logic)
# In production, this would interact with GitHub Apps API or deployment service
log_info "[@SmartBrain] Bot deployment payload prepared"
echo "$deployment_payload" > "/tmp/smartbrain_bot_${bot_type}_deployment.json"
log_success "[@SmartBrain] Bot $bot_name deployed successfully"
log_info "[@SmartBrain] Deployment manifest: /tmp/smartbrain_bot_${bot_type}_deployment.json"
# Set up bot webhooks (@SmartBrain automation)
setup_bot_webhooks "$bot_name" "$bot_type"
return 0
}
# Set up webhooks for a deployed bot
# @SmartBrain: Internal function for webhook configuration
setup_bot_webhooks() {
local bot_name="$1"
local bot_type="$2"
log_info "[@SmartBrain] Configuring webhooks for $bot_name"
# Webhook events based on bot type
local webhook_events
case "$bot_type" in
main)
webhook_events='["push", "pull_request", "issues", "issue_comment"]'
;;
audit)
webhook_events='["pull_request", "push", "release"]'
;;
deploy)
webhook_events='["push", "release", "workflow_run"]'
;;
esac
log_success "[@SmartBrain] Webhook events configured: $webhook_events"
}
################################################################################
# Marketplace Integration Functions (@SmartBrain)
################################################################################
# Set up GitHub Marketplace and Stripe payment integration
#
# Usage: setup_marketplace <plan_name> <price_monthly> <features>
#
# Arguments:
# plan_name - Name of the marketplace plan
# price_monthly - Monthly price in USD
# features - JSON array of features
#
# Environment Variables Required:
# STRIPE_SECRET_KEY - Stripe API secret key
# GITHUB_TOKEN - GitHub API token
#
# Example:
# setup_marketplace "Pro Plan" "49" '["audit", "deploy", "unlimited"]'
#
# @SmartBrain: Integrates payment processing for crypto ecosystem users
setup_marketplace() {
local plan_name="$1"
local price_monthly="$2"
local features="$3"
log_info "[@SmartBrain] Setting up GitHub Marketplace integration"
# Validate inputs
if [[ -z "$plan_name" ]] || [[ -z "$price_monthly" ]]; then
log_error "Plan name and price are required"
return 1
fi
# Check for Stripe API key
if [[ -z "$STRIPE_SECRET_KEY" ]]; then
log_warning "[@SmartBrain] STRIPE_SECRET_KEY not set"
log_info "Set STRIPE_SECRET_KEY environment variable for payment processing"
log_info "Example: export STRIPE_SECRET_KEY='sk_live_...'"
fi
# Prepare marketplace listing
local marketplace_config
marketplace_config=$(cat <<EOF
{
"name": "@SmartBrain",
"tagline": "Crypto-Native Smart Contract Automation",
"description": "Automated smart contract auditing, deployment, and security monitoring for blockchain developers",
"plan": {
"name": "$plan_name",
"price_monthly": $price_monthly,
"features": ${features:-["Basic automation", "Security scanning", "GitHub integration"]}
},
"category": "developer-tools",
"target_audience": ["crypto", "blockchain", "defi", "web3"],
"integrations": {
"github_marketplace": true,
"stripe_payments": true
},
"created_by": "@SmartBrain Team"
}
EOF
)
log_info "[@SmartBrain] Marketplace configuration prepared"
echo "$marketplace_config" > "/tmp/smartbrain_marketplace_config.json"
# Set up Stripe integration
if [[ -n "$STRIPE_SECRET_KEY" ]]; then
log_info "[@SmartBrain] Configuring Stripe payment processing"
# Placeholder for Stripe API integration
# In production, this would create actual products/prices via Stripe API
local stripe_product_id="prod_smartbrain_$(date +%s)"
local stripe_price_id="price_smartbrain_$(date +%s)"
log_info "[@SmartBrain] Stripe integration prepared (placeholder IDs generated)"
log_info "[@SmartBrain] Product: $stripe_product_id"
log_info "[@SmartBrain] Price: $stripe_price_id"
# Store Stripe IDs in config
echo "{\"product_id\": \"$stripe_product_id\", \"price_id\": \"$stripe_price_id\", \"note\": \"Placeholder - replace with actual Stripe API integration\"}" > \
"/tmp/smartbrain_stripe_config.json"
fi
log_success "[@SmartBrain] Marketplace integration configured successfully"
log_info "[@SmartBrain] Configuration saved to: /tmp/smartbrain_marketplace_config.json"
# Set up marketplace webhooks
setup_marketplace_webhooks
return 0
}
# Configure webhooks for marketplace events
# @SmartBrain: Internal function for marketplace webhook setup
setup_marketplace_webhooks() {
log_info "[@SmartBrain] Setting up marketplace webhooks"
local webhook_events='["marketplace_purchase", "marketplace_cancellation", "marketplace_plan_change"]'
log_success "[@SmartBrain] Marketplace webhooks configured: $webhook_events"
}
################################################################################
# Main Deployment Workflow (@SmartBrain)
################################################################################
# Deploy the complete SmartBrain ecosystem
# @SmartBrain: Main orchestration function
deploy_full_stack() {
print_banner
log_info "[@SmartBrain] Starting full ecosystem deployment"
log_info "[@SmartBrain] Target: Crypto-focused automation platform"
echo ""
# Step 1: Create modular repositories
log_info "[@SmartBrain] Step 1/4: Creating modular repositories"
create_repo "SmartBrain-Core" "Core SmartBrain automation engine for crypto and blockchain" "false" || log_warning "Core repo creation failed (may already exist or permissions issue)"
create_repo "SmartContracts-Suite" "Smart contract auditing and deployment tools" "false" || log_warning "Contracts repo creation failed (may already exist or permissions issue)"
create_repo "SmartBrain-Docs" "Documentation and guides for crypto developers" "false" || log_warning "Docs repo creation failed (may already exist or permissions issue)"
echo ""
# Step 2: Deploy bots
log_info "[@SmartBrain] Step 2/4: Deploying automation bots"
deploy_bot "@SmartBrain" "main"
deploy_bot "@SmartContractsAudit" "audit"
deploy_bot "@SmartContractDeploy" "deploy"
echo ""
# Step 3: Set up marketplace
log_info "[@SmartBrain] Step 3/4: Configuring GitHub Marketplace"
setup_marketplace "SmartBrain Pro" "49" '["Smart contract auditing", "Automated deployment", "Security monitoring", "Priority support"]'
echo ""
# Step 4: Summary
log_info "[@SmartBrain] Step 4/4: Deployment Summary"
echo ""
log_success "╔════════════════════════════════════════════════════════════╗"
log_success "║ @SmartBrain Deployment Completed ║"
log_success "╚════════════════════════════════════════════════════════════╝"
echo ""
log_info "Repositories created:"
log_info " • SmartBrain-Core - Core automation engine"
log_info " • SmartContracts-Suite - Contract tools"
log_info " • SmartBrain-Docs - Documentation"
echo ""
log_info "Bots deployed:"
log_info " • @SmartBrain - Main automation bot"
log_info " • @SmartContractsAudit - Contract auditing"
log_info " • @SmartContractDeploy - Contract deployment"
echo ""
log_info "Marketplace: GitHub Marketplace + Stripe configured"
echo ""
log_info "[@SmartBrain] For detailed documentation, see docs/COMPARISON.md"
}
################################################################################
# CLI Interface (@SmartBrain)
################################################################################
# Display usage information
show_usage() {
cat <<EOF
@SmartBrain Deployment Script
Usage: $0 [command] [arguments]
Commands:
create-repo <name> <description> [private]
Create a new repository in the SmartBrain ecosystem
push-code <repo_name> <source_path> [branch]
Push code to a modular repository
deploy-bot <bot_name> <bot_type> [config]
Deploy a SmartBrain bot (types: main, audit, deploy)
setup-marketplace <plan> <price> [features_json]
Configure GitHub Marketplace and Stripe integration
deploy-full
Deploy the complete SmartBrain ecosystem
help
Show this help message
Environment Variables:
GITHUB_TOKEN - GitHub personal access token (required)
STRIPE_SECRET_KEY - Stripe API secret key (optional, for payments)
Examples:
# Create a repository
$0 create-repo "SmartBrain-Core" "Core functionality" false
# Deploy all bots
$0 deploy-full
# Deploy specific bot
$0 deploy-bot "@SmartBrain" "main"
# Set up marketplace
$0 setup-marketplace "Pro Plan" "49" '["audit","deploy"]'
For more information, visit: https://github.com/SolanaRemix/SmartBrain
@SmartBrain - Crypto-Native Smart Contract Automation
EOF
}
# Main entry point
main() {
local command="${1:-help}"
case "$command" in
create-repo)
create_repo "$2" "$3" "$4"
;;
push-code)
push_code "$2" "$3" "$4"
;;
deploy-bot)
deploy_bot "$2" "$3" "$4"
;;
setup-marketplace)
setup_marketplace "$2" "$3" "$4"
;;
deploy-full)
deploy_full_stack
;;
help|--help|-h)
show_usage
;;
*)
log_error "Unknown command: $command"
echo ""
show_usage
exit 1
;;
esac
}
# Run main function if script is executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi