install.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # Change to the directory where the script is located
  3. cd "$(dirname "$0")"
  4. # Colors for output
  5. GREEN='\033[0;32m'
  6. YELLOW='\033[1;33m'
  7. RED='\033[0;31m'
  8. NC='\033[0m' # No Color
  9. echo -e "${GREEN}Setting up the project...${NC}"
  10. # Check if uv is installed
  11. if ! command -v uv &> /dev/null; then
  12. echo -e "${YELLOW}uv not found. Installing...${NC}"
  13. # Install uv using the standalone installer
  14. curl -LsSf https://astral.sh/uv/install.sh | sh
  15. # Add uv to PATH
  16. export PATH="$HOME/.local/bin:$PATH"
  17. # Source the environment file
  18. if [ -f "$HOME/.local/bin/env" ]; then
  19. source "$HOME/.local/bin/env"
  20. fi
  21. else
  22. echo -e "${GREEN}uv is already installed${NC}"
  23. # Optionally update uv
  24. echo "Updating uv..."
  25. uv self update
  26. fi
  27. # Verify uv installation
  28. if ! command -v uv &> /dev/null; then
  29. echo -e "${RED}Failed to install uv. Please install it manually.${NC}"
  30. exit 1
  31. fi
  32. # Initialize the project with uv (only if .venv doesn't exist)
  33. if [ ! -d ".venv" ]; then
  34. echo -e "\n${GREEN}Creating virtual environment...${NC}"
  35. uv venv --python 3.10
  36. else
  37. echo -e "\n${GREEN}Virtual environment already exists${NC}"
  38. fi
  39. # Install dependencies from pyproject.toml
  40. echo -e "\n${GREEN}Installing dependencies...${NC}"
  41. uv pip install .
  42. # Set up pycache directory before build
  43. mkdir -p .cache/__pycache__
  44. PYTHONPYCACHEPREFIX="$(pwd)/.cache/__pycache__"
  45. # Build the project
  46. echo -e "\n${GREEN}Building project...${NC}"
  47. uv build
  48. # Configure config.yaml
  49. if [ ! -f "config.yaml" ] && [ -f "config_example.yaml" ]; then
  50. echo -e "\n${YELLOW}Setting up configuration...${NC}"
  51. cp config_example.yaml config.yaml
  52. # Get current directory and update base_dir in config.yaml
  53. CURRENT_DIR=$(pwd)
  54. WORKSPACE_DIR="${CURRENT_DIR}/.nanobrowser"
  55. # Create .nanobrowser directory if it doesn't exist
  56. mkdir -p "${WORKSPACE_DIR}"
  57. # Update base_dir in config.yaml
  58. if [[ "$OSTYPE" == "darwin"* ]]; then
  59. # macOS
  60. sed -i '' "s|/Users/jason/.nanobrowser|${WORKSPACE_DIR}|" config.yaml
  61. else
  62. # Linux
  63. sed -i "s|/Users/jason/.nanobrowser|${WORKSPACE_DIR}|" config.yaml
  64. fi
  65. echo "A default config.yaml file has been created in the current directory. Please configure it before running the application."
  66. fi
  67. echo -e "\n${GREEN}Setup completed!${NC}"
  68. echo "Before running the project:"
  69. echo "1. Edit config.yaml with your settings, fill in the LLM api keys"
  70. echo "2. Make sure you have a Google Chrome browser installed"
  71. echo "3. Make sure you have the chrome extension installed via the developer mode in chrome"
  72. echo "4. Either restart your shell or run:"
  73. echo " • For bash/zsh/sh users:"
  74. echo " source \$HOME/.local/bin/env"
  75. echo " • For fish users:"
  76. echo " source \$HOME/.local/bin/env.fish"
  77. echo "5. Run: uv run nanobrowser"