]> git.pld-linux.org Git - packages/etckeeper.git/commitdiff
motd: be smarter and accept ~/.gitconfig from user's homes
authorElan Ruusamäe <glen@delfi.ee>
Sat, 1 Oct 2016 09:31:05 +0000 (12:31 +0300)
committerElan Ruusamäe <glen@delfi.ee>
Tue, 11 Oct 2016 05:59:37 +0000 (08:59 +0300)
motd.sh

diff --git a/motd.sh b/motd.sh
index 26eb3a5c4393002e647612edca3e9c320d0ca430..5ad49a96cfc54ee2472cc4a98ba69fe9ffc19862 100644 (file)
--- 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
This page took 0.176875 seconds and 4 git commands to generate.