Skip to content

Instantly share code, notes, and snippets.

@jerrykan
Created April 30, 2012 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerrykan/2555438 to your computer and use it in GitHub Desktop.
Save jerrykan/2555438 to your computer and use it in GitHub Desktop.
Determine user logged in as root and export git env variables
#
# Export some environment variables so git can better determine the real user
# making commits when 'su'ed as the root user.
#
### Git Settings
USERNAME=`who -m | cut -d ' ' -f 1`
# Set the git author name and email
GIT_AUTHOR_EMAIL=`who -m | awk -F ' ' '{print $1"@"$5}' | sed -e 's/[()]//g'`
GIT_AUTHOR_NAME=`grep ^$USERNAME: /etc/passwd | cut -d ':' -f5`
# Default to the user's username if no name is found
[ -z "$GIT_AUTHOR_NAME" ] && GIT_AUTHOR_NAME=$USERNAME
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment