@@ -7,7 +7,51 @@ RED='\033[0;31m' |
7 | 7 | ORANGE='\033[38;5;214m' |
8 | 8 | NC='\033[0m' # No Color |
9 | 9 |
|
| 10 | +usage() { |
| 11 | + cat <<EOF |
| 12 | +OpenCode Installer |
| 13 | +
|
| 14 | +Usage: install.sh [options] |
| 15 | +
|
| 16 | +Options: |
| 17 | + -h, --help Display this help message |
| 18 | + -v, --version <version> Install a specific version (e.g., 1.0.180) |
| 19 | + --no-modify-path Don't modify shell config files (.zshrc, .bashrc, etc.) |
| 20 | +
|
| 21 | +Examples: |
| 22 | + curl -fsSL https://opencode.ai/install | bash |
| 23 | + curl -fsSL https://opencode.ai/install | bash -s -- --version 1.0.180 |
| 24 | +EOF |
| 25 | +} |
| 26 | + |
10 | 27 | requested_version=${VERSION:-} |
| 28 | +no_modify_path=false |
| 29 | + |
| 30 | +while [[ $# -gt 0 ]]; do |
| 31 | + case "$1" in |
| 32 | + -h|--help) |
| 33 | + usage |
| 34 | + exit 0 |
| 35 | + ;; |
| 36 | + -v|--version) |
| 37 | + if [[ -n "${2:-}" ]]; then |
| 38 | + requested_version="$2" |
| 39 | + shift 2 |
| 40 | + else |
| 41 | + echo -e "${RED}Error: --version requires a version argument${NC}" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + ;; |
| 45 | + --no-modify-path) |
| 46 | + no_modify_path=true |
| 47 | + shift |
| 48 | + ;; |
| 49 | + *) |
| 50 | + echo -e "${ORANGE}Warning: Unknown option '$1'${NC}" >&2 |
| 51 | + shift |
| 52 | + ;; |
| 53 | + esac |
| 54 | +done |
11 | 55 |
|
12 | 56 | raw_os=$(uname -s) |
13 | 57 | os=$(echo "$raw_os" | tr '[:upper:]' '[:lower:]') |
@@ -304,42 +348,42 @@ case $current_shell in |
304 | 348 | ;; |
305 | 349 | esac |
306 | 350 |
|
307 | | -config_file="" |
308 | | -for file in $config_files; do |
309 | | - if [[ -f $file ]]; then |
310 | | - config_file=$file |
311 | | - break |
| 351 | +if [[ "$no_modify_path" != "true" ]]; then |
| 352 | + config_file="" |
| 353 | + for file in $config_files; do |
| 354 | + if [[ -f $file ]]; then |
| 355 | + config_file=$file |
| 356 | + break |
| 357 | + fi |
| 358 | + done |
| 359 | + |
| 360 | + if [[ -z $config_file ]]; then |
| 361 | + print_message warning "No config file found for $current_shell. You may need to manually add to PATH:" |
| 362 | + print_message info " export PATH=$INSTALL_DIR:\$PATH" |
| 363 | + elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then |
| 364 | + case $current_shell in |
| 365 | + fish) |
| 366 | + add_to_path "$config_file" "fish_add_path $INSTALL_DIR" |
| 367 | + ;; |
| 368 | + zsh) |
| 369 | + add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" |
| 370 | + ;; |
| 371 | + bash) |
| 372 | + add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" |
| 373 | + ;; |
| 374 | + ash) |
| 375 | + add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" |
| 376 | + ;; |
| 377 | + sh) |
| 378 | + add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" |
| 379 | + ;; |
| 380 | + *) |
| 381 | + export PATH=$INSTALL_DIR:$PATH |
| 382 | + print_message warning "Manually add the directory to $config_file (or similar):" |
| 383 | + print_message info " export PATH=$INSTALL_DIR:\$PATH" |
| 384 | + ;; |
| 385 | + esac |
312 | 386 | fi |
313 | | -done |
314 | | - |
315 | | -if [[ -z $config_file ]]; then |
316 | | - print_message error "No config file found for $current_shell. Checked files: ${config_files[@]}" |
317 | | - exit 1 |
318 | | -fi |
319 | | - |
320 | | -if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then |
321 | | - case $current_shell in |
322 | | - fish) |
323 | | - add_to_path "$config_file" "fish_add_path $INSTALL_DIR" |
324 | | - ;; |
325 | | - zsh) |
326 | | - add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" |
327 | | - ;; |
328 | | - bash) |
329 | | - add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" |
330 | | - ;; |
331 | | - ash) |
332 | | - add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" |
333 | | - ;; |
334 | | - sh) |
335 | | - add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" |
336 | | - ;; |
337 | | - *) |
338 | | - export PATH=$INSTALL_DIR:$PATH |
339 | | - print_message warning "Manually add the directory to $config_file (or similar):" |
340 | | - print_message info " export PATH=$INSTALL_DIR:\$PATH" |
341 | | - ;; |
342 | | - esac |
343 | 387 | fi |
344 | 388 |
|
345 | 389 | if [ -n "${GITHUB_ACTIONS-}" ] && [ "${GITHUB_ACTIONS}" == "true" ]; then |
|