#!/usr/bin/env bash set -euo pipefail if [[ ${OS:-} = Windows_NT ]]; then echo 'error: Windows support will resume shortly' exit 1 fi # replaced by CI on each release LATEST_VERSION="0.6.0" # Reset Color_Off='' # Regular Colors Red='' Green='' Dim='' # White # Bold Bold_White='' Bold_Green='' if [[ -t 1 ]]; then # Reset Color_Off='\033[0m' # Text Reset # Regular Colors Red='\033[0;31m' # Red Green='\033[0;32m' # Green Dim='\033[0;2m' # White # Bold Bold_Green='\033[1;32m' # Bold Green Bold_White='\033[1m' # Bold White fi error() { echo -e "${Red}error${Color_Off}:" "$@" >&2 exit 1 } info() { echo -e "${Dim}$* ${Color_Off}" } info_bold() { echo -e "${Bold_White}$* ${Color_Off}" } success() { echo -e "${Green}$* ${Color_Off}" } if [[ $# -gt 1 ]]; then error "Too many arguments, only one argument is allowed (the tag version of nexus to install, e.g. '0.60.0')" fi case $(uname -ms) in 'Darwin x86_64') target=macos-x86_64 ;; 'Darwin arm64') target=macos-aarch64 ;; 'Linux aarch64' | 'Linux arm64') target=linux-aarch64 ;; 'Linux x86_64' | *) target=linux-x86_64 ;; esac if [[ $target = darwin-x64 ]]; then # Is this process running in Rosetta? # redirect stderr to devnull to avoid error message when not running in Rosetta if [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; then target=darwin-aarch64 info "Your shell is running in Rosetta 2. Downloading nexus for $target instead" fi fi GITHUB="https://github.com" github_repo="$GITHUB/grafbase/nexus" if [[ $# = 0 ]]; then nexus_uri=$github_repo/releases/download/$LATEST_VERSION/nexus-$LATEST_VERSION-$target else nexus_uri=$github_repo/releases/download/$1/nexus-$1-$target fi install_dir=$HOME/.nexus bin_dir=$install_dir/bin exe=$bin_dir/nexus if [[ ! -d $bin_dir ]]; then mkdir -p "$bin_dir" || error "Failed to create install directory \"$bin_dir\"" fi echo "Downloading $nexus_uri" curl --fail --location --progress-bar --output "$exe" "$nexus_uri" || error "Failed to download nexus from \"$nexus_uri\"" chmod +x "$exe" || error 'Failed to set permissions on nexus executable' tildify() { if [[ $1 = $HOME/* ]]; then local replacement=\~/ echo "${1/$HOME\//$replacement}" else echo "$1" fi } success "nexus was installed successfully to $Bold_Green$(tildify "$exe")" if command -v nexus >/dev/null; then echo "Run 'nexus --help' to get started" exit fi refresh_command='' tilde_bin_dir=$(tildify "$bin_dir") quoted_install_dir=\"${install_dir//\"/\\\"}\" if [[ $quoted_install_dir = \"$HOME/* ]]; then quoted_install_dir=${quoted_install_dir/$HOME\//\$HOME/} fi echo case $(basename "$SHELL") in fish) commands=( "set --export PATH $bin_dir \$PATH" ) fish_config=$HOME/.config/fish/config.fish tilde_fish_config=$(tildify "$fish_config") if [[ -w $fish_config ]]; then { echo -e '\n# nexus' for command in "${commands[@]}"; do echo "$command" done } >>"$fish_config" info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_fish_config\"" refresh_command="source $tilde_fish_config" else echo "Manually add the directory to $tilde_fish_config (or similar):" for command in "${commands[@]}"; do info_bold " $command" done fi ;; zsh) commands=( "export PATH=\"$bin_dir:\$PATH\"" ) zsh_config=$HOME/.zshrc tilde_zsh_config=$(tildify "$zsh_config") if [[ -w $zsh_config ]]; then { echo -e '\n# nexus' for command in "${commands[@]}"; do echo "$command" done } >>"$zsh_config" info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_zsh_config\"" refresh_command="exec $SHELL" else echo "Manually add the directory to $tilde_zsh_config (or similar):" for command in "${commands[@]}"; do info_bold " $command" done fi ;; bash) commands=( "export PATH=$bin_dir:\$PATH" ) bash_configs=( "$HOME/.bashrc" "$HOME/.bash_profile" ) if [[ ${XDG_CONFIG_HOME:-} ]]; then bash_configs+=( "$XDG_CONFIG_HOME/.bash_profile" "$XDG_CONFIG_HOME/.bashrc" "$XDG_CONFIG_HOME/bash_profile" "$XDG_CONFIG_HOME/bashrc" ) fi set_manually=true for bash_config in "${bash_configs[@]}"; do tilde_bash_config=$(tildify "$bash_config") if [[ -w $bash_config ]]; then { echo -e '\n# nexus' for command in "${commands[@]}"; do echo "$command" done } >>"$bash_config" info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_bash_config\"" refresh_command="source $bash_config" set_manually=false break fi done if [[ $set_manually = true ]]; then echo "Manually add the directory to $tilde_bash_config (or similar):" for command in "${commands[@]}"; do info_bold " $command" done fi ;; *) echo 'Manually add the directory to ~/.bashrc (or similar):' info_bold " export PATH=\"$bin_dir:\$PATH\"" ;; esac echo info "To get started, run:" echo if [[ $refresh_command ]]; then info_bold " $refresh_command" fi info_bold " nexus --help"