From fdeec420b54e252e611c353ce39fe61c924e3e7d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 31 Jul 2013 11:33:45 -0400 Subject: etckeeper (1.7) unstable; urgency=low * Fix hilarious typo hardcoding my name. Closes: #718425 # imported from the archive --- init.d/10restore-metadata | 14 ++++++++++++ init.d/20restore-etckeeper | 22 ++++++++++++++++++ init.d/40vcs-init | 17 ++++++++++++++ init.d/50vcs-ignore | 4 ++++ init.d/50vcs-perm | 12 ++++++++++ init.d/50vcs-pre-commit-hook | 49 +++++++++++++++++++++++++++++++++++++++++ init.d/60darcs-deleted-symlinks | 48 ++++++++++++++++++++++++++++++++++++++++ init.d/70vcs-add | 27 +++++++++++++++++++++++ init.d/README | 13 +++++++++++ 9 files changed, 206 insertions(+) create mode 100755 init.d/10restore-metadata create mode 100755 init.d/20restore-etckeeper create mode 100755 init.d/40vcs-init create mode 100755 init.d/50vcs-ignore create mode 100755 init.d/50vcs-perm create mode 100755 init.d/50vcs-pre-commit-hook create mode 100755 init.d/60darcs-deleted-symlinks create mode 100755 init.d/70vcs-add create mode 100644 init.d/README (limited to 'init.d') 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 <&2 + fi + else + touch .hg/hgrc + cat >>.hg/hgrc <&2 + fi + else + cat >_darcs/prefs/defaults < "$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. -- cgit v1.2.3