install.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. else
  16. echo -e "${GREEN}uv is already installed${NC}"
  17. # Optionally update uv
  18. echo "Updating uv..."
  19. uv self update
  20. fi
  21. # Verify uv installation
  22. if ! command -v uv &> /dev/null; then
  23. echo -e "${RED}Failed to install uv. Please install it manually.${NC}"
  24. exit 1
  25. fi
  26. # Initialize the project with uv (only if .venv doesn't exist)
  27. if [ ! -d ".venv" ]; then
  28. echo -e "\n${GREEN}Creating virtual environment...${NC}"
  29. uv venv --python 3.10
  30. else
  31. echo -e "\n${GREEN}Virtual environment already exists${NC}"
  32. fi
  33. # Install dependencies from pyproject.toml
  34. echo -e "\n${GREEN}Installing dependencies...${NC}"
  35. uv pip install .
  36. # Set up pycache directory before build
  37. mkdir -p .cache/__pycache__
  38. PYTHONPYCACHEPREFIX="$(pwd)/.cache/__pycache__"
  39. # Build the project
  40. echo -e "\n${GREEN}Building project...${NC}"
  41. uv build
  42. # Configure config.yaml
  43. if [ ! -f "config.yaml" ] && [ -f "config_example.yaml" ]; then
  44. echo -e "\n${YELLOW}Setting up configuration...${NC}"
  45. cp config_example.yaml config.yaml
  46. # Get current directory and update base_dir in config.yaml
  47. CURRENT_DIR=$(pwd)
  48. WORKSPACE_DIR="${CURRENT_DIR}/.nanobrowser"
  49. # Create .nanobrowser directory if it doesn't exist
  50. mkdir -p "${WORKSPACE_DIR}"
  51. # Update base_dir in config.yaml
  52. if [[ "$OSTYPE" == "darwin"* ]]; then
  53. # macOS
  54. sed -i '' "s|/Users/jason/.nanobrowser|${WORKSPACE_DIR}|" config.yaml
  55. else
  56. # Linux
  57. sed -i "s|/Users/jason/.nanobrowser|${WORKSPACE_DIR}|" config.yaml
  58. fi
  59. echo "A default config.yaml file has been created in the current directory. Please configure it before running the application."
  60. fi
  61. echo -e "\n${GREEN}Setup completed!${NC}"
  62. echo "To run the project:"
  63. echo "1. Edit config.yaml with your settings, fill in the LLM api keys"
  64. echo "2. Make sure you have a Google Chrome browser installed"
  65. echo "3. Make sure you have the chrome extension installed via the developer mode in chrome"
  66. echo "4. Run: uv run nanobrowser"