Files
aitbc/scripts/utils/workspace-manager.sh
aitbc 3b8249d299 refactor: comprehensive scripts directory reorganization by functionality
Scripts Directory Reorganization - Complete:
 FUNCTIONAL ORGANIZATION: Scripts sorted into 8 logical categories
- github/: GitHub and Git operations (6 files)
- sync/: Synchronization and data replication (4 files)
- security/: Security and audit operations (2 files)
- monitoring/: System and service monitoring (6 files)
- maintenance/: System maintenance and cleanup (4 files)
- deployment/: Deployment and provisioning (11 files)
- testing/: Testing and quality assurance (13 files)
- utils/: Utility scripts and helpers (47 files)

 ROOT DIRECTORY CLEANED: Only README.md remains in scripts root
- scripts/README.md: Main documentation
- scripts/SCRIPTS_ORGANIZATION.md: Complete organization guide
- All functional scripts moved to appropriate subdirectories

 SCRIPTS CATEGORIZATION:
📁 GitHub Operations: PR resolution, repository management, Git workflows
📁 Synchronization: Bulk sync, fast sync, sync detection, SystemD sync
📁 Security: Security audits, monitoring, vulnerability scanning
📁 Monitoring: Health checks, log monitoring, network monitoring, production monitoring
📁 Maintenance: Cleanup operations, performance tuning, weekly maintenance
📁 Deployment: Release building, node provisioning, DAO deployment, production deployment
📁 Testing: E2E testing, workflow testing, QA cycles, service testing
📁 Utilities: System management, setup scripts, helpers, tools

 ORGANIZATION BENEFITS:
- Better Navigation: Scripts grouped by functionality
- Easier Maintenance: Related scripts grouped together
- Scalable Structure: Easy to add new scripts to appropriate categories
- Clear Documentation: Comprehensive organization guide with descriptions
- Improved Workflow: Quick access to relevant scripts by category

 DOCUMENTATION ENHANCED:
- SCRIPTS_ORGANIZATION.md: Complete directory structure and usage guide
- Quick Reference: Common script usage examples
- Script Descriptions: Purpose and functionality for each script
- Maintenance Guidelines: How to keep organization current

DIRECTORY STRUCTURE:
📁 scripts/
├── README.md (Main documentation)
├── SCRIPTS_ORGANIZATION.md (Organization guide)
├── github/ (6 files - GitHub operations)
├── sync/ (4 files - Synchronization)
├── security/ (2 files - Security)
├── monitoring/ (6 files - Monitoring)
├── maintenance/ (4 files - Maintenance)
├── deployment/ (11 files - Deployment)
├── testing/ (13 files - Testing)
├── utils/ (47 files - Utilities)
├── ci/ (existing - CI/CD)
├── deployment/ (existing - legacy deployment)
├── development/ (existing - Development tools)
├── monitoring/ (existing - Legacy monitoring)
├── services/ (existing - Service management)
├── testing/ (existing - Legacy testing)
├── utils/ (existing - Legacy utilities)
├── workflow/ (existing - Workflow automation)
└── workflow-openclaw/ (existing - OpenClaw workflows)

RESULT: Successfully reorganized 27 unorganized scripts into 8 functional categories, creating a clean, maintainable, and well-documented scripts directory structure with comprehensive organization guide.
2026-03-30 17:13:27 +02:00

206 lines
5.6 KiB
Bash
Executable File

