diff options
Diffstat (limited to 'init.d')
-rwxr-xr-x | init.d/10restore-etckeeper | 8 | ||||
-rwxr-xr-x | init.d/20restore-metadata | 10 | ||||
-rwxr-xr-x | init.d/40vcs-init | 11 | ||||
-rwxr-xr-x | init.d/50vcs-ignore | 70 | ||||
-rwxr-xr-x | init.d/50vcs-perm | 8 | ||||
-rwxr-xr-x | init.d/50vcs-pre-commit-hook | 32 | ||||
-rwxr-xr-x | init.d/70vcs-add | 12 | ||||
-rw-r--r-- | init.d/README | 13 |
8 files changed, 164 insertions, 0 deletions
diff --git a/init.d/10restore-etckeeper b/init.d/10restore-etckeeper new file mode 100755 index 0000000..376524c --- /dev/null +++ b/init.d/10restore-etckeeper @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +# Yes, this runs code from the repository. As documented, etckeeper-init +# should only be run on repositories you trust. +if [ -e .etckeeper ]; then + . ./.etckeeper +fi diff --git a/init.d/20restore-metadata b/init.d/20restore-metadata new file mode 100755 index 0000000..01c45e4 --- /dev/null +++ b/init.d/20restore-metadata @@ -0,0 +1,10 @@ +#!/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 + metastore --apply --mtime +fi diff --git a/init.d/40vcs-init b/init.d/40vcs-init new file mode 100755 index 0000000..e2677bc --- /dev/null +++ b/init.d/40vcs-init @@ -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 diff --git a/init.d/50vcs-ignore b/init.d/50vcs-ignore new file mode 100755 index 0000000..18f368e --- /dev/null +++ b/init.d/50vcs-ignore @@ -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 diff --git a/init.d/50vcs-perm b/init.d/50vcs-perm new file mode 100755 index 0000000..9ffad92 --- /dev/null +++ b/init.d/50vcs-perm @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +if [ "$VCS" = git ]; then + chmod 700 .git +elif [ "$VCS" = hg ]; then + chmod 700 .hg +fi diff --git a/init.d/50vcs-pre-commit-hook b/init.d/50vcs-pre-commit-hook new file mode 100755 index 0000000..33d0ae7 --- /dev/null +++ b/init.d/50vcs-pre-commit-hook @@ -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 diff --git a/init.d/70vcs-add b/init.d/70vcs-add new file mode 100755 index 0000000..8cf60d0 --- /dev/null +++ b/init.d/70vcs-add @@ -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 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. |