2
0

install.sh 1.4 KB

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