|
| 1 | +#!/bin/sh |
| 2 | +# TODO(everyone): Keep this script simple and easily auditable. |
| 3 | + |
| 4 | +set -e |
| 5 | + |
| 6 | +if ["$(uname -m)"!="x86_64" ];then |
| 7 | +echo"Error: Unsupported architecture$(uname -m). Only x64 binaries are available."1>&2 |
| 8 | +exit 1 |
| 9 | +fi |
| 10 | + |
| 11 | +if ["$OS"="Windows_NT" ];then |
| 12 | + target="windows-386" |
| 13 | + ext=".zip" |
| 14 | +if!command -v unzip>/dev/null;then |
| 15 | +echo"Error: unzip is required to install coder-cli"1>&2 |
| 16 | +exit 1 |
| 17 | +fi |
| 18 | +else |
| 19 | +if!command -v tar>/dev/null;then |
| 20 | +echo"Error: tar is required to install coder-cli"1>&2 |
| 21 | +exit 1 |
| 22 | +fi |
| 23 | + ext=".tar.gz" |
| 24 | +case$(uname -s)in |
| 25 | + Darwin) target="darwin-amd64" ;; |
| 26 | +*) target="linux-amd64" ;; |
| 27 | +esac |
| 28 | +fi |
| 29 | + |
| 30 | +if [$#-eq 0 ];then |
| 31 | + coder_asset_path=$( |
| 32 | + curl -sSf https://github.com/cdr/coder-cli/releases| |
| 33 | + grep -o"/cdr/coder-cli/releases/download/.*/coder-cli-${target}${ext}"| |
| 34 | + head -n 1 |
| 35 | +) |
| 36 | +if [!"$coder_asset_path" ];then |
| 37 | +echo"Error: Unable to find latest coder-cli release on GitHub."1>&2 |
| 38 | +exit 1 |
| 39 | +fi |
| 40 | + cdr_uri="https://github.com${coder_asset_path}" |
| 41 | +else |
| 42 | + cdr_uri="https://github.com/cdr/coder-cli/releases/download/${1}/coder-cli-${target}${ext}" |
| 43 | +fi |
| 44 | + |
| 45 | +coder_install="${CODER_INSTALL:-$HOME/.coder}" |
| 46 | +bin_dir="$coder_install/bin" |
| 47 | +exe="$bin_dir/coder" |
| 48 | + |
| 49 | +if [!-d"$bin_dir" ];then |
| 50 | + mkdir -p"$bin_dir" |
| 51 | +fi |
| 52 | + |
| 53 | +curl --fail --location --progress-bar --output"$exe$ext""$cdr_uri" |
| 54 | +if ["$ext"=".zip" ];then |
| 55 | + unzip -d"$bin_dir" -o"$exe$ext" |
| 56 | +else |
| 57 | + tar -xzf"$exe$ext" -C"$bin_dir" |
| 58 | +fi |
| 59 | +chmod +x"$exe" |
| 60 | +rm"$exe$ext" |
| 61 | + |
| 62 | +echo"Coder was installed successfully to$exe" |
| 63 | +ifcommand -v coder>/dev/null;then |
| 64 | +echo"Run 'coder --help' to get started" |
| 65 | +else |
| 66 | +case$SHELLin |
| 67 | + /bin/zsh) shell_profile=".zshrc" ;; |
| 68 | +*) shell_profile=".bash_profile" ;; |
| 69 | +esac |
| 70 | +echo"Manually add the directory to your\$HOME/$shell_profile (or similar)" |
| 71 | +echo" export CODER_INSTALL=\"$coder_install\"" |
| 72 | +echo" export PATH=\"\$CODER_INSTALL/bin:\$PATH\"" |
| 73 | +echo"Run '$exe --help' to get started" |
| 74 | +fi |