diff options
Diffstat (limited to 'init.d')
-rwxr-xr-x | init.d/10restore-metadata | 14 | ||||
-rwxr-xr-x | init.d/20restore-etckeeper | 22 | ||||
-rwxr-xr-x | init.d/40vcs-init | 17 | ||||
-rwxr-xr-x | init.d/50vcs-ignore | 4 | ||||
-rwxr-xr-x | init.d/50vcs-perm | 12 | ||||
-rwxr-xr-x | init.d/50vcs-pre-commit-hook | 49 | ||||
-rwxr-xr-x | init.d/60darcs-deleted-symlinks | 48 | ||||
-rwxr-xr-x | init.d/70vcs-add | 27 | ||||
-rw-r--r-- | init.d/README | 13 |
9 files changed, 206 insertions, 0 deletions
diff --git a/init.d/10restore-metadata b/init.d/10restore-metadata new file mode 100755 index 0000000..9c2bf65 --- /dev/null +++ b/init.d/10restore-metadata @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +# Note that metastore doesn't check that the .metastore file only changes +# perms of files in the current directory. It's ok to trust the .metastore +# file won't do anything shady, because, as documented, etckeeper-init +# should only be run on repositories you trust. +if [ -e .metadata ]; then + if which metastore >/dev/null; then + metastore --apply --mtime + else + echo "etckeeper warning: legacy .metastore file is present but metastore is not installed" >&2 + fi +fi diff --git a/init.d/20restore-etckeeper b/init.d/20restore-etckeeper new file mode 100755 index 0000000..0485e63 --- /dev/null +++ b/init.d/20restore-etckeeper @@ -0,0 +1,22 @@ +#!/bin/sh +set -e + +# Used by .etckeeper to run a command if the file it acts on +# (the last parameter) exists. +maybe () { + command="$1" + shift 1 + + if eval [ -e "\"\$$#\"" ]; then + "$command" "$@" + fi +} + +# Yes, this runs code from the repository. As documented, etckeeper-init +# should only be run on repositories you trust. +if [ -e .etckeeper ]; then + . ./.etckeeper +else + touch .etckeeper + chmod 600 .etckeeper +fi diff --git a/init.d/40vcs-init b/init.d/40vcs-init new file mode 100755 index 0000000..3c7a3bb --- /dev/null +++ b/init.d/40vcs-init @@ -0,0 +1,17 @@ +#!/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 +elif [ "$VCS" = bzr ] && [ ! -e .bzr ]; then + bzr init + bzr nick "$(hostname) /etc repository" +elif [ "$VCS" = darcs ] && [ ! -e _darcs ]; then + darcs initialize + echo "$(hostname) /etc repository" > _darcs/prefs/motd +fi diff --git a/init.d/50vcs-ignore b/init.d/50vcs-ignore new file mode 100755 index 0000000..33d79d3 --- /dev/null +++ b/init.d/50vcs-ignore @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +etckeeper update-ignore -a || true diff --git a/init.d/50vcs-perm b/init.d/50vcs-perm new file mode 100755 index 0000000..4dd080b --- /dev/null +++ b/init.d/50vcs-perm @@ -0,0 +1,12 @@ +#!/bin/sh +set -e + +if [ "$VCS" = git ]; then + chmod 700 .git +elif [ "$VCS" = hg ]; then + chmod 700 .hg +elif [ "$VCS" = bzr ]; then + chmod 700 .bzr +elif [ "$VCS" = darcs ]; then + chmod 700 _darcs +fi diff --git a/init.d/50vcs-pre-commit-hook b/init.d/50vcs-pre-commit-hook new file mode 100755 index 0000000..6045981 --- /dev/null +++ b/init.d/50vcs-pre-commit-hook @@ -0,0 +1,49 @@ +#!/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 modified to run: etckeeper pre-commit -d `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 -d `pwd` +EOF + chmod +x .git/hooks/pre-commit + fi + ;; + hg) + if [ -e .hg/hgrc ] && grep "^\[hooks\]" .hg/hgrc; then + if ! grep "^pre-commit" .hg/hgrc | grep -q "etckeeper pre-commit"; then + echo "etckeeper warning: [hooks] section in .hg/hgrc needs to be manually modified to contain: pre-commit = etckeeper pre-commit -d `pwd`" >&2 + fi + else + touch .hg/hgrc + cat >>.hg/hgrc <<EOF +[hooks] +# pre-commit hook for etckeeper, to store metadata and do sanity checks +pre-commit = etckeeper pre-commit -d `pwd` +EOF + fi + ;; + darcs) + if [ -e _darcs/prefs/defaults ]; then + if ! ( grep -q "record prehook etckeeper pre-commit" _darcs/prefs/defaults && + grep -q "whatsnew prehook etckeeper pre-commit" _darcs/prefs/defaults ); then + echo "etckeeper warning: _darcs/prefs/defaults needs to be manually modified to run: etckeeper pre-commit -d `pwd`" >&2 + fi + else + cat >_darcs/prefs/defaults <<EOF +record prehook etckeeper pre-commit -d `pwd` +record run-prehook +whatsnew prehook etckeeper pre-commit -d `pwd` +whatsnew run-prehook +EOF + fi + ;; +esac diff --git a/init.d/60darcs-deleted-symlinks b/init.d/60darcs-deleted-symlinks new file mode 100755 index 0000000..9c34e95 --- /dev/null +++ b/init.d/60darcs-deleted-symlinks @@ -0,0 +1,48 @@ +#!/bin/sh +set -e + +filter_ignore() { + if [ "$VCS" = darcs ]; then + ignorefile=.darcsignore + fi + + if [ "$VCS" = darcs ] && [ -e "$ignorefile" ]; then + # Spaces embedded into patterns would break it. + # But really, why would anyone want to use ' ' instead of '\s' ? + #patterns=$( grep -v '^[[:space:]]*\(#\|$\)' "$ignorefile" | xargs -n 1 printf " -e %s" ) + #grep -Ev $patterns + #unset patterns + # Alternative using a temp file + patternsfile="$( mktemp -t etckeeper-$VCS.XXXXXXXXXX )" + grep -v '^[[:space:]]*\(#\|$\)' "$ignorefile" > "$patternsfile" || true + grep -Evf "$patternsfile" + rm -f "$patternsfile" + unset patternsfile + else + cat - + fi +} + + +if [ "$VCS" = darcs ];then + NOVCS='. -path ./.git -prune -o -path ./.bzr -prune -o -path ./.hg -prune -o -path ./_darcs -prune -o' + + # We assume that if .etckeeper is empty this is the first run + if [ -s .etckeeper ]; then + linksindex="$( mktemp -t etckeeper-$VCS.XXXXXXXXXX )" + grep '^ln -s' .etckeeper | while IFS="'" read n n n link n; do + printf "%s\n" "$link" >> "$linksindex" + done + + # Warn about symbolic links that shouldn't exist + if links=$( find $NOVCS -type l -print | filter_ignore | grep -vFf "$linksindex" ); then + printf "%s\n%s\n" \ + "The following symbolic links should not exist:" \ + "$links" >&2 + fi + + rm -f "$linksindex" + unset links linksindex + fi + +fi diff --git a/init.d/70vcs-add b/init.d/70vcs-add new file mode 100755 index 0000000..9a9ec45 --- /dev/null +++ b/init.d/70vcs-add @@ -0,0 +1,27 @@ +#!/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 +elif [ "$VCS" = bzr ]; then + if ! bzr add .; then + echo "etckeeper warning: bzr add failed" >&2 + fi +elif [ "$VCS" = darcs ]; then + # Don't warn if all the files were already added. + rc=0 + res=$( darcs add -qr . 2>&1 ) || rc=$? + if test $rc -ne 0; then + if ! test $rc -eq 2 -a "${res%No files were added}" != "$res"; then + printf "%s" "$res" + echo "etckeeper warning: darcs add failed" >&2 + fi + fi + unset rc res +fi diff --git a/init.d/README b/init.d/README new file mode 100644 index 0000000..90aec67 --- /dev/null +++ b/init.d/README @@ -0,0 +1,13 @@ +Executable files in this directory are run to initialise the working directory +for use by etckeeper. If the working directory is not already in version +control, that includes setting up the version control, but not actually +committing anything. If the working directory is in version control, +it includes applying stored metadata to the checked out files in the +working directory. + +Please be careful to *never* overwrite existing files/directories +in the working directory (or use absolute care when doing so). If a file +you need to write already exists, check if its contents are sane, and +if not, emit a warning on stderr. + +If initialisation fails, exit nonzero and no later files will be run. |