#!/bin/bash # # Sets up the /etc directory for git tracking of configuration files # # Author: Jason Graham # # Usage: git-etc-tracking.sh # EDITOR=${EDITOR:-nano} function config_git { local user_name=$(git config --global --get user.name) local user_email=$(git config --global --get user.email) if [ -z "$user_name" ] || [ -z "$user_email" ]; then echo "Set local Git user configuration:" fi if [ -z "$user_name" ]; then user_name="" while [ -z "$user_name" ] do echo -n " Name (e.g., Your Name): " read -a user_name done git config --local user.name "$user_name" fi if [ -z "$user_email" ]; then user_email="" while [ -z "$user_email" ] do echo -n " Email (e.g, your@email.com): " read -a user_email done git config --local user.email "$user_email" fi } function trap_cleanup { cleanup if [ -d /etc/.git ]; then echo "Removing Git repository in /etc/.git" fi rm -rf /etc/.git /etc/.gitignore } function cleanup { rm -f /tmp/git-files } trap 'trap_cleanup; exit 1' TERM INT set -e if (( $UID != 0 )); then echo "root privileges required" exit 1 fi cd /etc find . -not -path '*~' -not -path '*.orig' -not -path '*.new' -not -path '*.save' -not -path '*.archive' -type f > /tmp/git-files find . -not -path '*~' -not -path '*.orig' -not -path '*.new' -not -path '*.save' -not -path '*.archive' -type l >> /tmp/git-files echo -n "Review and modify the tracked file list (y/n)? " read -a ans if [ $ans == "y" ]; then $EDITOR /tmp/git-files fi echo -n "Create Git repository (y/n)? " read -a ans if [ $ans != "y" ]; then cleanup exit 0 fi git init config_git cat > .gitignore <