#!/bin/bash
# AITBC Workspace Management Script
# Handles setup, cleanup, and management of external workspaces
set -euo pipefail
# Configuration
WORKSPACE_BASE="/var/lib/aitbc-workspaces"
REPO_URL="http://10.0.3.107:3000/oib/aitbc.git"
GITEA_TOKEN="${GITEA_TOKEN:-b8fbb3e7e6cecf3a01f8a242fc652631c6dfd010}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Create workspace base directory
ensure_workspace_base() {
if [[ ! -d "$WORKSPACE_BASE" ]]; then
log_info "Creating workspace base directory: $WORKSPACE_BASE"
sudo mkdir -p "$WORKSPACE_BASE"
sudo chmod 755 "$WORKSPACE_BASE"
log_success "Workspace base directory created"
fi
}
# Setup a specific workspace
setup_workspace() {
local workspace_type="$1"
local workspace_dir="$WORKSPACE_BASE/$workspace_type"
log_info "=== Setting up $workspace_type workspace ==="
# Cleanup existing workspace
if [[ -d "$workspace_dir" ]]; then
log_warning "Removing existing workspace: $workspace_dir"
rm -rf "$workspace_dir"
fi
# Create new workspace
mkdir -p "$workspace_dir"
cd "$workspace_dir"
# Clone repository
log_info "Cloning repository to: $workspace_dir/repo"
if ! git clone "$REPO_URL" repo; then
log_error "Failed to clone repository"
return 1
fi
cd repo
log_success "$workspace_type workspace ready at $workspace_dir/repo"
log_info "Current directory: $(pwd)"
log_info "Repository contents:"
ls -la | head -10
# Set git config for CI
git config --global http.sslVerify false
git config --global http.postBuffer 1048576000
return 0
}
# Cleanup all workspaces
cleanup_all_workspaces() {
log_info "=== Cleaning up all workspaces ==="
if [[ -d "$WORKSPACE_BASE" ]]; then
log_warning "Removing workspace base directory: $WORKSPACE_BASE"
rm -rf "$WORKSPACE_BASE"
log_success "All workspaces cleaned up"
else
log_info "No workspaces to clean up"
fi
}
# List all workspaces
list_workspaces() {
log_info "=== AITBC Workspaces ==="
if [[ ! -d "$WORKSPACE_BASE" ]]; then
log_info "No workspace base directory found"
return 0
fi
log_info "Workspace base: $WORKSPACE_BASE"
echo
for workspace in "$WORKSPACE_BASE"/*; do
if [[ -d "$workspace" ]]; then
local workspace_name=$(basename "$workspace")
local size=$(du -sh "$workspace" 2>/dev/null | cut -f1)
local files=$(find "$workspace" -type f 2>/dev/null | wc -l)
echo "📁 $workspace_name"
echo " Size: $size"
echo " Files: $files"
echo " Path: $workspace"
echo
fi
done
}
# Check workspace status
check_workspace() {
local workspace_type="$1"
local workspace_dir="$WORKSPACE_BASE/$workspace_type"
log_info "=== Checking $workspace_type workspace ==="
if [[ ! -d "$workspace_dir" ]]; then
log_warning "Workspace does not exist: $workspace_dir"
return 1
fi
if [[ ! -d "$workspace_dir/repo" ]]; then
log_warning "Repository not found in workspace: $workspace_dir/repo"
return 1
fi
cd "$workspace_dir/repo"
local git_status=$(git status --porcelain 2>/dev/null | wc -l)
local current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
local last_commit=$(git log -1 --format="%h %s" 2>/dev/null || echo "unknown")
local workspace_size=$(du -sh "$workspace_dir" 2>/dev/null | cut -f1)
echo "📊 Workspace Status:"
echo " Path: $workspace_dir/repo"
echo " Size: $workspace_size"
echo " Branch: $current_branch"
echo " Modified files: $git_status"
echo " Last commit: $last_commit"
return 0
}
# Main function
main() {
local command="${1:-help}"
case "$command" in
"setup")
ensure_workspace_base
setup_workspace "${2:-python-packages}"
;;
"cleanup")
cleanup_all_workspaces
;;
"list")
list_workspaces
;;
"check")
check_workspace "${2:-python-packages}"
;;
"help"|*)
echo "AITBC Workspace Management Script"
echo
echo "Usage: $0 <command> [args]"
echo
echo "Commands:"
echo " setup [workspace] Setup a workspace (default: python-packages)"
echo " cleanup Clean up all workspaces"
echo " list List all workspaces"
echo " check [workspace] Check workspace status"
echo " help Show this help"
echo
echo "Available workspaces:"
echo " python-packages"
echo " javascript-packages"
echo " security-tests"
echo " integration-tests"
echo " compatibility-tests"
echo
echo "Examples:"
echo " $0 setup python-packages"
echo " $0 setup javascript-packages"
echo " $0 check python-packages"
echo " $0 list"
echo " $0 cleanup"
;;
esac
}
# Run main function
main "$@"