Last active
October 6, 2016 15:47
-
-
Save hashbrowncipher/211583692b1edff753b185dd08c0469e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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