forked from luohy15/y-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstallSh.ts
More file actions
212 lines (184 loc) · 7.34 KB
/
installSh.ts
File metadata and controls
212 lines (184 loc) · 7.34 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
export const installSh = `#!/bin/bash
set -e
install_nodejs() {
local platform=$(uname -s)
case "$platform" in
Linux|Darwin)
echo "🚀 Installing Node.js on Unix/Linux/macOS..."
echo "📥 Downloading and installing nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
echo "🔄 Loading nvm environment..."
\\. "$HOME/.nvm/nvm.sh"
echo "📦 Downloading and installing Node.js v22..."
nvm install 22
echo -n "✅ Node.js installation completed! Version: "
node -v # Should print "v22.17.0".
echo -n "✅ Current nvm version: "
nvm current # Should print "v22.17.0".
echo -n "✅ npm version: "
npm -v # Should print "10.9.2".
;;
*)
echo "Unsupported platform: $platform"
exit 1
;;
esac
}
# Check if Node.js is already installed and version is >= 18
if command -v node >/dev/null 2>&1; then
current_version=$(node -v | sed 's/v//')
major_version=$(echo $current_version | cut -d. -f1)
if [ "$major_version" -ge 18 ]; then
echo "Node.js is already installed: v$current_version"
else
echo "Node.js v$current_version is installed but version < 18. Upgrading..."
install_nodejs
fi
else
echo "Node.js not found. Installing..."
install_nodejs
fi
# Check if Claude Code is already installed
if command -v claude >/dev/null 2>&1; then
echo "Claude Code is already installed: $(claude --version)"
else
echo "Claude Code not found. Installing..."
npm install -g @anthropic-ai/claude-code
fi
# Configure Claude Code to skip onboarding
echo "Configuring Claude Code to skip onboarding..."
node --eval '
const homeDir = os.homedir();
const filePath = path.join(homeDir, ".claude.json");
if (fs.existsSync(filePath)) {
const content = JSON.parse(fs.readFileSync(filePath, "utf-8"));
fs.writeFileSync(filePath,JSON.stringify({ ...content, hasCompletedOnboarding: true }, 2), "utf-8");
} else {
fs.writeFileSync(filePath,JSON.stringify({ hasCompletedOnboarding: true }), "utf-8");
}'
# Provider selection
echo "🔧 Please select your AI provider:"
echo "1) OpenRouter (default)"
echo "2) Moonshot"
echo ""
read -p "Enter your choice [1]: " provider_choice
provider_choice=\${provider_choice:-1}
echo ""
case "$provider_choice" in
1)
provider="openrouter"
default_base_url="https://cc.yovy.app"
api_key_url="https://openrouter.ai/keys"
default_model_main="anthropic/claude-sonnet-4"
default_model_small="anthropic/claude-3.5-haiku"
;;
2)
provider="moonshot"
echo "🔧 Please select your Moonshot endpoint:"
echo "1) Global (api.moonshot.ai)"
echo "2) China (api.moonshot.cn)"
echo ""
read -p "Enter your choice [1]: " moonshot_endpoint_choice
moonshot_endpoint_choice=\${moonshot_endpoint_choice:-1}
case "$moonshot_endpoint_choice" in
1)
default_base_url="https://api.moonshot.ai/anthropic/"
api_key_url="https://platform.moonshot.ai/console/api-keys"
pricing_url="https://platform.moonshot.ai/docs/pricing/limits"
;;
2)
default_base_url="https://api.moonshot.cn/anthropic/"
api_key_url="https://platform.moonshot.cn/console/api-keys"
pricing_url="https://platform.moonshot.cn/docs/pricing/limits"
;;
*)
echo "⚠️ Invalid choice. Using Global (.ai) endpoint as default."
default_base_url="https://api.moonshot.ai/anthropic/"
api_key_url="https://platform.moonshot.ai/console/api-keys"
pricing_url="https://platform.moonshot.ai/docs/pricing/limits"
;;
esac
echo ""
echo "⚠️ Important: Moonshot requires account credit before use"
echo " You must add funds to your account first, otherwise you'll get rate limit errors"
echo " Pricing info: $pricing_url"
echo ""
default_model_main="kimi-k2-0711-preview"
default_model_small="moonshot-v1-8k"
;;
*)
echo "⚠️ Invalid choice. Please run the script again and select 1 or 2."
exit 1
;;
esac
# Prompt for configuration with defaults
echo "⚙️ Configure your $provider settings (press Enter to use defaults):"
echo ""
read -p "Base URL [$default_base_url]: " base_url
echo ""
base_url=\${base_url:-$default_base_url}
echo "🔑 Please enter your $provider API key:"
echo " You can get your API key from: $api_key_url"
echo " Note: The input is hidden for security. Please paste your API key directly."
echo ""
read -s api_key
echo "✅ API key received (\${#api_key} characters)"
echo ""
if [ -z "$api_key" ]; then
echo "⚠️ API key cannot be empty. Please run the script again."
exit 1
fi
read -p "Main model [$default_model_main]: " model_main
model_main=\${model_main:-$default_model_main}
read -p "Small/fast model [$default_model_small]: " model_small
model_small=\${model_small:-$default_model_small}
# Detect current shell and determine rc file
current_shell=$(basename "$SHELL")
case "$current_shell" in
bash)
rc_file="$HOME/.bashrc"
;;
zsh)
rc_file="$HOME/.zshrc"
;;
fish)
rc_file="$HOME/.config/fish/config.fish"
;;
*)
rc_file="$HOME/.profile"
;;
esac
# Add environment variables to rc file
echo ""
echo "📝 Configuring environment variables in $rc_file..."
# Create backup if file exists
if [ -f "$rc_file" ]; then
cp "$rc_file" "\${rc_file}.backup.$(date +%Y%m%d_%H%M%S)"
fi
# Remove existing Claude Code environment variables
if [ -f "$rc_file" ]; then
# Use a temporary file to store content without Claude Code variables
grep -v "^# Claude Code environment variables\\|^export ANTHROPIC_BASE_URL\\|^export ANTHROPIC_API_KEY\\|^export ANTHROPIC_MODEL\\|^export ANTHROPIC_SMALL_FAST_MODEL" "$rc_file" > "\${rc_file}.tmp" || true
mv "\${rc_file}.tmp" "$rc_file"
fi
# Add new environment variables
echo "" >> "$rc_file"
echo "# Claude Code environment variables for $provider" >> "$rc_file"
echo "export ANTHROPIC_BASE_URL=$base_url" >> "$rc_file"
echo "export ANTHROPIC_API_KEY=$api_key" >> "$rc_file"
echo "export ANTHROPIC_MODEL=$model_main" >> "$rc_file"
echo "export ANTHROPIC_SMALL_FAST_MODEL=$model_small" >> "$rc_file"
echo "✅ Environment variables configured in $rc_file"
echo ""
echo "🎉 Installation completed successfully!"
echo ""
echo "🔄 Please restart your terminal or run:"
echo " source $rc_file"
echo ""
echo "🚀 Then you can start using Claude Code with:"
echo " claude"
echo ""
echo "💡 Tip: To maintain multiple configurations, use shell aliases:"
echo " alias c1='ANTHROPIC_BASE_URL=\\"https://cc.yovy.app\\" ANTHROPIC_API_KEY=\\"key1\\" ANTHROPIC_MODEL=\\"moonshotai/kimi-k2\\" ANTHROPIC_SMALL_FAST_MODEL=\\"google/gemini-2.5-flash\\" claude'"
echo " alias c2='ANTHROPIC_BASE_URL=\\"https://api.moonshot.ai/anthropic/\\" ANTHROPIC_API_KEY=\\"key2\\" ANTHROPIC_MODEL=\\"kimi-k2-0711-preview\\" ANTHROPIC_SMALL_FAST_MODEL=\\"moonshot-v1-8k\\" claude'"
`;