diff --git a/bin/sys b/bin/sys index 9e8ac7b..de24861 100755 --- a/bin/sys +++ b/bin/sys @@ -49,21 +49,24 @@ if [ "${uid}" -ne "0" ]; then fi ### create/find credentials for using with git -homedir=$(getent passwd ${SUDO_USER} | cut -d\: -f 6) -git_config_file="${homedir}"/.gitconfig -hostname=$(hostname -f) -# check for user credentials! -if [ -z "$GIT_COMMITTER_NAME" ]; then - # if they do not exist, try to read from gitconfig in home dir - export GIT_COMMITTER_NAME=$(git config -f $git_config_file user.name) - export GIT_AUTHOR_NAME=$(git config -f $git_config_file user.name) - export GIT_COMMITTER_EMAIL=$(git config -f $git_config_file user.email) - export GIT_AUTHOR_EMAIL=$(git config -f $git_config_file user.email) - # if this fails ... generate the credentials - : ${GIT_COMMITTER_EMAIL:=${SUDO_USER}@${hostname}} - : ${GIT_AUTHOR_EMAIL:=${SUDO_USER}@${hostname}} - : ${GIT_COMMITTER_NAME:=${SUDO_USER}} - : ${GIT_AUTHOR_NAME:=${SUDO_USER}} + +if [ -n "$SUDO_USER" ]; then + homedir=$(getent passwd ${SUDO_USER} | cut -d\: -f 6) + git_config_file="${homedir}"/.gitconfig + hostname=$(hostname -f) + # check for user credentials! + if [ -z "$GIT_COMMITTER_NAME" ]; then + # if they do not exist, try to read from gitconfig in home dir + export GIT_COMMITTER_NAME=$(git config -f $git_config_file user.name) + export GIT_AUTHOR_NAME=$(git config -f $git_config_file user.name) + export GIT_COMMITTER_EMAIL=$(git config -f $git_config_file user.email) + export GIT_AUTHOR_EMAIL=$(git config -f $git_config_file user.email) + # if this fails ... generate the credentials + fi + : ${GIT_COMMITTER_EMAIL:=${SUDO_USER}@${hostname}} + : ${GIT_AUTHOR_EMAIL:=${SUDO_USER}@${hostname}} + : ${GIT_COMMITTER_NAME:=${SUDO_USER}} + : ${GIT_AUTHOR_NAME:=${SUDO_USER}} fi ################################################################################ export GIT_DIR=$SYSGIT_PATH_OFFSET/var/lib/sysgit