Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. set -eu
  4.  
  5. # we only want to run this script as root
  6. if [ ! $(id -u) = 0 ]; then
  7. echo "This script must be run as root" 1>&2
  8. exit 1
  9. fi
  10.  
  11. # use environment variable for user
  12. # or fallback to logname
  13. USER="${SOURCE_USER:-$(logname)}"
  14.  
  15. # get user home directory and preferred shell
  16. HOME="$(getent passwd "$USER" | cut -d: -f6)"
  17. SHELL="$(getent passwd "$USER" | cut -d: -f7)"
  18.  
  19. # in case the users preferred shell defaulted to this
  20. # script we fallback to bash
  21. if [ "$SHELL" = "$0" ]; then
  22. SHELL=/bin/bash
  23. fi
  24.  
  25. # if the user has a custom gitconfig we use it to define the
  26. # git author and email
  27. if [ -n "$HOME" ] && [ -e "$HOME/.gitconfig" ]; then
  28. GIT_AUTHOR_NAME="$(git config -f "$HOME/.gitconfig" user.name)"
  29. GIT_AUTHOR_EMAIL="$(git config -f "$HOME/.gitconfig" user.email)"
  30. # in case no custom gitconfig has been provided we fallback to
  31. # the username and a dynamically created mail address
  32. else
  33. GIT_AUTHOR_NAME="$USER"
  34. GIT_AUTHOR_EMAIL="$USER@$(hostname -a)"
  35. fi
  36.  
  37. # export the git authorship information into the environment
  38. export GIT_AUTHOR_NAME
  39. export GIT_AUTHOR_EMAIL
  40.  
  41. # finally execute the preferred shell
  42. exec "$SHELL"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement