1+ #! /bin/bash
2+ # setup_workspace.sh - One-time setup for Coffee Buddy development environment
3+ #
4+ # DESCRIPTION:
5+ # This script performs the initial setup required for Coffee Buddy development.
6+ # It installs system dependencies, creates the Python virtual environment,
7+ # and installs all required Python packages. Run this script once before
8+ # using the activate_workspace.sh script for daily development.
9+ #
10+ # Currently supports Ubuntu/Debian systems. Future versions will support macOS.
11+ #
12+ # USAGE:
13+ # ./scripts/setup_workspace.sh [venv_name]
14+ #
15+ # PARAMETERS:
16+ # venv_name Optional. Name of the virtual environment to create.
17+ # Default: coffee_buddy_venv
18+ #
19+ # EXAMPLES:
20+ # # Use default virtual environment
21+ # ./scripts/setup_workspace.sh
22+ #
23+ # # Use specific virtual environment
24+ # ./scripts/setup_workspace.sh my_custom_venv
25+ #
26+ # REQUIREMENTS:
27+ # - Ubuntu/Debian system (apt package manager)
28+ # - sudo privileges (for system package installation)
29+ # - Internet connection
30+ #
31+ # WHAT IT DOES:
32+ # 1. Installs system dependencies for audio processing (PyAudio)
33+ # 2. Creates Python virtual environment if it doesn't exist
34+ # 3. Installs Python packages from requirements.txt
35+ # 4. Calls activate_workspace.sh to verify setup
36+ #
37+ # NOTE:
38+ # This script requires sudo privileges for system package installation.
39+
40+ # TODO: Add macOS support using homebrew
41+ # TODO: Add Windows support using chocolatey or vcpkg
42+ # TODO: Add automatic platform detection
43+
44+ set -e # Exit on any error
45+
46+ # Default venv name
47+ DEFAULT_VENV_NAME=" coffee_buddy_venv"
48+ VENV_NAME=" ${1:- $DEFAULT_VENV_NAME } "
49+
50+ # Find the repository root
51+ REPO_ROOT=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) /.." && pwd)
52+
53+ # Define paths
54+ VENV_PATH=" $REPO_ROOT /$VENV_NAME "
55+ REQUIREMENTS_FILE=" $REPO_ROOT /requirements.txt"
56+
57+ echo " Setting up Coffee Buddy development environment..."
58+ echo " Virtual environment: $VENV_NAME "
59+ echo " Repository root: $REPO_ROOT "
60+ echo " "
61+
62+ # Step 1: Install system dependencies for Ubuntu
63+ echo " [1/4] Installing system dependencies..."
64+
65+ # TODO: Add platform detection here
66+ # if [[ "$OSTYPE" == "darwin"* ]]; then
67+ # # macOS
68+ # echo "Installing macOS dependencies with homebrew..."
69+ # brew install portaudio python3
70+ # elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
71+ # # Linux (Ubuntu/Debian)
72+
73+ # Check if we're on Ubuntu/Debian
74+ if ! command -v apt & > /dev/null; then
75+ echo " Error: This script currently only supports Ubuntu/Debian systems (apt package manager)"
76+ echo " TODO: Add support for other Linux distributions and macOS"
77+ exit 1
78+ fi
79+
80+ # Install system dependencies required for PyAudio
81+ echo " Installing Ubuntu system dependencies for audio processing..."
82+ sudo apt update
83+ sudo apt install -y \
84+ portaudio19-dev \
85+ python3-dev \
86+ python3-venv \
87+ python3-pip \
88+ build-essential \
89+ libasound2-dev \
90+ pkg-config
91+
92+ echo " ✓ System dependencies installed"
93+
94+ # TODO: Add elif for other platforms here
95+ # else
96+ # echo "Error: Unsupported platform: $OSTYPE"
97+ # echo "TODO: Add support for this platform"
98+ # exit 1
99+ # fi
100+
101+ # Step 2: Create virtual environment if it doesn't exist
102+ echo " "
103+ echo " [2/4] Setting up Python virtual environment..."
104+
105+ if [ -d " $VENV_PATH " ]; then
106+ echo " Virtual environment already exists at: $VENV_PATH "
107+ else
108+ echo " Creating virtual environment at: $VENV_PATH "
109+ python3 -m venv " $VENV_PATH "
110+ echo " ✓ Virtual environment created"
111+ fi
112+
113+ # Step 3: Activate virtual environment and install packages
114+ echo " "
115+ echo " [3/4] Installing Python packages..."
116+
117+ if [ ! -f " $REQUIREMENTS_FILE " ]; then
118+ echo " Error: requirements.txt not found at: $REQUIREMENTS_FILE "
119+ exit 1
120+ fi
121+
122+ # Activate virtual environment
123+ source " $VENV_PATH /bin/activate"
124+
125+ # Upgrade pip to latest version
126+ echo " Upgrading pip..."
127+ pip install --upgrade pip
128+
129+ # Install packages from requirements.txt
130+ echo " Installing packages from requirements.txt..."
131+ pip install -r " $REQUIREMENTS_FILE "
132+
133+ echo " ✓ Python packages installed"
134+
135+ # Step 4: Test the setup by activating the workspace
136+ echo " "
137+ echo " [4/4] Testing workspace activation..."
138+
139+ # Source the activation script to verify everything works
140+ source " $REPO_ROOT /scripts/activate_workspace.sh" " $VENV_NAME "
141+
142+ echo " "
143+ echo " 🎉 Setup complete!"
144+ echo " "
145+ echo " Next steps:"
146+ echo " 1. To activate your development environment daily, run:"
147+ echo " source scripts/activate_workspace.sh"
148+ echo " "
149+ echo " 2. Test your TTS node:"
150+ echo " ros2 run coffee_voice_service tts_node"
151+ echo " "
152+ echo " 3. If you encounter issues, check the logs or re-run this setup script."
153+ echo " "
154+
155+ # TODO: Add verification steps
156+ # TODO: Test PyAudio import specifically
157+ # TODO: Check ROS2 package build status
0 commit comments