From d6bf04012af50a308afe612d5687e8775a23dcca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20L=C3=A4ssig?= Date: Thu, 6 Jun 2019 18:16:46 +0200 Subject: [PATCH] fix if not used with sudo --- bin/sys | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) 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