You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9 KiB

  1. #!/usr/bin/env bash
  2. INSTALL_OPTIONS=( "$@" )
  3. PUPPET_BIN=/opt/puppetlabs/bin/puppet
  4. beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
  5. # Check whether a command exists - returns 0 if it does, 1 if it does not
  6. exists() {
  7. if command -v "$1" >/dev/null 2>&1
  8. then
  9. return 0
  10. else
  11. return 1
  12. fi
  13. }
  14. while [[ "$#" -gt 0 ]]; do
  15. case $1 in
  16. -v|--version) EXPECTED_VERSION="$2"; shift ;;
  17. -c|--collection) EXPECTED_COLLECTION="$2"; shift;
  18. case $EXPECTED_COLLECTION in
  19. puppet|puppet-nightly) EXPECTED_VERSION="7." ;;
  20. puppet6|puppet6-nightly) EXPECTED_VERSION="6." ;;
  21. puppet7|puppet7-nightly) EXPECTED_VERSION="7." ;;
  22. esac
  23. ;;
  24. --cleanup) EXPECT_CLEANUP=true; shift ;;
  25. *) echo "Unknown parameter passed: $1"; usage; exit 1 ;;
  26. esac
  27. shift
  28. done
  29. curl -sSL https://raw.githubusercontent.com/puppetlabs/install-puppet/main/install.sh | bash -s -- "${INSTALL_OPTIONS[@]}"
  30. if [ -n "$EXPECTED_VERSION" ]; then
  31. if ! exists $PUPPET_BIN; then
  32. echo "ERROR: puppet executable not found under $(dirname $PUPPET_BIN)"
  33. exit 1
  34. fi
  35. echo "INFO: running $PUPPET_BIN --version"
  36. ACTUAL_VERSION=$($PUPPET_BIN --version)
  37. if ! beginswith "$EXPECTED_VERSION" "$ACTUAL_VERSION"; then
  38. echo "ERROR: expected version to begin with $EXPECTED_VERSION but got $ACTUAL_VERSION"
  39. exit 1
  40. fi
  41. fi
  42. if [[ $EXPECT_CLEANUP == true ]]; then
  43. if exists rpm; then
  44. if rpm -q "${EXPECTED_COLLECTION}-release"; then
  45. echo "ERROR: cleanup requested but $EXPECTED_COLLECTION-release repo was not removed"
  46. exit 1
  47. fi
  48. elif exists dpkg; then
  49. if dpkg -l "${EXPECTED_COLLECTION}-release"; then
  50. echo "ERROR: cleanup requested but $EXPECTED_COLLECTION-release repo was not removed/purged"
  51. exit 1
  52. fi
  53. else
  54. echo "INFO: no rpm/dpkg found; don't know how to cleanup repos"
  55. exit 1
  56. fi
  57. fi