cscsj/gemini-business2api
0
1@echo off
2REM Gemini Business2API Setup Script
3REM Handles both installation and updates automatically
4REM Uses uv for Python environment management
5REM Usage: setup.bat
6
7setlocal enabledelayedexpansion
8
9echo ==========================================
10echo Gemini Business2API Setup Script
11echo ==========================================
12echo.
13
14REM Color codes for output (using echo instead of ANSI codes for better Windows compatibility)
15set GREEN=[92m
16set RED=[91m
17set YELLOW=[93m
18set BLUE=[94m
19set NC=[0m
20
21REM Function to print colored messages (simplified for Windows)
22set "PRINT_SUCCESS=echo [SUCCESS]"
23set "PRINT_ERROR=echo [ERROR]"
24set "PRINT_INFO=echo [INFO]"
25set "PRINT_STEP=echo [STEP]"
26
27REM Check if git is installed
28where git >nul 2>nul
29if %errorlevel% neq 0 (
30 echo [ERROR] Git is not installed. Please install git first.
31 exit /b 1
32)
33
34REM Step 1: Install or update uv
35echo [STEP] Step 1: Installing/Updating uv...
36
37where uv >nul 2>nul
38if %errorlevel% neq 0 (
39 echo [INFO] uv not found, installing...
40 REM Install uv using pipx or pip
41 pipx install uv 2>nul
42 if %errorlevel% neq 0 (
43 pip install --user uv 2>nul
44 if %errorlevel% neq 0 (
45 REM Fallback: download and install uv binary
46 curl -LsSf https://astral.sh/uv/install.bat | cmd
47 )
48 )
49 if %errorlevel% equ 0 (
50 echo [SUCCESS] uv installed successfully
51 ) else (
52 echo [ERROR] Failed to install uv
53 exit /b 1
54 )
55) else (
56 echo [INFO] Updating uv to latest version...
57 uv pip install --upgrade uv
58 echo [SUCCESS] uv updated
59)
60echo.
61
62REM Step 2: Ensure Python 3.11 is available
63echo [STEP] Step 2: Ensuring Python 3.11 is available...
64uv python list | findstr /C:"3.11" >nul
65if %errorlevel% neq 0 (
66 echo [INFO] Python 3.11 not found, installing...
67 uv python install 3.11
68 if %errorlevel% neq 0 (
69 echo [ERROR] Failed to install Python 3.11
70 exit /b 1
71 )
72 echo [SUCCESS] Python 3.11 installed
73) else (
74 echo [SUCCESS] Python 3.11 is already available
75)
76echo.
77
78REM Step 3: Pull latest code from git
79echo [STEP] Step 3: Syncing code from repository...
80echo [INFO] Fetching latest changes...
81git fetch origin
82
83echo [INFO] Pulling latest code...
84git pull origin main 2>nul || git pull origin master 2>nul
85if %errorlevel% equ 0 (
86 echo [SUCCESS] Code synchronized successfully
87) else (
88 echo [INFO] No remote changes to pull
89)
90echo.
91
92REM Step 4: Setup .env file if it doesn't exist
93echo [STEP] Step 4: Checking configuration...
94if exist .env (
95 echo [INFO] .env file exists
96) else (
97 if exist .env.example (
98 copy .env.example .env >nul
99 echo [SUCCESS] .env file created from .env.example
100 echo [INFO] Please edit .env and configure your ADMIN_KEY
101 ) else (
102 echo [ERROR] .env.example not found
103 exit /b 1
104 )
105)
106echo.
107
108REM Step 5: Setup Python virtual environment
109echo [STEP] Step 5: Setting up Python environment...
110if exist .venv (
111 echo [INFO] Virtual environment already exists
112) else (
113 echo [INFO] Creating virtual environment with Python 3.11...
114 uv venv --python 3.11 .venv
115 if %errorlevel% neq 0 (
116 echo [ERROR] Failed to create virtual environment
117 exit /b 1
118 )
119 echo [SUCCESS] Virtual environment created
120)
121echo.
122
123REM Step 6: Install/Update Python dependencies
124echo [STEP] Step 6: Installing Python dependencies...
125echo [INFO] Using uv to install dependencies (this may take a moment)...
126.venv\Scripts\python.exe -m pip install --upgrade pip --quiet
127uv pip install -r requirements.txt
128if %errorlevel% neq 0 (
129 echo [ERROR] Failed to install Python dependencies
130 exit /b 1
131)
132echo [SUCCESS] Python dependencies installed
133echo.
134
135REM Step 7: Setup frontend
136echo [STEP] Step 7: Setting up frontend...
137if exist frontend (
138 cd frontend
139
140 REM Check if npm is installed
141 where npm >nul 2>nul
142 if %errorlevel% equ 0 (
143 echo [INFO] Installing dependencies...
144 npm install
145
146 echo [INFO] Building frontend...
147 npm run build
148 echo [SUCCESS] Frontend built successfully
149 ) else (
150 echo [ERROR] npm is not installed. Please install Node.js and npm first.
151 cd ..
152 exit /b 1
153 )
154
155 cd ..
156) else (
157 echo [ERROR] Frontend directory not found. Are you in the project root?
158 exit /b 1
159)
160echo.
161
162REM Step 8: Show completion message
163echo ==========================================
164echo [SUCCESS] Setup completed successfully!
165echo ==========================================
166echo.
167
168if exist .env (
169 echo [INFO] Next steps:
170 echo.
171 echo 1. Edit .env file if needed:
172 echo notepad .env
173 echo.
174 echo 2. Start the service:
175 echo .venv\Scripts\python.exe main.py
176 echo.
177 echo 3. Access the admin panel:
178 echo http://localhost:7860/
179 echo.
180 echo [INFO] To activate virtual environment later, run:
181 echo .venv\Scripts\activate.bat
182)
183echo.
184
185endlocal
186 