|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +if [[ "$(uname -s)" != "Darwin" ]]; then |
| 4 | + echo "Only macOS is currently supported." |
| 5 | + exit 1 |
| 6 | +fi |
| 7 | + |
| 8 | +options=("nodejs" "python" "golang" "rust") |
| 9 | +binaries=("node" "python" "go" "rustc") |
| 10 | +choices[0]="*" |
| 11 | + |
| 12 | +menu() { |
| 13 | + echo -e "\nWhich eval types would you like to support?\n" |
| 14 | + |
| 15 | + for i in ${!options[@]}; do |
| 16 | + printf "%d %6s [%s]" $((i + 1)) "${options[i]}" "${choices[i]:- }" |
| 17 | + |
| 18 | + if [[ $i == 0 ]]; then |
| 19 | + printf " (required)" |
| 20 | + fi |
| 21 | + |
| 22 | + printf "\n" |
| 23 | + done |
| 24 | + |
| 25 | + echo |
| 26 | +} |
| 27 | + |
| 28 | +prompt="Type 🔢 to select, 'a' for all, 'q' to quit, ⏎ to continue: " |
| 29 | + |
| 30 | +while menu && read -rp "$prompt" num && [[ "$num" ]]; do |
| 31 | + [[ "$num" == "q" ]] && exit 0 |
| 32 | + |
| 33 | + [[ "$num" == "a" ]] && { |
| 34 | + for i in ${!options[@]}; do |
| 35 | + choices[i]="*" |
| 36 | + done |
| 37 | + |
| 38 | + continue |
| 39 | + } |
| 40 | + |
| 41 | + [[ "$num" != *[![:digit:]]* ]] && |
| 42 | + ((num > 1 && num <= ${#options[@]})) || |
| 43 | + { |
| 44 | + continue |
| 45 | + } |
| 46 | + |
| 47 | + ((num--)) |
| 48 | + [[ "${choices[num]}" ]] && choices[num]="" || choices[num]="*" |
| 49 | +done |
| 50 | + |
| 51 | +empty=true |
| 52 | + |
| 53 | +for i in ${!options[@]}; do |
| 54 | + [[ "${choices[i]}" ]] && { |
| 55 | + empty=false |
| 56 | + break |
| 57 | + } |
| 58 | +done |
| 59 | + |
| 60 | +[[ "$empty" == true ]] && exit 0 |
| 61 | + |
| 62 | +echo -e "\nInstalling dependencies..." |
| 63 | + |
| 64 | +if ! command -v brew &>/dev/null; then |
| 65 | + if [[ -f "/opt/homebrew/bin/brew" ]]; then |
| 66 | + echo "Homebrew is installed but not in your PATH" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + |
| 70 | + read -p "Homebrew (https://brew.sh) is required. Install it? (Y/n): " install_brew |
| 71 | + |
| 72 | + if [[ "$install_brew" =~ ^[Yy]|^$ ]]; then |
| 73 | + echo "Installing Homebrew..." |
| 74 | + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 75 | + # Can be undone with: |
| 76 | + # /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" && sudo rm -rvf /opt/homebrew |
| 77 | + |
| 78 | + if [[ "$SHELL" == "/bin/zsh" ]] && ! grep -q 'eval "$(/opt/homebrew/bin/brew shellenv)"' ~/.zprofile; then |
| 79 | + echo '[[ -s "/opt/homebrew/bin/brew" ]] && eval "$(/opt/homebrew/bin/brew shellenv)"' >>~/.zprofile |
| 80 | + elif [[ "$SHELL" == "/bin/bash" ]] && ! grep -q 'eval "$(/opt/homebrew/bin/brew shellenv)"' ~/.bash_profile; then |
| 81 | + echo '[[ -s "/opt/homebrew/bin/brew" ]] && eval "$(/opt/homebrew/bin/brew shellenv)"' >>~/.bash_profile |
| 82 | + fi |
| 83 | + |
| 84 | + if [[ "$SHELL" == "/bin/zsh" ]]; then |
| 85 | + eval "$(/opt/homebrew/bin/brew shellenv)" |
| 86 | + elif [[ "$SHELL" == "/bin/bash" ]]; then |
| 87 | + eval "$(/opt/homebrew/bin/brew shellenv)" |
| 88 | + fi |
| 89 | + |
| 90 | + echo "✅ Homebrew is installed" |
| 91 | + else |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | +else |
| 95 | + BREW_VERSION=$(brew --version) |
| 96 | + echo "✅ Homebrew is installed ($BREW_VERSION)" |
| 97 | +fi |
| 98 | + |
| 99 | +ASDF_PATH="$(brew --prefix asdf)/libexec/asdf.sh" |
| 100 | + |
| 101 | +if ! command -v asdf &>/dev/null; then |
| 102 | + if [[ -f "$ASDF_PATH" ]]; then |
| 103 | + echo "asdf is installed but not in your PATH" |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | + |
| 107 | + read -p "asdf (https://asdf-vm.com) is required. Install it? (Y/n): " install_asdf |
| 108 | + # Can be undone with: |
| 109 | + # rm -rvf ~/.asdf |
| 110 | + |
| 111 | + if [[ "$install_asdf" =~ ^[Yy]|^$ ]]; then |
| 112 | + echo "Installing asdf..." |
| 113 | + brew install asdf |
| 114 | + |
| 115 | + . "$ASDF_PATH" |
| 116 | + |
| 117 | + if [[ "$SHELL" == "/bin/zsh" ]] && ! grep -q 'source "$(brew --prefix asdf)/libexec/asdf.sh"' ~/.zshrc; then |
| 118 | + echo '[[ -s "/opt/homebrew/bin/brew" ]] && [[ -s "$(brew --prefix asdf)/libexec/asdf.sh" ]] && source "$(brew --prefix asdf)/libexec/asdf.sh"' >>~/.zprofile |
| 119 | + elif [[ "$SHELL" == "/bin/bash" ]] && ! grep -q 'source "$(brew --prefix asdf)/libexec/asdf.sh"' ~/.bash_profile; then |
| 120 | + echo '[[ -s "/opt/homebrew/bin/brew" ]] && [[ -s "$(brew --prefix asdf)/libexec/asdf.sh" ]] && source "$(brew --prefix asdf)/libexec/asdf.sh"' >>~/.bash_profile |
| 121 | + fi |
| 122 | + |
| 123 | + echo "✅ asdf is installed" |
| 124 | + else |
| 125 | + exit 1 |
| 126 | + fi |
| 127 | +else |
| 128 | + ASDF_VERSION=$(asdf --version) |
| 129 | + echo "✅ asdf is installed ($ASDF_VERSION)" |
| 130 | +fi |
| 131 | + |
| 132 | +for i in "${!options[@]}"; do |
| 133 | + [[ "${choices[i]}" ]] || continue |
| 134 | + |
| 135 | + plugin="${options[$i]}" |
| 136 | + binary="${binaries[$i]}" |
| 137 | + |
| 138 | + if ! asdf plugin list | grep -q "^${plugin}$" && ! command -v "${binary[$i]}" &>/dev/null; then |
| 139 | + asdf plugin add "${plugin}" |
| 140 | + |
| 141 | + if ! asdf plugin list | grep -q "^${plugin}$"; then |
| 142 | + echo "Failed to install ${plugin} asdf plugin. Please install it manually." |
| 143 | + exit 1 |
| 144 | + else |
| 145 | + echo "✅ asdf ${plugin} plugin installed" |
| 146 | + fi |
| 147 | + fi |
| 148 | + |
| 149 | + if [[ "${plugin}" == "nodejs" ]] && ! command -v node &>/dev/null; then |
| 150 | + asdf install nodejs v20.18.1 |
| 151 | + asdf set nodejs v20.18.1 |
| 152 | + NODE_VERSION=$(node --version) |
| 153 | + echo "✅ Node.js is installed ($NODE_VERSION)" |
| 154 | + elif [[ "${plugin}" == "nodejs" ]]; then |
| 155 | + NODE_VERSION=$(node --version) |
| 156 | + echo "✅ Node.js is installed ($NODE_VERSION)" |
| 157 | + fi |
| 158 | + |
| 159 | + if [[ "${plugin}" == "python" ]] && ! command -v python &>/dev/null; then |
| 160 | + asdf install python 3.13.2 |
| 161 | + asdf set python 3.13.2 |
| 162 | + PYTHON_VERSION=$(python --version) |
| 163 | + echo "✅ Python is installed ($PYTHON_VERSION)" |
| 164 | + elif [[ "${plugin}" == "python" ]]; then |
| 165 | + PYTHON_VERSION=$(python --version) |
| 166 | + echo "✅ Python is installed ($PYTHON_VERSION)" |
| 167 | + fi |
| 168 | + |
| 169 | + if [[ "${plugin}" == "golang" ]] && ! command -v go &>/dev/null; then |
| 170 | + asdf install golang 1.24.2 |
| 171 | + asdf set golang 1.24.2 |
| 172 | + GO_VERSION=$(go version) |
| 173 | + echo "✅ Go is installed ($GO_VERSION)" |
| 174 | + elif [[ "${plugin}" == "golang" ]]; then |
| 175 | + GO_VERSION=$(go version) |
| 176 | + echo "✅ Go is installed ($GO_VERSION)" |
| 177 | + fi |
| 178 | + |
| 179 | + if [[ "${plugin}" == "rust" ]] && ! command -v rustc &>/dev/null; then |
| 180 | + asdf install rust 1.85.1 |
| 181 | + asdf set rust 1.85.1 |
| 182 | + RUST_VERSION=$(rustc --version) |
| 183 | + echo "✅ Rust is installed ($RUST_VERSION)" |
| 184 | + elif [[ "${plugin}" == "rust" ]]; then |
| 185 | + RUST_VERSION=$(rustc --version) |
| 186 | + echo "✅ Rust is installed ($RUST_VERSION)" |
| 187 | + fi |
| 188 | +done |
| 189 | + |
| 190 | +if ! command -v pnpm &>/dev/null; then |
| 191 | + brew install pnpm |
| 192 | + PNPM_VERSION=$(pnpm --version) |
| 193 | + echo "✅ pnpm is installed ($PNPM_VERSION)" |
| 194 | +else |
| 195 | + PNPM_VERSION=$(pnpm --version) |
| 196 | + echo "✅ pnpm is installed ($PNPM_VERSION)" |
| 197 | +fi |
| 198 | + |
| 199 | +pnpm install |
0 commit comments