Permalink
Browse files

Merge branch 'hg'

Significantly refactored
  • Loading branch information...
2 parents 69739dd + fd4a851 commit 788ae5a34c0fad2e3c0788a745400a138d735195 Joey Hess committed Jan 4, 2008
View
@@ -3,16 +3,26 @@
CONFFILE=etckeeper.conf
include $(CONFFILE)
+DESTDIR?=
+prefix=/usr
+bindir=${prefix}/bin
+etcdir=/etc
+mandir=${prefix}/share/man
+
+INSTALL=install
+INSTALL_EXE=${INSTALL} -D
+INSTALL_DATA=${INSTALL} -m 0644 -D
+
install:
- mkdir -p $(PREFIX)/etc/etckeeper/
- cp -a *.d $(PREFIX)/etc/etckeeper/
- cp $(CONFFILE) $(PREFIX)/etc/etckeeper/etckeeper.conf
- install -D etckeeper $(PREFIX)/usr/bin/etckeeper
- install -m 0644 -D etckeeper.1 $(PREFIX)/usr/share/man/man1/etckeeper.1
- install -m 0644 -D bash_completion $(PREFIX)/etc/bash_completion.d/etckeeper
+ mkdir -p $(DESTDIR)$(etcdir)/etckeeper/
+ cp -a *.d $(DESTDIR)$(etcdir)/etckeeper/
+ $(INSTALL_DATA) $(CONFFILE) $(DESTDIR)$(etcdir)/etckeeper/etckeeper.conf
+ $(INSTALL_EXE) etckeeper $(DESTDIR)$(bindir)/etckeeper
+ $(INSTALL_DATA) etckeeper.1 $(DESTDIR)$(mandir)/man1/etckeeper.1
+ $(INSTALL_DATA) bash_completion $(DESTDIR)$(etcdir)/bash_completion.d/etckeeper
ifeq ($(HIGHLEVEL_PACKAGE_MANAGER),apt))
- install -m 0644 -D apt.conf $(PREFIX)/etc/apt/apt.conf.d/05etckeeper
+ $(INSTALL_DATA) apt.conf $(DESTDIR)$(etcdir)/apt/apt.conf.d/05etckeeper
endif
ifeq ($(LOWLEVEL_PACKAGE_MANAGER),pacman-g2))
- install -m 0644 -D pacman-g2.hook $(PREFIX)/etc/pacman-g2/hooks/etckeeper
+ $(INSTALL_DATA) pacman-g2.hook $(DESTDIR)$(etcdir)/etc/pacman-g2/hooks/etckeeper
endif
View
@@ -5,4 +5,4 @@ _etckeeper() {
COMPREPLY=( $( compgen -W '$(cd /etc/etckeeper/; for i in *.d/; do echo ${i%.d/}; done)' -- $cur ) );
}
-complete -F _etckeeper etckeeper
+complete -F _etckeeper etckeeper
View
@@ -1,13 +1,24 @@
#!/bin/sh
set -e
+conf=/etc/etckeeper/etckeeper.conf
-if [ -e /etc/etckeeper/etckeeper.conf ]; then
- . /etc/etckeeper/etckeeper.conf
+if [ -e $conf ]; then
+ . $conf
fi
+if [ -z "$VCS" ]; then
+ echo "Please configure a VCS in $conf" >&2
+ exit 1
+fi
+export VCS
+
if [ ! -z "$GIT_COMMIT_OPTIONS" ]; then
export GIT_COMMIT_OPTIONS
fi
+if [ ! -z "$HG_COMMIT_OPTIONS" ]; then
+ export HG_COMMIT_OPTIONS
+fi
+
if [ ! -z "$HIGHLEVEL_PACKAGE_MANAGER" ]; then
export HIGHLEVEL_PACKAGE_MANAGER
fi
View
@@ -1,8 +1,15 @@
+# The VCS to use.
+# VCS="hg"
+VCS="git"
+
# Options passed to git commit when run by etckeeper.
# You could for exemple use "-e" if you want to edit all commit messages
# before committing.
#GIT_COMMIT_OPTIONS="-e"
+# Options passed to hg commit when run by etckeeper.
+#HG_COMMIT_OPTIONS=""
+
# The high-level package manager that's being used.
HIGHLEVEL_PACKAGE_MANAGER=apt
View
@@ -1,6 +0,0 @@
-#!/bin/sh
-set -e
-if [ ! -e .git ]; then
- git init
- echo "$(hostname) /etc repository" > .git/description
-fi
View
@@ -0,0 +1,11 @@
+#!/bin/sh
+set -e
+
+if [ "$VCS" = git ] && [ ! -e .git ]; then
+ git init
+ echo "$(hostname) /etc repository" > .git/description
+elif [ "$VCS" = hg ] && [ ! -e .hg ]; then
+ hg init
+ echo "[web]" > .hg/hgrc
+ echo "description = $(hostname) /etc repository" >> .hg/hgrc
+fi
View
@@ -1,34 +0,0 @@
-#!/bin/sh
-set -e
-if [ ! -e .gitignore ]; then
- if [ "$LOWLEVEL_PACKAGE_MANAGER" = dpkg ]; then
- cat >.gitignore <<EOF
-# new and old versions of conffiles, stored by dpkg
-*.dpkg-*
-EOF
- fi
- if [ "$LOWLEVEL_PACKAGE_MANAGER" = "pacman-g2" ]; then
- cat >.gitignore <<EOF
-# new and old versions of conffiles, stored by pacman
-*.pacnew
-*.pacorig
-*.pacsave
-EOF
- fi
- cat >>.gitignore <<EOF
-
-*~
-
-# mount(8) records system state here, no need to keep these in git
-blkid.tab
-blkid.tab.old
-
-# some other files in /etc that typically do not need to be tracked
-ld.so.cache
-mtab
-.pwd.lock
-network/run
-adjtime
-
-EOF
-fi
View
@@ -1,3 +0,0 @@
-#!/bin/sh
-set -e
-chmod 700 .git
@@ -1,15 +0,0 @@
-#!/bin/sh
-set -e
-if [ -x .git/hooks/pre-commit ]; then
- if ! grep -q "etckeeper pre-commit" .git/hooks/pre-commit; then
- echo "etckeeper warning: .git/hooks/pre-commit needs to be manually modifed to run: etckeeper pre-commit `pwd`" >&2
- fi
-else
- cat >.git/hooks/pre-commit <<EOF
-#!/bin/sh
-# pre-commit hook for etckeeper, to store metadata and do sanity checks
-set -e
-etckeeper pre-commit `pwd`
-EOF
- chmod +x .git/hooks/pre-commit
-fi
View
@@ -0,0 +1,70 @@
+#!/bin/sh
+set -e
+
+if [ "$VCS" = git ] && [ ! -e .gitignore ]; then
+ file=.gitignore
+elif [ "$VCS" = hg ] && [ ! -e .hgignore ]; then
+ file=.hgignore
+fi
+
+if [ -z "$file" ] || [ -e "$file" ]; then
+ exit 0
+fi
+
+nl() {
+ echo >>$file
+}
+
+comment() {
+ comment="$1"
+ echo "# $comment" >>$file
+}
+
+ignore() {
+ glob="$1"
+
+ case "$VCS" in
+ git)
+ echo "$glob" >> $file
+ ;;
+ hg)
+ # rather than converting the glob to a regexp, just
+ # configure hg to use globs
+ if [ -z "$hg_syntax_printed" ]; then
+ comment "use glob syntax"
+ echo "syntax: glob" >> $file
+ nl
+ hg_syntax_printed=1
+ fi
+ echo "$glob" >> $file
+ ;;
+ esac
+}
+
+if [ "$LOWLEVEL_PACKAGE_MANAGER" = dpkg ]; then
+ comment "new and old versions of conffiles, stored by dpkg"
+ ignore "*.dpkg-*"
+ nl
+elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "pacman-g2" ]; then
+ comment "new and old versions of conffiles, stored by pacman"
+ ignore "*.pacnew"
+ ignore "*.pacorig"
+ ignore "*.pacsave"
+ nl
+fi
+
+ignore "*~"
+nl
+
+comment "mount(8) records system state here, no need to store these"
+ignore blkid.tab
+ignore blkid.tab.old
+nl
+
+comment "some other files in /etc that typically do not need to be tracked"
+ignore ld.so.cache
+ignore mtab
+ignore .pwd.lock
+ignore network/run
+ignore adjtime
+nl
View
@@ -0,0 +1,8 @@
+#!/bin/sh
+set -e
+
+if [ "$VCS" = git ]; then
+ chmod 700 .git
+elif [ "$VCS" = hg ]; then
+ chmod 700 .hg
+fi
@@ -0,0 +1,32 @@
+#!/bin/sh
+set -e
+
+case "$VCS" in
+ git)
+ if [ -x .git/hooks/pre-commit ]; then
+ if ! grep -q "etckeeper pre-commit" .git/hooks/pre-commit; then
+ echo "etckeeper warning: .git/hooks/pre-commit needs to be manually modifed to run: etckeeper pre-commit `pwd`" >&2
+ fi
+ else
+ cat >.git/hooks/pre-commit <<EOF
+#!/bin/sh
+# pre-commit hook for etckeeper, to store metadata and do sanity checks
+set -e
+etckeeper pre-commit `pwd`
+EOF
+ chmod +x .git/hooks/pre-commit
+ fi
+ ;;
+ hg)
+ if [ -e .hg/hgrc ] && grep "^\[hooks\]" .hg/hgrc; then
+ echo "etckeeper warning: [hooks] section in .hg/hgrc needs to be manually modified to run: etckeeper pre-commit `pwd`" >&2
+ else
+ touch .hg/hgrc
+ cat >>.hg/hgrc <<EOF
+[hooks]
+# pre-commit hook for etckeeper, to store metadata and do sanity checks
+precommit = etckeeper pre-commit `pwd`
+EOF
+ fi
+ ;;
+esac
View
@@ -1,5 +0,0 @@
-#!/bin/sh
-set -e
-if ! git add .; then
- echo "etckeeper warning: git add failed" >&2
-fi
View
@@ -0,0 +1,12 @@
+#!/bin/sh
+set -e
+
+if [ "$VCS" = git ]; then
+ if ! git add .; then
+ echo "etckeeper warning: git add failed" >&2
+ fi
+elif [ "$VCS" = hg ]; then
+ if ! hg add .; then
+ echo "etckeeper warning: hg add failed" >&2
+ fi
+fi
@@ -1,6 +0,0 @@
-#!/bin/sh
-set -e
-if [ ! -d .git ]; then
- echo "etckeeper warning: etckeeper is not yet enabled for $(pwd)" >&2
- echo "etckeeper warning: run etckeeper init to enable it" >&2
-fi
View
@@ -0,0 +1,13 @@
+#!/bin/sh
+set -e
+
+not_enabled_warning() {
+ echo "etckeeper warning: etckeeper is not yet enabled for $(pwd)" >&2
+ echo "etckeeper warning: run etckeeper init to enable it" >&2
+}
+
+if [ "$VCS" = git ] && [ ! -d .git ]; then
+ not_enabled_warning
+elif [ "$VCS" = hg ] && [ ! -d .hg ]; then
+ not_enabled_warning
+fi
View
@@ -1,6 +1,7 @@
#!/bin/sh
set -e
-if [ -d .git ]; then
+
+if [ "$VCS" = git ] && [ -d .git ]; then
if ! git add .; then
echo "etckeeper warning: git add failed" >&2
fi
@@ -0,0 +1,8 @@
+#!/bin/sh
+set -e
+
+if [ "$VCS" = hg ] && [ -d .hg ]; then
+ if ! hg addremove .; then
+ echo "etckeeper warning: hg addremove failed" >&2
+ fi
+fi
View
@@ -3,7 +3,7 @@ set -e
TAB=" "
-if [ -d .git ]; then
+if [ "$VCS" = git ] && [ -d .git ]; then
for file in $(git ls-files --deleted); do
if [ ! -d "$file" ]; then
git rm --quiet "$file"
@@ -1,9 +0,0 @@
-#!/bin/sh
-set -e
-
-if [ -d .git ]; then
- message="committing changes after $HIGHLEVEL_PACKAGE_MANAGER run"
-
- # ignore exit code since it exits nonzero if there is nothing to do
- git commit $GIT_COMMIT_OPTIONS -m "$message" || true
-fi
@@ -0,0 +1,11 @@
+#!/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
+fi
Oops, something went wrong.

0 comments on commit 788ae5a

Please sign in to comment.