Skip to content

Instantly share code, notes, and snippets.

@Jonny007-MKD
Created April 10, 2020 12:09
Show Gist options
  • Select an option

  • Save Jonny007-MKD/91d776d2898daf75e957ac22b7f43741 to your computer and use it in GitHub Desktop.

Select an option

Save Jonny007-MKD/91d776d2898daf75e957ac22b7f43741 to your computer and use it in GitHub Desktop.
Check if /etc is clean before logout
# Check /etc git is clean (from etckeeper)
if sudo -n true 2> /dev/null; then # if we can run sudo without prompting
cd /etc/
if [[ `sudo git status --porcelain` ]]; then # if git is not clean
echo -e "\033[0;31mPlease commit changes in /etc first\033[0m"
exec sudo bash -l # start a new bash (i.e. abort logout) as root in /etc
# the login bash is now running as root
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment