Skip to content

Instantly share code, notes, and snippets.

@FlorianHeigl

FlorianHeigl/900.etckeeper

Last active Sep 15, 2020
Embed
What would you like to do?
FreeBSD etckeeper periodic job
#!/usr/bin/env bash
set -eu
# from https://gist.githubusercontent.com/kenjiskywalker/4372273/raw/11af3f5ca1f05b803a2828a8b3eb2f2a288c2311/etckeeper
check_clean() {
cd "$1"
git_diff=$( git diff | head -n1 | cut -d " " -f 1 )
[ -n "$git_diff" ] && return 1
}
commit_if_enabled() {
cd "$1"
# config ist noch in /etc anstatt /usr/local/etc
if [ -x /usr/bin/etckeeper ] && [ -e /etc/etckeeper/etckeeper.conf ]; then
. /etc/etckeeper/etckeeper.conf
if [ "$AVOID_DAILY_AUTOCOMMITS" != "1" ]; then
# avoid autocommit if an install run is in progress
# TODO: Verify path
lockfile=/var/cache/etckeeper/packagelist.pre-install
# TODO: Shellcheck warning: where is $pe coming from?
#if [ -e "$pe" ] && [ -n "$(find "$lockfile" -mtime +1)" ]; then
# rm -f "$lockfile" # stale
#fi
# TODO un-nest control flow
if [ ! -e "$lockfile" ]; then
AVOID_SPECIAL_FILE_WARNING=1
export AVOID_SPECIAL_FILE_WARNING
if etckeeper unclean; then
etckeeper commit "daily autocommit" >/dev/null
fi
fi
fi
fi
}
main() {
for _confdir in /etc /usr/local/etc ; do
check_clean ${_confdir}
commit_if_enabled ${_confdir}
done
}
main
@FlorianHeigl

This comment has been minimized.

Copy link
Owner Author

@FlorianHeigl FlorianHeigl commented Sep 15, 2020

stock etckeeper still can't handle multiple dirs.
there is a fork of unknown maintenance state.
until the situation clarifies this hackish autocommit job is supposed to commit changes.

it's based from an existing cronjob, but I have to say the lockfile logic looks not very trustworthy.
i commented the $pe stuff since it seems to not come from anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment