Initial commit.

This commit is contained in:
2021-05-24 22:18:33 +03:00
commit e2954d55f4
3701 changed files with 330017 additions and 0 deletions

View File

@@ -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 command -v metastore >/dev/null; then
metastore --apply --mtime
else
echo "etckeeper warning: legacy .metastore file is present but metastore is not installed" >&2
fi
fi

View File

@@ -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

18
etckeeper/init.d/40vcs-init Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/sh
set -e
description="$(hostname 2>/dev/null || cat /etc/hostname) /etc repository"
if [ "$VCS" = git ] && [ ! -e .git ]; then
git init
echo "$description" > .git/description
elif [ "$VCS" = hg ] && [ ! -e .hg ]; then
hg init
echo "[web]" > .hg/hgrc
echo "description = $description" >> .hg/hgrc
elif [ "$VCS" = bzr ] && [ ! -e .bzr ]; then
bzr init
bzr nick "$description"
elif [ "$VCS" = darcs ] && [ ! -e _darcs ]; then
darcs initialize
echo "$description" > _darcs/prefs/motd
fi

4
etckeeper/init.d/50vcs-ignore Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
set -e
etckeeper update-ignore -a || true

12
etckeeper/init.d/50vcs-perm Executable file
View File

@@ -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

View File

@@ -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

View File

@@ -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

27
etckeeper/init.d/70vcs-add Executable file
View File

@@ -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

13
etckeeper/init.d/README Normal file
View File

@@ -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.