[packages/etckeeper] motd: be smarter and accept ~/.gitconfig from user's homes

glen glen at pld-linux.org
Tue Oct 11 08:00:16 CEST 2016


commit c9313d999dfbec8b0d083383dc60399e49cf5833
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Sat Oct 1 12:31:05 2016 +0300

    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 at 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 at 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
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/etckeeper.git/commitdiff/c9313d999dfbec8b0d083383dc60399e49cf5833



More information about the pld-cvs-commit mailing list