setup.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. #!/bin/bash
  2. has_asdf_plugin() {
  3. local plugin="$1"
  4. case "$plugin" in
  5. nodejs|python|golang|rust) echo "true" ;;
  6. *) echo "false" ;;
  7. esac
  8. }
  9. build_extension() {
  10. echo "🔨 Building the Roo Code extension..."
  11. pnpm -w vsix -- --out ../bin/roo-code-$(git rev-parse --short HEAD).vsix || exit 1
  12. code --install-extension ../../bin/roo-code-$(git rev-parse --short HEAD).vsix || exit 1
  13. cd evals
  14. }
  15. check_docker_services() {
  16. echo "🐳 Checking Docker services..."
  17. if ! command -v docker &> /dev/null; then
  18. echo "❌ Docker is not installed. Please install Docker Desktop and try again."
  19. exit 1
  20. fi
  21. if ! docker info &> /dev/null; then
  22. echo "❌ Docker is not running. Please start Docker Desktop and try again."
  23. exit 1
  24. fi
  25. if ! docker compose version &> /dev/null; then
  26. echo "❌ Docker Compose is not available. Please ensure Docker Desktop is properly installed."
  27. exit 1
  28. fi
  29. local services_to_start=()
  30. if ! nc -z localhost 5432 2>/dev/null; then
  31. echo "📦 PostgreSQL not running on port 5432"
  32. services_to_start+=("db")
  33. else
  34. echo "✅ PostgreSQL is running"
  35. fi
  36. if ! nc -z localhost 6379 2>/dev/null; then
  37. echo "📦 Redis not running on port 6379"
  38. services_to_start+=("redis")
  39. else
  40. echo "✅ Redis is running"
  41. fi
  42. if [ ${#services_to_start[@]} -gt 0 ]; then
  43. echo "🚀 Starting Docker services: ${services_to_start[*]}"
  44. echo "🧹 Cleaning up stale Docker state..."
  45. docker compose down --remove-orphans &>/dev/null || true
  46. docker network prune -f &>/dev/null || true
  47. if docker compose --profile server up -d "${services_to_start[@]}"; then
  48. echo "✅ Docker services started successfully"
  49. echo "⏳ Waiting for services to be ready..."
  50. local timeout=30
  51. local elapsed=0
  52. local all_ready=false
  53. while [ $elapsed -lt $timeout ]; do
  54. all_ready=true
  55. for service in "${services_to_start[@]}"; do
  56. if [[ "$service" == "db" ]] && ! nc -z localhost 5432 2>/dev/null; then
  57. all_ready=false
  58. break
  59. elif [[ "$service" == "redis" ]] && ! nc -z localhost 6379 2>/dev/null; then
  60. all_ready=false
  61. break
  62. fi
  63. done
  64. if [ "$all_ready" = true ]; then
  65. echo "✅ All services are ready"
  66. break
  67. fi
  68. sleep 1
  69. elapsed=$((elapsed + 1))
  70. if [ $((elapsed % 5)) -eq 0 ]; then
  71. echo " Still waiting... (${elapsed}s/${timeout}s)"
  72. fi
  73. done
  74. if [ "$all_ready" = false ]; then
  75. echo "❌ Timeout: Services failed to start within ${timeout} seconds"
  76. echo " Please check Docker logs: docker compose logs"
  77. exit 1
  78. fi
  79. else
  80. echo "❌ Failed to start Docker services even after cleanup. Please check your docker-compose.yml file."
  81. exit 1
  82. fi
  83. else
  84. echo "✅ All required Docker services are already running"
  85. fi
  86. }
  87. if [[ "$(uname -s)" != "Darwin" ]]; then
  88. echo "⚠️ Only macOS is currently supported."
  89. echo "The Roo Code evals system can also be run with Docker on any platform."
  90. echo "See https://github.com/RooCodeInc/Roo-Code/blob/main/packages/evals/README.md for instructions."
  91. exit 1
  92. fi
  93. if ! command -v brew &>/dev/null; then
  94. if [[ -f "/opt/homebrew/bin/brew" ]]; then
  95. echo "⚠️ Homebrew is installed but not in your PATH"
  96. exit 1
  97. fi
  98. read -p "🍺 Homebrew (https://brew.sh) is required. Install it? (Y/n): " install_brew
  99. if [[ "$install_brew" =~ ^[Yy]|^$ ]]; then
  100. echo "🍺 Installing Homebrew..."
  101. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || exit 1
  102. # Can be undone with:
  103. # /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" && sudo rm -rvf /opt/homebrew
  104. if [[ "$SHELL" == "/bin/zsh" ]] && ! grep -q 'eval "$(/opt/homebrew/bin/brew shellenv)"' ~/.zprofile; then
  105. echo '[[ -s "/opt/homebrew/bin/brew" ]] && eval "$(/opt/homebrew/bin/brew shellenv)"' >>~/.zprofile
  106. elif [[ "$SHELL" == "/bin/bash" ]] && ! grep -q 'eval "$(/opt/homebrew/bin/brew shellenv)"' ~/.bash_profile; then
  107. echo '[[ -s "/opt/homebrew/bin/brew" ]] && eval "$(/opt/homebrew/bin/brew shellenv)"' >>~/.bash_profile
  108. fi
  109. if [[ "$SHELL" == "/bin/zsh" ]]; then
  110. eval "$(/opt/homebrew/bin/brew shellenv)"
  111. elif [[ "$SHELL" == "/bin/bash" ]]; then
  112. eval "$(/opt/homebrew/bin/brew shellenv)"
  113. fi
  114. BREW_VERSION=$(brew --version)
  115. echo "✅ Homebrew is installed ($BREW_VERSION)"
  116. else
  117. exit 1
  118. fi
  119. else
  120. BREW_VERSION=$(brew --version)
  121. echo "✅ Homebrew is installed ($BREW_VERSION)"
  122. fi
  123. ASDF_PATH="$(brew --prefix asdf)/libexec/asdf.sh"
  124. if ! command -v asdf &>/dev/null; then
  125. if [[ -f "$ASDF_PATH" ]]; then
  126. echo "⚠️ asdf is installed but not in your PATH"
  127. exit 1
  128. fi
  129. read -p "🛠️ asdf (https://asdf-vm.com) is required. Install it? (Y/n): " install_asdf
  130. if [[ "$install_asdf" =~ ^[Yy]|^$ ]]; then
  131. echo "🛠️ Installing asdf..."
  132. brew install asdf || exit 1
  133. # Can be undone with:
  134. # brew uninstall asdf
  135. # rm -rvf ~/.asdf
  136. . "$ASDF_PATH"
  137. if [[ "$SHELL" == "/bin/zsh" ]] && ! grep -q 'source "$(brew --prefix asdf)/libexec/asdf.sh"' ~/.zshrc; then
  138. echo '[[ -s "/opt/homebrew/bin/brew" ]] && [[ -s "$(brew --prefix asdf)/libexec/asdf.sh" ]] && source "$(brew --prefix asdf)/libexec/asdf.sh"' >>~/.zprofile
  139. elif [[ "$SHELL" == "/bin/bash" ]] && ! grep -q 'source "$(brew --prefix asdf)/libexec/asdf.sh"' ~/.bash_profile; then
  140. echo '[[ -s "/opt/homebrew/bin/brew" ]] && [[ -s "$(brew --prefix asdf)/libexec/asdf.sh" ]] && source "$(brew --prefix asdf)/libexec/asdf.sh"' >>~/.bash_profile
  141. fi
  142. ASDF_VERSION=$(asdf --version)
  143. echo "✅ asdf is installed ($ASDF_VERSION)"
  144. else
  145. exit 1
  146. fi
  147. else
  148. ASDF_VERSION=$(asdf --version)
  149. echo "✅ asdf is installed ($ASDF_VERSION)"
  150. . "$ASDF_PATH"
  151. fi
  152. if ! command -v gh &>/dev/null; then
  153. read -p "👨‍💻 GitHub cli is needed to submit evals results. Install it? (Y/n): " install_gh
  154. if [[ "$install_gh" =~ ^[Yy]|^$ ]]; then
  155. brew install gh || exit 1
  156. GH_VERSION=$(gh --version | head -n 1)
  157. echo "✅ gh is installed ($GH_VERSION)"
  158. gh auth status || gh auth login -w -p https
  159. fi
  160. else
  161. GH_VERSION=$(gh --version | head -n 1)
  162. echo "✅ gh is installed ($GH_VERSION)"
  163. fi
  164. options=("nodejs" "python" "golang" "rust" "java")
  165. binaries=("node" "python" "go" "rustc" "javac")
  166. for i in "${!options[@]}"; do
  167. plugin="${options[$i]}"
  168. binary="${binaries[$i]}"
  169. if [[ "$(has_asdf_plugin "$plugin")" == "true" ]]; then
  170. if ! asdf plugin list | grep -q "^${plugin}$" && ! command -v "${binary}" &>/dev/null; then
  171. echo "📦 Installing ${plugin} asdf plugin..."
  172. asdf plugin add "${plugin}" || exit 1
  173. echo "✅ asdf ${plugin} plugin installed successfully"
  174. fi
  175. fi
  176. case "${plugin}" in
  177. "nodejs")
  178. if ! command -v node &>/dev/null; then
  179. asdf install nodejs 20.19.2 || exit 1
  180. asdf set nodejs 20.19.2 || exit 1
  181. NODE_VERSION=$(node --version)
  182. echo "✅ Node.js is installed ($NODE_VERSION)"
  183. else
  184. NODE_VERSION=$(node --version)
  185. echo "✅ Node.js is installed ($NODE_VERSION)"
  186. fi
  187. if [[ $(node --version) != "v20.19.2" ]]; then
  188. NODE_VERSION=$(node --version)
  189. echo "🚨 You have the wrong version of node installed ($NODE_VERSION)."
  190. echo "💡 If you are using nvm then run 'nvm install' to install the version specified by the repo's .nvmrc."
  191. exit 1
  192. fi
  193. ;;
  194. "python")
  195. if ! command -v python &>/dev/null; then
  196. asdf install python 3.13.2 || exit 1
  197. asdf set python 3.13.2 || exit 1
  198. PYTHON_VERSION=$(python --version)
  199. echo "✅ Python is installed ($PYTHON_VERSION)"
  200. else
  201. PYTHON_VERSION=$(python --version)
  202. echo "✅ Python is installed ($PYTHON_VERSION)"
  203. fi
  204. if ! command -v uv &>/dev/null; then
  205. brew install uv || exit 1
  206. UV_VERSION=$(uv --version)
  207. echo "✅ uv is installed ($UV_VERSION)"
  208. else
  209. UV_VERSION=$(uv --version)
  210. echo "✅ uv is installed ($UV_VERSION)"
  211. fi
  212. ;;
  213. "golang")
  214. if ! command -v go &>/dev/null; then
  215. asdf install golang 1.24.2 || exit 1
  216. asdf set golang 1.24.2 || exit 1
  217. GO_VERSION=$(go version)
  218. echo "✅ Go is installed ($GO_VERSION)"
  219. else
  220. GO_VERSION=$(go version)
  221. echo "✅ Go is installed ($GO_VERSION)"
  222. fi
  223. ;;
  224. "rust")
  225. if ! command -v rustc &>/dev/null; then
  226. asdf install rust 1.85.1 || exit 1
  227. asdf set rust 1.85.1 || exit 1
  228. RUST_VERSION=$(rustc --version)
  229. echo "✅ Rust is installed ($RUST_VERSION)"
  230. else
  231. RUST_VERSION=$(rustc --version)
  232. echo "✅ Rust is installed ($RUST_VERSION)"
  233. fi
  234. ;;
  235. "java")
  236. if ! command -v javac &>/dev/null || ! javac --version &>/dev/null; then
  237. echo "☕ Installing Java..."
  238. brew install openjdk@17 || exit 1
  239. export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
  240. if [[ "$SHELL" == "/bin/zsh" ]] && ! grep -q 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' ~/.zprofile; then
  241. echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zprofile
  242. elif [[ "$SHELL" == "/bin/bash" ]] && ! grep -q 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' ~/.bash_profile; then
  243. echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.bash_profile
  244. fi
  245. JAVA_VERSION=$(javac --version | head -n 1)
  246. echo "✅ Java is installed ($JAVA_VERSION)"
  247. else
  248. JAVA_VERSION=$(javac --version | head -n 1)
  249. echo "✅ Java is installed ($JAVA_VERSION)"
  250. fi
  251. ;;
  252. esac
  253. done
  254. if ! command -v pnpm &>/dev/null; then
  255. brew install pnpm || exit 1
  256. PNPM_VERSION=$(pnpm --version)
  257. echo "✅ pnpm is installed ($PNPM_VERSION)"
  258. else
  259. PNPM_VERSION=$(pnpm --version)
  260. echo "✅ pnpm is installed ($PNPM_VERSION)"
  261. fi
  262. pnpm install --silent || exit 1
  263. if ! command -v code &>/dev/null; then
  264. echo "⚠️ Visual Studio Code cli is not installed"
  265. exit 1
  266. else
  267. VSCODE_VERSION=$(code --version | head -n 1)
  268. echo "✅ Visual Studio Code is installed ($VSCODE_VERSION)"
  269. fi
  270. # To reset VSCode:
  271. # rm -rvf ~/.vscode && rm -rvf ~/Library/Application\ Support/Code
  272. echo -n "🔌 Installing Visual Studio Code extensions... "
  273. code --install-extension golang.go &>/dev/null || exit 1
  274. code --install-extension dbaeumer.vscode-eslint&>/dev/null || exit 1
  275. code --install-extension redhat.java &>/dev/null || exit 1
  276. code --install-extension ms-python.python&>/dev/null || exit 1
  277. code --install-extension rust-lang.rust-analyzer &>/dev/null || exit 1
  278. if ! code --list-extensions 2>/dev/null | grep -q "RooVeterinaryInc.roo-cline"; then
  279. code --install-extension RooVeterinaryInc.roo-cline &>/dev/null || exit 1
  280. fi
  281. echo "✅ Done"
  282. if [[ ! -d "../../../evals" ]]; then
  283. echo -n "🔗 Cloning evals repository... "
  284. git clone https://github.com/RooCodeInc/Roo-Code-Evals.git ../../../evals || exit 1
  285. echo "✅ Done"
  286. else
  287. echo -n "🔄 Updating evals repository... "
  288. (cd ../../../evals && \
  289. git checkout -f &>/dev/null && \
  290. git clean -f -d &>/dev/null && \
  291. git checkout main &>/dev/null && \
  292. git pull &>/dev/null) || { echo "❌ Failed to update evals repository."; exit 1; }
  293. echo "✅ Done"
  294. fi
  295. if [[ ! -s .env.local ]]; then
  296. touch .env.local || exit 1
  297. fi
  298. # Check and start Docker services before database operations
  299. check_docker_services
  300. echo -n "🗄️ Syncing Roo Code evals database... "
  301. pnpm --filter @roo-code/evals db:push --force &>/dev/null || exit 1
  302. echo "✅ Done"
  303. if ! grep -q "OPENROUTER_API_KEY" .env.local; then
  304. read -p "🔐 Enter your OpenRouter API key (sk-or-v1-...): " openrouter_api_key
  305. echo "🔑 Validating..."
  306. curl --silent --fail https://openrouter.ai/api/v1/key -H "Authorization: Bearer $openrouter_api_key" &>/dev/null || exit 1
  307. echo "OPENROUTER_API_KEY=$openrouter_api_key" >> .env.local || exit 1
  308. fi
  309. current_version=$(code --list-extensions --show-versions 2>/dev/null | grep roo)
  310. read -p "💻 Do you want to build a new version of the Roo Code extension? [currently $current_version] (y/N): " build_extension
  311. if [[ "$build_extension" =~ ^[Yy]$ ]]; then
  312. build_extension
  313. fi
  314. echo -e "\n🚀 You're ready to rock and roll! \n"
  315. if ! nc -z localhost 3000; then
  316. read -p "🌐 Would you like to start the evals web app? (Y/n): " start_evals
  317. if [[ "$start_evals" =~ ^[Yy]|^$ ]]; then
  318. pnpm --filter @roo-code/web-evals dev
  319. else
  320. echo "💡 You can start it anytime with 'pnpm --filter @roo-code/web-evals dev'."
  321. fi
  322. else
  323. echo "👟 The evals web app is running at http://localhost:3000 (or http://localhost:3446 if using Docker)"
  324. fi