Skip to content

Instantly share code, notes, and snippets.

@hashbrowncipher
Last active October 6, 2016 15:47
Show Gist options
  • Save hashbrowncipher/211583692b1edff753b185dd08c0469e to your computer and use it in GitHub Desktop.
Save hashbrowncipher/211583692b1edff753b185dd08c0469e to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script is designed to give an overview of which files are present
# in a directory which Puppet does not manage. It isn't perfect, but it
# works reasonably well.
# Specifically, it doesn't understand whether a directory contains
# subdirectories that shouldn't be purged, and it doesn't query the Puppet
# fileserver.
set -o errexit
set -o nounset
set -o pipefail
hostname=$(hostname -f)
search=${1%/}
existing=$(mktemp -t "analyze_cruft.XXXXXX")
find "${search}" -maxdepth 1 | sort > "${existing}"
catalog=$(mktemp -t "analyze_cruft.XXXXXX")
jq -r '.data.resources[] | select(.type == "File" and .ensure != "absent") | .parameters.path // .title' "/var/lib/puppet/client_data/catalog/${hostname}.json" \
| grep '^'"$search" | sort > "${catalog}"
join -v1 "${existing}" "${catalog}"
rm "${existing}" "${catalog}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment