Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Last active January 19, 2024 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h0tw1r3/8819c73915b6eb4c5a929001252f2dd9 to your computer and use it in GitHub Desktop.
Save h0tw1r3/8819c73915b6eb4c5a929001252f2dd9 to your computer and use it in GitHub Desktop.
no requirements ghostbuster for puppet enterprise control-repo modules
#!/bin/bash
#####> BEGIN: script init
set -o pipefail -o errtrace -o errexit -o nounset -o functrace
__traperror() {
local el=${1:=??} ec=${2:=??} lc="$BASH_COMMAND"
printf "ERROR in %s : line %d error %d\\n [%s]\\n" "$0" "$el" "$ec" "$lc" 1>&2
exit "${2:=1}"
}
trap '__traperror ${LINENO} ${?}' ERR
RUN_PATH="${PWD}"
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
finish() {
[[ -n $SCRATCH && -d $SCRATCH ]] && rm -rf "${SCRATCH}"
}
trap finish EXIT
export SCRATCH
SCRIPT_BASENAME=$(basename "$0")
SCRATCH=$(mktemp -d -t "${SCRIPT_BASENAME}".XXXXXXXX)
#####> END: script init
FIND_PATH=$(realpath "${1:-.}")
CHECKS=()
for arg in "$@" ; do
case "$arg" in
classes|defines|facts|functions|hiera_files|files|template|types)
CHECKS+=($arg)
shift ;;
*)
if [ ! -d $arg ] ; then
echo "path does not exist? $arg" ; exit 1
fi
FIND_PATH=$(realpath $arg)
shift ;;
esac
done
echo "search path set to: $FIND_PATH"
if [ ${#CHECKS[@]} -eq 0 ] ; then
CHECKS=(classes defines facts functions hiera_files files template types)
fi
pushd "${SCRATCH}" >/dev/null
PATH=/opt/puppetlabs/puppet/bin:$PATH
PUPPETDB_CONF=${PUPPETDB_CONF:-/etc/puppetlabs/client-tools/puppetdb.conf}
export PE_TOKEN=${PE_TOKEN:-${HOME}/.puppetlabs/token}
export PUPPETDB_CACERT_FILE=$(jq -r .puppetdb.cacert < $PUPPETDB_CONF)
export PUPPETDB_URL=$(jq -r .puppetdb.server_urls[0] < $PUPPETDB_CONF)
cat <<HERE > Gemfile
source 'https://rubygems.org'
gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem 'voxpupuli-puppet-lint-plugins', '~> 5.0', require: false
gem 'puppet-ghostbuster', nil, git: 'https://github.com/h0tw1r3/puppet-ghostbuster', branch: 'optimize', require: false
gem 'puppet', '>= 0', require: false
gem 'facter', '>= 0', require: false
gem 'hiera', '>= 0', require: false
HERE
bundle config set --local path ~/.ghostbuster
bundle config set --local cache_path ~/.ghostbuster/cache
bundle config set --local allow_offline_install true
bundle config set --local cache_all true
bundle config set --local suppress_install_using_messages true
bundle cache
export HIERA_YAML_PATH=${RUN_PATH}/hiera.yaml
CHECKS=$(printf "ghostbuster_%s," "${CHECKS[@]}")
CHECKS=${CHECKS%,}
BASE=$(basename "${FIND_PATH}")
ln -s ${FIND_PATH} ${BASE}
find ./${BASE}/ -type f -not -path '**/.git/**' \
-exec bundle exec puppet-lint --only-checks ${CHECKS} {} \+ | \
tee ${RUN_PATH}/ghostbuster.$$.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment