update.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env bash
  2. #############################################################################
  3. # OpenAgents Control Updater
  4. # Updates existing OpenCode components to latest versions
  5. #############################################################################
  6. set -e
  7. # Colors
  8. GREEN='\033[0;32m'
  9. # YELLOW='\033[1;33m' # Unused
  10. BLUE='\033[0;34m'
  11. CYAN='\033[0;36m'
  12. BOLD='\033[1m'
  13. NC='\033[0m'
  14. REPO_URL="https://raw.githubusercontent.com/darrenhinde/OpenAgentsControl/main"
  15. INSTALL_DIR=".opencode"
  16. print_success() { echo -e "${GREEN}✓${NC} $1"; }
  17. print_info() { echo -e "${BLUE}ℹ${NC} $1"; }
  18. print_step() { echo -e "\n${CYAN}${BOLD}▶${NC} $1\n"; }
  19. print_header() {
  20. echo -e "${CYAN}${BOLD}"
  21. echo "╔════════════════════════════════════════════════════════════════╗"
  22. echo "║ ║"
  23. echo "║ OpenAgents Control Updater v1.0.0 ║"
  24. echo "║ ║"
  25. echo "╚════════════════════════════════════════════════════════════════╝"
  26. echo -e "${NC}"
  27. }
  28. update_component() {
  29. local path=$1
  30. local url="${REPO_URL}/${path}"
  31. if [ ! -f "$path" ]; then
  32. print_info "Skipping $path (not installed)"
  33. return
  34. fi
  35. # Backup existing file
  36. cp "$path" "${path}.backup"
  37. if curl -fsSL "$url" -o "$path"; then
  38. print_success "Updated $path"
  39. rm "${path}.backup"
  40. else
  41. print_info "Failed to update $path, restoring backup"
  42. mv "${path}.backup" "$path"
  43. fi
  44. }
  45. main() {
  46. print_header
  47. if [ ! -d "$INSTALL_DIR" ]; then
  48. echo "Error: $INSTALL_DIR directory not found"
  49. echo "Run install.sh first to install components"
  50. exit 1
  51. fi
  52. print_step "Updating components..."
  53. # Update all markdown files in .opencode
  54. while IFS= read -r -d '' file; do
  55. update_component "$file"
  56. done < <(find "$INSTALL_DIR" -name "*.md" -type f -print0)
  57. # Update TypeScript files
  58. while IFS= read -r -d '' file; do
  59. update_component "$file"
  60. done < <(find "$INSTALL_DIR" -name "*.ts" -type f -not -path "*/node_modules/*" -print0)
  61. # Update config files
  62. [ -f "env.example" ] && update_component "env.example"
  63. print_success "Update complete!"
  64. }
  65. main "$@"