diff options
-rw-r--r-- | README | 4 | ||||
-rwxr-xr-x | commit.d/10vcs-test (renamed from post-install.d/10vcs-test) | 0 | ||||
-rwxr-xr-x | commit.d/30git-add (renamed from post-install.d/30git-add) | 0 | ||||
-rwxr-xr-x | commit.d/30hg-addremove (renamed from post-install.d/30hg-addremove) | 0 | ||||
-rwxr-xr-x | commit.d/40git-rm (renamed from post-install.d/40git-rm) | 0 | ||||
-rwxr-xr-x | commit.d/50vcs-commit | 18 | ||||
-rw-r--r-- | commit.d/README | 3 | ||||
-rw-r--r-- | debian/changelog | 13 | ||||
-rw-r--r-- | debian/preinst | 25 | ||||
-rwxr-xr-x | etckeeper | 30 | ||||
-rw-r--r-- | etckeeper.1 | 13 | ||||
-rwxr-xr-x | post-install.d/50vcs-commit | 9 | ||||
-rwxr-xr-x | pre-install.d/50uncommitted-changes | 29 | ||||
-rwxr-xr-x | unclean.d/50test | 8 | ||||
-rw-r--r-- | unclean.d/README | 2 |
15 files changed, 110 insertions, 44 deletions
@@ -126,7 +126,7 @@ fixes their permissions: chmod 700 . git clone /etc cd etc - etckeeper init . + etckeeper init -d . chmod 755 .. Another common reason to clone the repository is to make a backup to a @@ -164,7 +164,7 @@ which will save a lot of disk space: Here's how to disable the automatic commits after each apt run, while still letting it git add new files and git rm removed ones: - chmod -x /etc/etckeeper/post-install.d/75vcs-commit + chmod -x /etc/etckeeper/commit.d/50vcs-commit ## inspiration diff --git a/post-install.d/10vcs-test b/commit.d/10vcs-test index ddd4448..ddd4448 100755 --- a/post-install.d/10vcs-test +++ b/commit.d/10vcs-test diff --git a/post-install.d/30git-add b/commit.d/30git-add index 66d96a9..66d96a9 100755 --- a/post-install.d/30git-add +++ b/commit.d/30git-add diff --git a/post-install.d/30hg-addremove b/commit.d/30hg-addremove index 1b999bb..1b999bb 100755 --- a/post-install.d/30hg-addremove +++ b/commit.d/30hg-addremove diff --git a/post-install.d/40git-rm b/commit.d/40git-rm index 3d5289a..3d5289a 100755 --- a/post-install.d/40git-rm +++ b/commit.d/40git-rm diff --git a/commit.d/50vcs-commit b/commit.d/50vcs-commit new file mode 100755 index 0000000..48fa177 --- /dev/null +++ b/commit.d/50vcs-commit @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +message="$1" + +if [ "$VCS" = git ] && [ -d .git ]; then + if [ -n "$message" ]; then + git commit $GIT_COMMIT_OPTIONS -m "$message" + else + git commit $GIT_COMMIT_OPTIONS + fi +elif [ "$VCS" = hg ] && [ -d .hg ]; then + if [ -n "$message" ]; then + hg commit $HG_COMMIT_OPTIONS -m "$message" + else + hg commit $HG_COMMIT_OPTIONS + fi +fi diff --git a/commit.d/README b/commit.d/README new file mode 100644 index 0000000..25d0d45 --- /dev/null +++ b/commit.d/README @@ -0,0 +1,3 @@ +Files in this directory are run when there might be changes to commit. +(Before and after packages are installed, upgraded, etc.) +They should commit changes and new files in /etc to repository. diff --git a/debian/changelog b/debian/changelog index d3585c9..09d6dfa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,16 @@ +etckeeper (0.10) UNRELEASED; urgency=low + + * Convert the directory parameter of etckeeper into "-d directory". + * Pass other patameters on from etckeeper to the .d scripts. + * Stop using run-parts for various reasons. + * Split out a commit.d that contains committing code that's used by + both the pre-install.d and post-install.d scripts. + * Split out an unclean.d that tests if the WC contains uncommitted + changes. + * Add preinst code to remove old post-install.d scripts. + + -- Joey Hess <joeyh@debian.org> Tue, 15 Jan 2008 13:20:29 -0500 + etckeeper (0.9) unstable; urgency=low * Separate debconf use from the main flow of the script so the commit diff --git a/debian/preinst b/debian/preinst index c1fdc27..7caa62d 100644 --- a/debian/preinst +++ b/debian/preinst @@ -17,6 +17,25 @@ prep_mv_conffile() { fi } +# Remove a no-longer used conffile +rm_conffile() { + PKGNAME="$1" + CONFFILE="$2" + + if [ -e "$CONFFILE" ]; then + md5sum="`md5sum \"$CONFFILE\" | sed -e \"s/ .*//\"`" + old_md5sum="`dpkg-query -W -f='${Conffiles}' $PKGNAME | sed -n -e \"\\\\' $CONFFILE'{s/ obsolete$//;s/.* //p}\"`" + if [ "$md5sum" != "$old_md5sum" ]; then + echo "Obsolete conffile $CONFFILE has been modified by you." + echo "Saving as $CONFFILE.dpkg-bak ..." + mv -f "$CONFFILE" "$CONFFILE".dpkg-bak + else + echo "Removing obsolete conffile $CONFFILE ..." + rm -f "$CONFFILE" + fi + fi +} + case "$1" in install|upgrade) if dpkg --compare-versions "$2" le "0.7"; then @@ -31,4 +50,10 @@ install|upgrade) prep_mv_conffile etckeeper "/etc/etckeeper/init.d/$c" done fi + if dpkg --compare-versions "$2" le "0.10"; then + for c in 10vcs-test 30git-add 30hg-addremove 40git-rm; do + rm_conffile etckeeper "/etc/etckeeper/post-install.d/$c" + + done + fi esac @@ -2,6 +2,11 @@ set -e conf=/etc/etckeeper/etckeeper.conf +usage() { + echo "usage: etckeeper command [-d directory]" >&2 + exit 1 +} + if [ -e $conf ]; then . $conf fi @@ -27,8 +32,7 @@ if [ ! -z "$LOWLEVEL_PACKAGE_MANAGER" ]; then fi if [ -z "$1" ]; then - echo "usage: etckeeper command [directory]" >&2 - exit 1 + usage fi command="$1" shift 1 @@ -45,10 +49,26 @@ if [ ! -d "/etc/etckeeper/$command.d" ]; then exit 1 fi -if [ -n "$1" ]; then - cd "$1" +if [ "x$1" = "x-d" ]; then + if [ -n "$2" ]; then + cd "$2" + shift 2 + else + usage + fi else cd /etc fi -run-parts --exit-on-error "/etc/etckeeper/$command.d" +lsscripts() { + perl -e ' + $dir=shift; + print join "\n", grep { ! -d $_ && -x $_ } + grep /^\Q$dir\/\E[-a-zA-Z0-9]+$/, + glob "$dir/*"; + ' "$1" +} + +for script in $(lsscripts "/etc/etckeeper/$command.d"); do + "$script" "$@" +done diff --git a/etckeeper.1 b/etckeeper.1 index cd31b5d..e05cd5f 100644 --- a/etckeeper.1 +++ b/etckeeper.1 @@ -3,12 +3,12 @@ .SH NAME etckeeper \- store /etc in git or mercurial .SH SYNOPSIS -.B etckeeper command [directory] +.B etckeeper command [-d directory] .SH DESCRIPTION etckeeper manages /etc be stored in a git or mercurial repository. By default each of the commands operates on /etc, but a different directory -can be specified as a parameter to operate on a clone of the /etc repository -located elsewhere. +can be specified to operate on a clone of the /etc repository located +elsewhere. .SH COMMANDS .TP .B init @@ -18,6 +18,10 @@ and sets up a git or mercurial repository (depending on the VCS setting in when starting to use etckeeper on a machine. It can also be used to initialise a clone of the /etc repository located elsewhere. .TP +.B commit [message] +Commits changes in /etc to the repository. A commit message can be +specified. +.TP .B pre-commit This is called as a pre-commit hook. It stores metadata and does sanity checks. @@ -31,6 +35,9 @@ packages are installed, upgraded, etc. This is called by apt's DPkg::Post-Invoke hook, or by equivilant hooks of other package managers. It commits changes made by packages into the repository. (You can also call this by hand after running dpkg by hand.) +.TP +.B unclean +This returns true if the directory contains uncommitted changes. .SH FILES /etc/etckeeper/etckeeper.conf is the configuration file. diff --git a/post-install.d/50vcs-commit b/post-install.d/50vcs-commit index 52c6c10..581e310 100755 --- a/post-install.d/50vcs-commit +++ b/post-install.d/50vcs-commit @@ -1,11 +1,6 @@ #!/bin/sh set -e -message="committing changes after $HIGHLEVEL_PACKAGE_MANAGER run" - -if [ "$VCS" = git ] && [ -d .git ]; then - # ignore exit code since it exits nonzero if there is nothing to do - git commit $GIT_COMMIT_OPTIONS -m "$message" || true -elif [ "$VCS" = hg ] && [ -d .hg ]; then - hg commit $HG_COMMIT_OPTIONS -m "$message" || true +if etckeeper unclean; then + etckeeper commit "committing changes after $HIGHLEVEL_PACKAGE_MANAGER run" fi diff --git a/pre-install.d/50uncommitted-changes b/pre-install.d/50uncommitted-changes index bc33ff9..4e573dc 100755 --- a/pre-install.d/50uncommitted-changes +++ b/pre-install.d/50uncommitted-changes @@ -1,14 +1,6 @@ #!/bin/sh set -e -unclean() { - if [ "$VCS" = git ]; then - [ -d .git ] && ! LANG=C git-status 2>&1 | grep -q "working directory clean" - elif [ "$VCS" = hg ]; then - [ -d .hg ] && ! hg status 2>&1 | wc -l | grep -q "^0$" - fi -} - status() { if [ "$VCS" = git ]; then git status @@ -17,23 +9,6 @@ status() { fi } -commit() { - message="$1" - - if [ "$VCS" = git ]; then - git add . - for file in $(git ls-files --deleted); do - if [ ! -d "$file" ]; then - git rm --quiet "$file" - fi - done - git commit $GIT_COMMIT_OPTIONS -m "$message" - elif [ "$VCS" = hg ]; then - hg addremove . - hg commit $HG_COMMIT_OPTIONS -m "$message" - fi -} - if [ "$1" = "ask-debconf" ]; then . /usr/share/debconf/confmodule db_capb escape @@ -60,7 +35,7 @@ elif [ "$1" = "fail-debconf" ]; then db_reset etckeeper/commit_failed || true fi -if unclean; then +if etckeeper unclean; then docommit="true" if [ -e /usr/share/debconf/confmodule ]; then if $0 ask-debconf; then @@ -70,7 +45,7 @@ if unclean; then fi fi if [ "$docommit" = true ]; then - if ! commit "saving uncommitted changes in /etc prior to $HIGHLEVEL_PACKAGE_MANAGER run"; then + if ! etckeeper commit "saving uncommitted changes in /etc prior to $HIGHLEVEL_PACKAGE_MANAGER run"; then if [ -e /usr/share/debconf/confmodule ]; then $0 fail-debconf else diff --git a/unclean.d/50test b/unclean.d/50test new file mode 100755 index 0000000..0495815 --- /dev/null +++ b/unclean.d/50test @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +if [ "$VCS" = git ]; then + [ -d .git ] && ! LANG=C git-status 2>&1 | grep -q "working directory clean" +elif [ "$VCS" = hg ]; then + [ -d .hg ] && ! hg status 2>&1 | wc -l | grep -q "^0$" +fi diff --git a/unclean.d/README b/unclean.d/README new file mode 100644 index 0000000..74bfbdd --- /dev/null +++ b/unclean.d/README @@ -0,0 +1,2 @@ +Files in this directory are used to test if the working copy has +uncommitted changes. |