|
@@ -7,7 +7,51 @@ RED='\033[0;31m'
|
|
|
ORANGE='\033[38;5;214m'
|
|
ORANGE='\033[38;5;214m'
|
|
|
NC='\033[0m' # No Color
|
|
NC='\033[0m' # No Color
|
|
|
|
|
|
|
|
|
|
+usage() {
|
|
|
|
|
+ cat <<EOF
|
|
|
|
|
+OpenCode Installer
|
|
|
|
|
+
|
|
|
|
|
+Usage: install.sh [options]
|
|
|
|
|
+
|
|
|
|
|
+Options:
|
|
|
|
|
+ -h, --help Display this help message
|
|
|
|
|
+ -v, --version <version> Install a specific version (e.g., 1.0.180)
|
|
|
|
|
+ --no-modify-path Don't modify shell config files (.zshrc, .bashrc, etc.)
|
|
|
|
|
+
|
|
|
|
|
+Examples:
|
|
|
|
|
+ curl -fsSL https://opencode.ai/install | bash
|
|
|
|
|
+ curl -fsSL https://opencode.ai/install | bash -s -- --version 1.0.180
|
|
|
|
|
+EOF
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
requested_version=${VERSION:-}
|
|
requested_version=${VERSION:-}
|
|
|
|
|
+no_modify_path=false
|
|
|
|
|
+
|
|
|
|
|
+while [[ $# -gt 0 ]]; do
|
|
|
|
|
+ case "$1" in
|
|
|
|
|
+ -h|--help)
|
|
|
|
|
+ usage
|
|
|
|
|
+ exit 0
|
|
|
|
|
+ ;;
|
|
|
|
|
+ -v|--version)
|
|
|
|
|
+ if [[ -n "${2:-}" ]]; then
|
|
|
|
|
+ requested_version="$2"
|
|
|
|
|
+ shift 2
|
|
|
|
|
+ else
|
|
|
|
|
+ echo -e "${RED}Error: --version requires a version argument${NC}"
|
|
|
|
|
+ exit 1
|
|
|
|
|
+ fi
|
|
|
|
|
+ ;;
|
|
|
|
|
+ --no-modify-path)
|
|
|
|
|
+ no_modify_path=true
|
|
|
|
|
+ shift
|
|
|
|
|
+ ;;
|
|
|
|
|
+ *)
|
|
|
|
|
+ echo -e "${ORANGE}Warning: Unknown option '$1'${NC}" >&2
|
|
|
|
|
+ shift
|
|
|
|
|
+ ;;
|
|
|
|
|
+ esac
|
|
|
|
|
+done
|
|
|
|
|
|
|
|
raw_os=$(uname -s)
|
|
raw_os=$(uname -s)
|
|
|
os=$(echo "$raw_os" | tr '[:upper:]' '[:lower:]')
|
|
os=$(echo "$raw_os" | tr '[:upper:]' '[:lower:]')
|
|
@@ -304,42 +348,42 @@ case $current_shell in
|
|
|
;;
|
|
;;
|
|
|
esac
|
|
esac
|
|
|
|
|
|
|
|
-config_file=""
|
|
|
|
|
-for file in $config_files; do
|
|
|
|
|
- if [[ -f $file ]]; then
|
|
|
|
|
- config_file=$file
|
|
|
|
|
- break
|
|
|
|
|
|
|
+if [[ "$no_modify_path" != "true" ]]; then
|
|
|
|
|
+ config_file=""
|
|
|
|
|
+ for file in $config_files; do
|
|
|
|
|
+ if [[ -f $file ]]; then
|
|
|
|
|
+ config_file=$file
|
|
|
|
|
+ break
|
|
|
|
|
+ fi
|
|
|
|
|
+ done
|
|
|
|
|
+
|
|
|
|
|
+ if [[ -z $config_file ]]; then
|
|
|
|
|
+ print_message warning "No config file found for $current_shell. You may need to manually add to PATH:"
|
|
|
|
|
+ print_message info " export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
+ elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
|
|
|
|
|
+ case $current_shell in
|
|
|
|
|
+ fish)
|
|
|
|
|
+ add_to_path "$config_file" "fish_add_path $INSTALL_DIR"
|
|
|
|
|
+ ;;
|
|
|
|
|
+ zsh)
|
|
|
|
|
+ add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
+ ;;
|
|
|
|
|
+ bash)
|
|
|
|
|
+ add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
+ ;;
|
|
|
|
|
+ ash)
|
|
|
|
|
+ add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
+ ;;
|
|
|
|
|
+ sh)
|
|
|
|
|
+ add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
+ ;;
|
|
|
|
|
+ *)
|
|
|
|
|
+ export PATH=$INSTALL_DIR:$PATH
|
|
|
|
|
+ print_message warning "Manually add the directory to $config_file (or similar):"
|
|
|
|
|
+ print_message info " export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
+ ;;
|
|
|
|
|
+ esac
|
|
|
fi
|
|
fi
|
|
|
-done
|
|
|
|
|
-
|
|
|
|
|
-if [[ -z $config_file ]]; then
|
|
|
|
|
- print_message error "No config file found for $current_shell. Checked files: ${config_files[@]}"
|
|
|
|
|
- exit 1
|
|
|
|
|
-fi
|
|
|
|
|
-
|
|
|
|
|
-if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
|
|
|
|
|
- case $current_shell in
|
|
|
|
|
- fish)
|
|
|
|
|
- add_to_path "$config_file" "fish_add_path $INSTALL_DIR"
|
|
|
|
|
- ;;
|
|
|
|
|
- zsh)
|
|
|
|
|
- add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
- ;;
|
|
|
|
|
- bash)
|
|
|
|
|
- add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
- ;;
|
|
|
|
|
- ash)
|
|
|
|
|
- add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
- ;;
|
|
|
|
|
- sh)
|
|
|
|
|
- add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
- ;;
|
|
|
|
|
- *)
|
|
|
|
|
- export PATH=$INSTALL_DIR:$PATH
|
|
|
|
|
- print_message warning "Manually add the directory to $config_file (or similar):"
|
|
|
|
|
- print_message info " export PATH=$INSTALL_DIR:\$PATH"
|
|
|
|
|
- ;;
|
|
|
|
|
- esac
|
|
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${GITHUB_ACTIONS-}" ] && [ "${GITHUB_ACTIONS}" == "true" ]; then
|
|
if [ -n "${GITHUB_ACTIONS-}" ] && [ "${GITHUB_ACTIONS}" == "true" ]; then
|