Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add recursive show and display unmanaged files options

  • Loading branch information...
commit 80f89a4a4c61e8737db1369fcda629841af1dab1 1 parent 454a267
Dean Wilson authored
Showing with 69 additions and 9 deletions.
  1. +61 −9 puppet-ls
  2. +8 −0 puppet-ls-acknowledgements
View
70 puppet-ls
@@ -1,24 +1,76 @@
#!/bin/bash
# tested on 0.25
-# example - puppet-ls /etc/mcollective
+appname=$(basename "$0")
+comm="comm -12"
-target=${1-$(pwd)}
-target=${target%/}
+while getopts "irh" option
+do
+case $option in
+ i ) comm="comm -13" ;;
+ r ) recursive=1 ;;
+ h ) usage ;;
+ * ) usage
+ esac
+done
-appname=$(basename $0)
+# grab the non-getopts option
+shift $(($OPTIND - 1))
+target="${1-$(pwd)}"
+target="${target%/}"
+
+if [ -n "$recursive" ];then
+ lister="find $target"
+else
+ lister="ls -d1 $target/*"
+fi
catalog_filelist=$(mktemp -q /tmp/$appname.XXXXXX)
-ls_filelist=$(mktemp -q /tmp/$appname.XXXXXX)
+lister_filelist=$(mktemp -q /tmp/$appname.XXXXXX)
+
+# better clean up
+trap "rm -f $catalog_filelist $lister_filelist" 0 1 2 15
# get files puppet knows about - you might not need both of these.
(
grep -h "title: /" /var/lib/puppet/client_yaml/catalog/*.yaml | awk '{ print $NF }' ;
- grep '"File\[' /var/lib/puppet/state/state.yaml | sed -e 's/"File\[//' -e 's/\]"://' -e 's/ //g'
+ sed -e '/"File\[/!d' -e 's/"File\[//' -e 's/\]"://' -e 's/ //g' < /var/lib/puppet/state/state.yaml
) | sort > $catalog_filelist
-ls -1 $target/* | sort > $ls_filelist
+$lister | sort > $lister_filelist
+
+$comm $catalog_filelist $lister_filelist
+
+#################################################################
+
+usage () {
+
+cat<<EOU
+$appname - Copyright (c) 2011 Dean Wilson - Licensed under the GPLv2
+
+$appname lists files that puppet isn't currently managing in the given
+directory. Without arguments $appname shows the files in the current
+working directory.
+
+The directory to check should always be the last argument.
+
+Usage: $APPNAME [-r] [-i] [directory]
+ -i
+ Invert the check and show files that puppet isn't managing.
+ -r
+ Show all puppet managed files in the given directory and subdirectories
+ -h
+ This help and usage information.
+
+Usage: $APPNAME
+
+Examples:
+ # show all puppet managed files in the /etc/mcollective directory.
+ $appname /etc/mcollective
-comm -12 $catalog_filelist $ls_filelist
+ # show all unmanaged files in /etc/nagios and any subdirectories
+ $appname -r -i /etc/nagios/
-rm $catalog_filelist $ls_filelist
+EOU
+exit 0
+}
View
8 puppet-ls-acknowledgements
@@ -0,0 +1,8 @@
+These people have helped improve puppet-ls via the gift of code:
+
+Kjetil Torgrim Homme - a number of code cleanups and the "show unmanaged"
+functionatilty. He writes good shell.
+
+Eric Shamow - for the first draft of the recursive management check.
+
+And for that we're thankful.
Please sign in to comment.
Something went wrong with that request. Please try again.