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.

68 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. bash install.sh "${INSTALL_OPTIONS[@]}"
  30. # curl -sSL https://raw.githubusercontent.com/puppetlabs/install-puppet/main/install.sh | bash -s -- "${INSTALL_OPTIONS[@]}"
  31. if [ -n "$EXPECTED_VERSION" ]; then
  32. if ! exists $PUPPET_BIN; then
  33. echo "ERROR: puppet executable not found under $(dirname $PUPPET_BIN)"
  34. exit 1
  35. fi
  36. echo "INFO: running $PUPPET_BIN --version"
  37. ACTUAL_VERSION=$($PUPPET_BIN --version)
  38. if ! beginswith "$EXPECTED_VERSION" "$ACTUAL_VERSION"; then
  39. echo "ERROR: expected version to begin with $EXPECTED_VERSION but got $ACTUAL_VERSION"
  40. exit 1
  41. fi
  42. fi
  43. if [[ $EXPECT_CLEANUP == true ]]; then
  44. if exists rpm; then
  45. if rpm -q "${EXPECTED_COLLECTION}-release"; then
  46. echo "ERROR: cleanup requested but $EXPECTED_COLLECTION-release repo was not removed"
  47. exit 1
  48. fi
  49. elif exists dpkg; then
  50. if dpkg -l "${EXPECTED_COLLECTION}-release"; then
  51. echo "ERROR: cleanup requested but $EXPECTED_COLLECTION-release repo was not removed/purged"
  52. exit 1
  53. fi
  54. else
  55. echo "INFO: no rpm/dpkg found; don't know how to cleanup repos"
  56. exit 1
  57. fi
  58. fi