diff options
-rwxr-xr-x | init.d/20restore-metadata | 8 | ||||
-rwxr-xr-x | pre-commit.d/20store-empty-directory | 28 | ||||
-rwxr-xr-x | pre-commit.d/30store-metadata | 27 | ||||
-rwxr-xr-x | pre-commit.d/40rm-old-metadata | 11 |
4 files changed, 20 insertions, 54 deletions
diff --git a/init.d/20restore-metadata b/init.d/20restore-metadata deleted file mode 100755 index be34bc7..0000000 --- a/init.d/20restore-metadata +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -set -e - -# It's ok to trust that the .fix-metadata file won't do anything shady because, -# as documented, etckeeper-init should only be run on repositories you trust. -if [ -x .fix-metadata ]; then - ./.fix-metadata -fi diff --git a/pre-commit.d/20store-empty-directory b/pre-commit.d/20store-empty-directory deleted file mode 100755 index 22fde89..0000000 --- a/pre-commit.d/20store-empty-directory +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -set -e - -# These version control systems do not track directories, so empty -# directories must be stored specially. -if [ "$VCS" = git ] || [ "$VCS" = hg ]; then - # Make sure the file is not readable by others, since it can leak - # information about contents of non-readable directories in /etc. - umask 077 - - if [ -e .etckeeper ]; then - egrep -v '^mkdir ' .etckeeper > .etckeeper.new || true - fi - find -type d -empty | grep -v /.git/ | grep -v /.hg/ | grep -v /.bzr/ | - sort | sed -e "s/^/mkdir -p '/" -e "s/\$/'/" >> .etckeeper.new - - if [ ! -e .etckeeper ] || ! cmp -s .etckeeper .etckeeper.new ; then - mv -f .etckeeper.new .etckeeper - # stage the file as part of the current commit - if [ "$VCS" = git ]; then - git add .etckeeper - fi - # hg add not done, hg will automatically include the file - # in the current commit - else - rm -f .etckeeper.new - fi -fi 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 diff --git a/pre-commit.d/40rm-old-metadata b/pre-commit.d/40rm-old-metadata deleted file mode 100755 index 8580516..0000000 --- a/pre-commit.d/40rm-old-metadata +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -set -e - -# Remove the .metadata file if we're using .fix-metadata -if [ -f .metadata ] && [ -f .fix-metadata ]; then - # Don't want to do anything permanent if user is mistakenly - # running etckeeper without first setting VCS. - if [ "x$VCS" != "x" ]; then - $VCS rm .metadata - fi -fi |