Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- set -eu
- # we only want to run this script as root
- if [ ! $(id -u) = 0 ]; then
- echo "This script must be run as root" 1>&2
- exit 1
- fi
- # use environment variable for user
- # or fallback to logname
- USER="${SOURCE_USER:-$(logname)}"
- # get user home directory and preferred shell
- HOME="$(getent passwd "$USER" | cut -d: -f6)"
- SHELL="$(getent passwd "$USER" | cut -d: -f7)"
- # in case the users preferred shell defaulted to this
- # script we fallback to bash
- if [ "$SHELL" = "$0" ]; then
- SHELL=/bin/bash
- fi
- # if the user has a custom gitconfig we use it to define the
- # git author and email
- if [ -n "$HOME" ] && [ -e "$HOME/.gitconfig" ]; then
- GIT_AUTHOR_NAME="$(git config -f "$HOME/.gitconfig" user.name)"
- GIT_AUTHOR_EMAIL="$(git config -f "$HOME/.gitconfig" user.email)"
- # in case no custom gitconfig has been provided we fallback to
- # the username and a dynamically created mail address
- else
- GIT_AUTHOR_NAME="$USER"
- GIT_AUTHOR_EMAIL="$USER@$(hostname -a)"
- fi
- # export the git authorship information into the environment
- export GIT_AUTHOR_NAME
- export GIT_AUTHOR_EMAIL
- # finally execute the preferred shell
- exec "$SHELL"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement