ansible-roles/certbot/files/hooks/z-commit-etc.sh

38 lines
990 B
Bash
Raw Normal View History

2019-09-27 00:13:30 +02:00
#!/bin/sh
error() {
>&2 echo "${PROGNAME}: $1"
exit 1
}
debug() {
if [ "${VERBOSE}" = "1" ] && [ "${QUIET}" != "1" ]; then
>&2 echo "${PROGNAME}: $1"
fi
}
2019-09-27 14:03:39 +02:00
main() {
export GIT_DIR="/etc/.git"
export GIT_WORK_TREE="/etc"
if test -x "${git_bin}" && test -d "${GIT_DIR}" && test -d "${GIT_WORK_TREE}"; then
changed_lines=$(${git_bin} status --porcelain | wc -l | tr -d ' ')
2019-09-27 00:13:30 +02:00
2019-09-27 14:03:39 +02:00
if [ "${changed_lines}" != "0" ]; then
debug "Committing for ${RENEWED_DOMAINS}"
${git_bin} add --all
2019-09-27 14:03:39 +02:00
message="[letsencrypt] certificates renewal (${RENEWED_DOMAINS})"
${git_bin} commit --message "${message}" --quiet
else
error "Weird, nothing has changed but the hook has been executed for '${RENEWED_DOMAINS}'"
fi
fi
}
readonly PROGNAME=$(basename "$0")
readonly VERBOSE=${VERBOSE:-"0"}
readonly QUIET=${QUIET:-"0"}
2019-09-27 00:13:30 +02:00
2019-09-27 14:03:39 +02:00
readonly git_bin=$(command -v git)
readonly letsencrypt_dir=/etc/letsencrypt
2019-09-27 00:13:30 +02:00
2019-09-27 14:03:39 +02:00
main