From c9313d999dfbec8b0d083383dc60399e49cf5833 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 1 Oct 2016 12:31:05 +0300 Subject: [PATCH 1/1] motd: be smarter and accept ~/.gitconfig from user's homes --- motd.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/motd.sh b/motd.sh index 26eb3a5..5ad49a9 100644 --- a/motd.sh +++ b/motd.sh @@ -1,14 +1,51 @@ -if [ "$UID" = 0 -a -z "$GIT_AUTHOR_NAME" -a -z "$GIT_AUTHOR_EMAIL" ]; then - cat <<'EOF' -Please commit your changes if you modify any files in /etc to git! -But before that please setup env vars to identify your commits in your ~/.bash_profile: -export GIT_AUTHOR_NAME='Elan Ruusamäe' -export GIT_AUTHOR_EMAIL='glen@pld-linux.org' +git_config_check() { + # skip if env vars are set + if [ -n "$GIT_AUTHOR_NAME" -a -n "$GIT_AUTHOR_EMAIL" ]; then + return + fi -export GIT_COMMITTER_NAME=${GIT_COMMITER_NAME:-$GIT_AUTHOR_NAME} -export GIT_COMMITTER_EMAIL=${GIT_COMMITER_EMAIL:-$GIT_AUTHOR_EMAIL} + # check if configured in ~/.gitconfig + email=$(git config --global --get user.email) + username=$(git config --global --get user.name) + + # it's important for each user have their own ~/.gitconfig + if [ "$HOME" = "/root" ]; then + cat >&2 <<-'EOF' + + IMPORTANT: Use 'sudo -s' to become root, so that the $HOME belongs to you not /root + + EOF + fi + + if [ -n "$email" -a -n "$username" ]; then + return + fi + + user=${SUDO_USER:-$(id -un)} + gecos=$(getent passwd $user | cut -d: -f5) + email=$user@pld-linux.org + + cat >&2 <<-EOF + + Please commit your changes if you modify any files in /etc to git! + But before that please setup env vars to identify your commits in your ~/.bash_profile: + + export GIT_AUTHOR_NAME='$gecos' + export GIT_AUTHOR_EMAIL='$email' + + export GIT_COMMITTER_NAME=\${GIT_COMMITTER_NAME:-\$GIT_AUTHOR_NAME} + export GIT_COMMITTER_EMAIL=\${GIT_COMMITTER_EMAIL:-\$GIT_AUTHOR_EMAIL} + + NOTE: GIT_* vars are imported with sshd so you could setup them where you connect from. + + You may also use git config, but then you must learn to use 'sudo -s' to become root: + git config --global user.email '$email' + git config --global user.name '$gecos' - -glen EOF -fi +} + +# run in subshell not to leak variables +git_config_check | cat +unset -f git_config_check -- 2.44.0