Ajout : rule_user_configure : bash, screen, etckeeper .
[lhc/ateliers.git] / etc / etckeeper / prompt.sh
diff --git a/etc/etckeeper/prompt.sh b/etc/etckeeper/prompt.sh
new file mode 100644 (file)
index 0000000..1d1e3ce
--- /dev/null
@@ -0,0 +1,49 @@
+# DESCRIPTION :
+#  - Les variables GIT_AUTHOR_*, utilisées par git pour signer les commits,
+#    seront initialisées en fonction du contenu de ~/.gitconfig
+#    ou du login utilisé pour la connexion.
+#  - La fermeture du shell dans le cas où des modifications de /etc
+#    n'ont pas été enregistrées échouera avec un avertissement.
+
+case $- in
+ (*i*) # NOTE: interactive shell
+       check_uncommitted () {
+               if sudo -n etckeeper unclean 2>/dev/null
+                then printf '%s%s%s\n' >&2 "${tput_rev-}" "/etc has uncommitted changes: please use etckeeper commit." "${tput_sgr0-}"
+                       CHECK_UNCOMMITED="done" $SHELL -$-
+               fi
+        }
+       git_export_env () {
+               local ttyuser ttyuserhome conf
+               
+               ttyuser="$(stat -c "%U" $(tty))"
+               ttyuserhome="$(getent passwd "$ttyuser" | cut -d: -f6)"
+               conf="$ttyuserhome/.gitconfig"
+               
+               if [ -z "$GIT_AUTHOR_NAME" ] && [ -z "$GIT_AUTHOR_EMAIL" ]; then
+                       if [ ! -z "$GIT_CONFIG_LOCAL" ] || [ ! -z "$GIT_CONFIG" ]
+                        then
+                               export GIT_AUTHOR_NAME="$(git config --get user.name)"
+                               export GIT_AUTHOR_EMAIL="$(git config --get user.email)"
+                       elif [ -r "$conf" ]; then
+                               export GIT_AUTHOR_NAME="$(git config --file "$conf" --get user.name)"
+                               export GIT_AUTHOR_EMAIL="$(git config --file "$conf" --get user.email)"
+                       else
+                               export GIT_AUTHOR_NAME="$USER"
+                               export GIT_AUTHOR_EMAIL="$USER@$(hostname -f)"
+                        fi
+                fi
+        }
+       prompt_etckeeper () {
+               errno=$?;
+               if sudo -n etckeeper unclean 2>/dev/null
+                then printf '(!) '
+                fi
+               exit $errno
+        }
+       if [ "$CHECK_UNCOMMITED" != done ]
+        then trap check_uncommitted EXIT
+        fi
+       git_export_env
+       ;;
+ esac