don't exit bash on /etc with uncommitted changes
As explained before by Zack, it might happen that you co-administer a machine and have /etc under some VCS (which you should anyway by using etckeeper).
There are a few problems like detecting the identity of the committer and don't leave /etc with uncommitted changes so I recently came up with a slighly different solution than the one we thought two years ago (besides switching from bzr to git).
Take committer name/email from ~/.gitconfig of the user owning the tty or GIT_CONFIG or GIT_CONFIG_LOCAL if they are set.
Trap a function on shell's EXIT rather than loop on .bash_logout which applies only to login shell.
The resulting code to be put in /root/.bashrc:
git_functions="/path/to/git-etc-common"
# export GIT_* variables
if [ -f "$git_functions" ]; then
. "$git_functions"
git_export_env
fi
case $- in
*i*) # interactive shell
check_uncommitted(){
if [ -f "$git_functions" ]; then
. "$git_functions"
if ! git_etc_status; then
echo "Uncommitted changes to /etc found, please commit them"
bash -$-
fi
fi
}
trap check_uncommitted EXIT
;;
esac
Where git-etc-common is to be found here.
Posted at: 12:28
|
permalink
|
add to del.icio.us
|
Comments (1)