|
| 1 | +#!/bin/sh |
| 2 | +# Based on Deno installer. Copyright 2019 the Deno authors. All rights reserved. MIT license. |
| 3 | +# TODO(everyone): Keep this script simple and easily auditable. |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +if [ "$OS" = "Windows_NT" ]; then |
| 8 | + target="windows" |
| 9 | + echo "Windows is not supported at the moment, sorry" >&2 |
| 10 | + exit 1 |
| 11 | +else |
| 12 | + case $(uname -sm) in |
| 13 | + "Darwin x86_64") |
| 14 | + target="macos" |
| 15 | + ;; |
| 16 | + "Darwin arm64") |
| 17 | + target="macos-arm" |
| 18 | + echo "MacOSX on arm is not supported at the moment, sorry" >&2 |
| 19 | + exit 1 |
| 20 | + ;; |
| 21 | + *) |
| 22 | + target="linux" |
| 23 | + ;; |
| 24 | + esac |
| 25 | +fi |
| 26 | + |
| 27 | +LATEST_REL_URI="https://github.com/deepinfra/deepctl/releases/latest/download" |
| 28 | + |
| 29 | +if [ $# -eq 0 ]; then |
| 30 | + SOURCE_URI="$LATEST_REL_URI/deepctl-${target}" |
| 31 | +else |
| 32 | + SOURCE_URI="https://github.com/deepinfra/deepctl/releases/download/${1}/deepctl-${target}" |
| 33 | +fi |
| 34 | + |
| 35 | +EXE_NAME="${DEEPCTL_EXE_NAME:-deepctl}" |
| 36 | +DEEPCTL_INSTALL="${DEEPCTL_INSTALL:-/usr/local/bin}" |
| 37 | +EXE_TARGET="$DEEPCTL_INSTALL/$EXE_NAME" |
| 38 | + |
| 39 | +if [ "${DEEPCTL_INSTALL#$HOME}" != "$DEEPCTL_INSTALL" ]; then |
| 40 | + # assume subdirs of $HOME are writable without sudo |
| 41 | + MAYSUDO="env --" |
| 42 | +else |
| 43 | + # assume everything outside $HOME requires sudo |
| 44 | + echo -e "\nYou may be prompted for sudo password to write $EXE_TARGET" >&2 |
| 45 | + echo -e "To change the install folder you can set \$DEEPCTL_INSTALL:\n" >&2 |
| 46 | + echo -e " curl $LATEST_REL_URI/install.sh | DEEPCTL_INSTALL=another/dir bash\n" >&2 |
| 47 | + MAYSUDO="sudo" |
| 48 | +fi |
| 49 | + |
| 50 | +if [ ! -d "$DEEPCTL_INSTALL" ]; then |
| 51 | + $MAYSUDO mkdir -p "$DEEPCTL_INSTALL" |
| 52 | +fi |
| 53 | + |
| 54 | +$MAYSUDO curl --fail --location --progress-bar --output "$EXE_TARGET" "$SOURCE_URI" |
| 55 | +$MAYSUDO chmod +x "$EXE_TARGET" |
| 56 | + |
| 57 | +echo "deepctl was installed successfully to $EXE_TARGET" |
| 58 | +if ! command -v "$EXE_NAME" >/dev/null; then |
| 59 | + case $SHELL in |
| 60 | + /bin/zsh) shell_profile=".zshrc" ;; |
| 61 | + *) shell_profile=".bashrc" ;; |
| 62 | + esac |
| 63 | + echo "Manually add the directory to your \$HOME/$shell_profile (or similar)" |
| 64 | + echo " echo 'export PATH=\"$DEEPCTL_INSTALL:\$PATH\"' >> \$HOME/$shell_profile" |
| 65 | + echo " export PATH=\"$DEEPCTL_INSTALL:\$PATH\"" |
| 66 | +fi |
| 67 | +echo "Run '$EXE_NAME --help' to get started" |
0 commit comments