install.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # Script to install the Porter CLI on macOS, Linux, and WSL
  3. osname=""
  4. check_prereqs() {
  5. command -v curl >/dev/null 2>&1 || { echo "[ERROR] curl is required to install the Porter CLI." >&2; exit 1; }
  6. command -v unzip >/dev/null 2>&1 || { echo "[ERROR] unzip is required to install the Porter CLI." >&2; exit 1; }
  7. }
  8. download_and_install() {
  9. check_prereqs
  10. echo "[INFO] Since the Porter CLI gets installed in /usr/local/bin, you may be asked to input your password."
  11. echo "[INFO] Please make sure /usr/local/bin is included in your PATH."
  12. porter_version="{{ .TagName }}"
  13. if [[ -n "$PORTER_VERSION" ]]; then
  14. echo "[INFO] Using $PORTER_VERSION override instead of $porter_version"
  15. porter_version="$PORTER_VERSION"
  16. fi
  17. curl -L "https://github.com/porter-dev/porter/releases/download/${porter_version}/porter_${porter_version}_${osname}_x86_64.zip" --output porter.zip
  18. unzip -o -a porter.zip
  19. rm porter.zip
  20. chmod +x ./porter
  21. sudo mv ./porter /usr/local/bin/porter
  22. command -v porter >/dev/null 2>&1 || { echo "[ERROR] There was an error installing the Porter CLI. Please try again." >&2; exit 1; }
  23. exit
  24. }
  25. if [[ "$OSTYPE" == "linux-gnu"* ]]; then
  26. if uname -a | grep -q '^Linux.*Microsoft'; then
  27. echo "[WARNING] WSL support is experimental and may result in crashes."
  28. fi
  29. osname="Linux"
  30. download_and_install
  31. elif [[ "$OSTYPE" == "darwin"* ]]; then
  32. osname="Darwin"
  33. download_and_install
  34. fi
  35. echo "[ERROR] Unsupported operating system."
  36. exit 1