install.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. curl -L $(curl -s https://api.github.com/repos/porter-dev/porter/releases/latest | grep "browser_download_url.*/porter_.*_${osname}_x86_64\.zip" | cut -d ":" -f 2,3 | tr -d \") --output porter.zip
  12. unzip -a porter.zip
  13. rm porter.zip
  14. chmod +x ./porter
  15. sudo mv ./porter /usr/local/bin/porter
  16. command -v porter >/dev/null 2>&1 || { echo "[ERROR] There was an error installing the Porter CLI. Please try again." >&2; exit 1; }
  17. exit
  18. }
  19. if [[ "$OSTYPE" == "linux-gnu"* ]]; then
  20. if uname -a | grep -q '^Linux.*Microsoft'; then
  21. echo "[WARNING] WSL support is experimental and may result in crashes."
  22. fi
  23. osname="Linux"
  24. download_and_install
  25. elif [[ "$OSTYPE" == "darwin"* ]]; then
  26. osname="Darwin"
  27. download_and_install
  28. fi
  29. echo "[ERROR] Unsupported operating system."
  30. exit 1