From 20d7d55942b53bca4def251ce037fc84ff0f5e0d Mon Sep 17 00:00:00 2001 From: Scott Bronson Date: Thu, 20 Mar 2008 02:28:32 -0700 Subject: Store metadata in .etckeeper, not .fix-metadata. --- pre-commit.d/30store-metadata | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'pre-commit.d/30store-metadata') diff --git a/pre-commit.d/30store-metadata b/pre-commit.d/30store-metadata index fbd9096..65040bf 100755 --- a/pre-commit.d/30store-metadata +++ b/pre-commit.d/30store-metadata @@ -15,6 +15,7 @@ filter_unknown() { done } + generate_metadata() { # This function generates the script commands to fix any files # that aren't owner=root, group=root, or mode=0644 or 0755. @@ -24,6 +25,13 @@ generate_metadata() { # but we want find to ignore the VCS files themselves. NOVCS='. -wholename ./.git -prune -o -wholename ./.bzr -prune -o -wholename ./.hg -prune -o' + if [ "$VCS" = git ] || [ "$VCS" = hg ]; then + # These version control systems do not track directories, + # so empty directories must be stored specially. + find $NOVCS -type d -empty | sort | \ + sed -e "s/^/mkdir -p '/" -e "s/\$/'/" + fi + # Find all files and directories that don't have root as the owner find $NOVCS \! -user root -exec stat --format="chown %U {}" {} \; \ | sort | filter_unknown chown owner @@ -47,22 +55,27 @@ generate_metadata() { if [ "$VCS" = git ] || [ "$VCS" = hg ] || [ "$VCS" = bzr ]; then # ensure the file exists so that it will list its own metadata - if [ ! -e .fix-metadata ]; then - touch .fix-metadata + if [ ! -e .etckeeper ]; then + touch .etckeeper # Make sure the file is not readable by others, since it can leak # information about contents of non-readable directories in /etc. - chmod 700 .fix-metadata + chmod 700 .etckeeper fi - echo "# Generated by etckeeper." > .fix-metadata - echo >> .fix-metadata - generate_metadata >> .fix-metadata + echo "# Generated by etckeeper." > .etckeeper + echo >> .etckeeper + generate_metadata >> .etckeeper # stage the file as part of the current commit if [ "$VCS" = git ]; then # this will do nothing if the metadata file is unchanged. - git add .fix-metadata + git add .etckeeper fi # hg and bzr add not done, they will automatically # include the file in the current commit + + # Finally, VCS remove obsolete .metadata (as long as VCS is set) + if [ -f .metadata ] && [ "x$VCS" != "x" ]; then + $VCS rm .metadata + fi fi -- cgit v1.2.3