Created
April 30, 2012 04:19
-
-
Save jerrykan/2555438 to your computer and use it in GitHub Desktop.
Determine user logged in as root and export git env variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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