Skip to content

Commit

Permalink
fix if not used with sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
Farom committed Jun 6, 2019
1 parent 3c0224b commit d6bf040
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions bin/sys
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d6bf040

Please sign in to comment.