forked from google-gemini/gemini-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-proxy.sh
More file actions
executable file
Β·172 lines (144 loc) Β· 4.84 KB
/
setup-proxy.sh
File metadata and controls
executable file
Β·172 lines (144 loc) Β· 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# GCR-Gemini Setup Script
# Sets up the Gemini CLI Router proxy for Gemini CLI
# Author: Jason Zhang
set -e
echo "π Setting up GCR-Gemini (Gemini CLI Router for Third-Party AI Providers)..."
# Check if Node.js is installed
if ! command -v node &> /dev/null; then
echo "β Node.js is required but not installed."
echo "Please install Node.js from https://nodejs.org/"
exit 1
fi
# Check Node.js version
NODE_VERSION=$(node -v | sed 's/v//')
MIN_VERSION="16.0.0"
if [ "$(printf '%s\n' "$MIN_VERSION" "$NODE_VERSION" | sort -V | head -n1)" != "$MIN_VERSION" ]; then
echo "β Node.js version $NODE_VERSION is too old. Minimum required: $MIN_VERSION"
exit 1
fi
echo "β
Node.js version: $NODE_VERSION"
# Check if gemini command exists
if ! command -v gemini &> /dev/null; then
echo "β οΈ Gemini CLI not found in PATH."
echo "Please install gemini-cli first: npm install -g @google/gemini-cli"
echo "Or make sure it's in your PATH."
exit 1
fi
echo "β
Gemini CLI found: $(which gemini)"
# Get current directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROXY_DIR="$SCRIPT_DIR/proxy-service"
echo "π Working directory: $SCRIPT_DIR"
# Install proxy service dependencies
if [ -d "$PROXY_DIR" ]; then
echo "π¦ Installing proxy service dependencies..."
cd "$PROXY_DIR"
npm install
echo "β
Dependencies installed"
else
echo "β Proxy service directory not found: $PROXY_DIR"
exit 1
fi
# Make gcr-gemini executable
cd "$SCRIPT_DIR"
chmod +x gcr-gemini
# Create environment file if it doesn't exist
if [ ! -f "$PROXY_DIR/.env" ]; then
echo "π Creating environment configuration..."
cp "$PROXY_DIR/.env.example" "$PROXY_DIR/.env"
echo "β
Created .env file from template"
echo "π§ You can edit $PROXY_DIR/.env to customize settings"
fi
# Test the setup
echo "π§ͺ Testing proxy service..."
cd "$PROXY_DIR"
# Check if port 3458 is already in use
PORT_CHECK=$(lsof -ti:3458 2>/dev/null || echo "")
if [ ! -z "$PORT_CHECK" ]; then
echo "β οΈ Port 3458 is already in use by process(es): $PORT_CHECK"
echo "πͺ Killing existing processes on port 3458..."
# Kill processes using the port
for pid in $PORT_CHECK; do
echo " Killing process $pid"
kill -9 $pid 2>/dev/null || true
done
# Wait a moment for processes to die
sleep 2
# Verify port is now free
REMAINING=$(lsof -ti:3458 2>/dev/null || echo "")
if [ ! -z "$REMAINING" ]; then
echo "β Failed to free port 3458. Please manually kill processes: $REMAINING"
exit 1
else
echo "β
Port 3458 is now free"
fi
fi
# Start proxy service in background for testing
echo "π Starting test proxy service..."
node src/server.js &
PROXY_PID=$!
# Wait a bit for the service to start
sleep 3
# Test if proxy is responding
if curl -s http://localhost:3458/health > /dev/null 2>&1; then
echo "β
Proxy service test successful"
else
echo "β οΈ Proxy service test failed, but setup is complete"
fi
# Stop test proxy service
echo "π Stopping test proxy service..."
kill $PROXY_PID 2>/dev/null || true
wait $PROXY_PID 2>/dev/null || true
# Final port cleanup
FINAL_CHECK=$(lsof -ti:3458 2>/dev/null || echo "")
if [ ! -z "$FINAL_CHECK" ]; then
echo "π§ Cleaning up remaining processes on port 3458..."
for pid in $FINAL_CHECK; do
kill -9 $pid 2>/dev/null || true
done
fi
# Global installation option
echo ""
echo "π GCR-Gemini setup complete!"
echo ""
echo "π Choose installation method:"
echo ""
echo "1. π Local usage (current directory):"
echo " ./gcr-gemini -p \"Hello, world!\""
echo ""
echo "2. π Global installation (recommended):"
read -p " Install globally? [y/N]: " INSTALL_GLOBAL
if [[ $INSTALL_GLOBAL =~ ^[Yy]$ ]]; then
echo " Installing globally..."
# Create global symlink as 'gcr' command
if [ -w "/usr/local/bin" ]; then
ln -sf "$SCRIPT_DIR/gcr-gemini" /usr/local/bin/gcr
echo " β
Global symlink created: /usr/local/bin/gcr"
else
echo " Creating global symlink (requires sudo):"
sudo ln -sf "$SCRIPT_DIR/gcr-gemini" /usr/local/bin/gcr
echo " β
Global symlink created: /usr/local/bin/gcr"
fi
echo ""
echo " π― Test global installation:"
echo " gcr -p \"Hello, world!\""
else
echo ""
echo " π Using local installation."
echo " π‘ To use globally, add to PATH:"
echo " export PATH=\"$SCRIPT_DIR:\$PATH\""
echo ""
echo " π― Test local installation:"
echo " ./gcr-gemini -p \"Hello, world!\""
fi
echo ""
echo "π§ Configuration:"
echo " Edit $PROXY_DIR/.env to change provider settings"
echo ""
echo "π Usage:"
echo " gcr [any-gemini-command]"
echo " gcr --help"
echo " GCR_DEBUG=true gcr -p \"test\""
echo ""
echo "β
Setup complete! Happy coding! π"