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.

73 lines
2.3 KiB

  1. # This script generates an install.sh file which can be used to install
  2. # puppet-agent on supported FOSS POSIX platforms.
  3. #
  4. # The script leverages tasks from the puppet_agent and facts modules, and
  5. # attempts to change as few things as possible.
  6. # we just need the variables from here
  7. facts_script = `sed '/munge_name "$family"/q' < modules/facts/tasks/bash.sh`
  8. install_script = File.read('modules/puppet_agent/tasks/install_shell.sh')
  9. .sub('[ -f "$PT__installdir/facts/tasks/bash.sh" ]', 'true')
  10. .sub('$(bash $PT__installdir/facts/tasks/bash.sh "platform")', '$ID')
  11. .sub('$(bash $PT__installdir/facts/tasks/bash.sh "release")', '$full')
  12. File.write('install.sh', <<-SH)
  13. #!/usr/bin/env bash
  14. beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
  15. function usage()
  16. {
  17. cat << HEREDOC
  18. Usage: install.sh [--version VERSION] [--collection COLLECTION] [--cleanup] [--noop]
  19. optional arguments:
  20. -h, --help show this help message and exit
  21. -v, --version VERSION install a specific puppet-agent version
  22. -c, --collection COLLECTION install a specific puppet-agent collection (e.g. puppet7)
  23. -n, --noop do a dry run, do not change any files
  24. --cleanup remove the puppetlabs repository after installation finishes
  25. HEREDOC
  26. }
  27. while [[ "$#" -gt 0 ]]; do
  28. case $1 in
  29. -v|--version) PT_version="$2"; shift ;
  30. if beginswith "6." "$PT_version"; then
  31. PT_collection="puppet6"
  32. elif beginswith "7." "$PT_version"; then
  33. PT_collection="puppet7"
  34. else
  35. PT_collection="puppet"
  36. fi ;;
  37. -c|--collection) PT_collection="$2"; shift ;;
  38. --cleanup) PT_cleanup=true; shift ;;
  39. -n|--noop) PT__noop=true; shift ;;
  40. -h|--help) usage; exit ;;
  41. *) echo "Unknown parameter passed: $1"; usage; exit 1 ;;
  42. esac
  43. shift
  44. done
  45. # shellcheck disable=SC1000-SC9999
  46. {
  47. #{facts_script}
  48. #{install_script}
  49. }
  50. if [[ $PT__noop != true ]]; then
  51. if [[ $PT_cleanup == true ]]; then
  52. info "Cleanup requested, removing ${collection}-release repository..."
  53. case $platform in
  54. SLES|el|Amzn|"Amazon Linux"|Fedora)
  55. rpm -e --allmatches ${collection}-release
  56. ;;
  57. Debian|LinuxMint|Linuxmint|Ubuntu)
  58. apt-get purge ${collection}-release -y
  59. ;;
  60. esac
  61. fi
  62. fi
  63. SH