123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
-
-
-
-
-
-
-
- _GITNONYMOUS_SRC="${BASH_SOURCE[0]}"
-
- while [ -h "$_GITNONYMOUS_SRC" ]; do
- dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
- _GITNONYMOUS_SRC="$(readlink "$_GITNONYMOUS_SRC")"
-
-
- [[ $_GITNONYMOUS_SRC != /* ]] && _GITNONYMOUS_SRC="$DIR/$_GITNONYMOUS_SRC"
- done
- dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
- unset _GITNONYMOUS_SRC
-
- gitnonymous_usage () {
- if [ "$1" != "" ]
- then
- gitnonymous_error "Don't call this script directly. 'Source' it instead."
- fi
- echo "Usage:"
- echo ". ${BASH_SOURCE[0]} KEYNAME"
- }
-
-
- gitnonymous_error () {
- >&2 echo $@
- }
-
-
- gitnonymous_error_missing () {
- gitnonymous_error $@
- gitnonymous_error "To create it run: ${dir}/gitnonymous-setup ${keyname}"
- }
-
-
- if [[ "${BASH_SOURCE[0]}" != "$0" ]]
- then
-
- if [ "$1" = "" ]
- then
- gitnonymous_usage
- return 1
- else
-
- keyname="${1}"
- rootdir="${HOME}/.gitnonymous-${keyname}"
- configfile="${rootdir}/config"
- sshdir="${rootdir}/ssh"
- oldenvfile="${rootdir}/previous-environment"
- sshagentsocket="${sshdir}/.ssh-agent-$$"
-
- if [ "$_GITNONYMOUS" != "" ]
-
- then
- echo "Unsetting gitnonymous environment ${keyname}"
-
- ssh-agent -k
-
- export PS1="${_GITNONYMOUS_OLDPS1}"
- unset GIT_COMMITTER_EMAIL
- unset GIT_COMMITTER_NAME
- unset GIT_AUTHOR_EMAIL
- unset GIT_AUTHOR_NAME
- unset GIT_SSH
- unset GIT_PROXY_COMMAND
- unset ALL_PROXY
- unset TZ
-
- . "${oldenvfile}"
-
- unset _GITNONYMOUS_OLDPS1
- unset _GITNONYMOUS
- echo "Done unsetting ${keyname}."
- else
-
- if [ -f ${sshdir}/id_rsa -o -f ${sshdir}/identity ]
- then
-
- if [ -f "${sshagentsocket}" ]
- then
- gitnonymous_error "Stale SSH agent socket '${sshagentsocket}' exists."
- gitnonymous_error "You can probably delete it safely and try again."
- return 2
- fi
-
- eval $(ssh-agent -a "${sshagentsocket}")
-
- if [ -f ${sshdir}/id_rsa ]
- then
- ssh-add ${sshdir}/id_rsa
- else
- ssh-add ${sshdir}/identity
- fi
- else
- gitnonymous_error_missing "SSH config in ${sshdir} not found!"
- return 3
- fi
-
-
- if [ -f "${configfile}" ]
- then
-
- export | grep -E "GIT_|ALL_PROXY|TZ" > ${oldenvfile}
-
- . "${configfile}"
- else
- gitnonymous_error_missing "GIT config in ${configfile} not found!"
- return 4
- fi
-
-
- trap 'ssh-agent -k' EXIT
-
-
- export GIT_SSH="${rootdir}/git-ssh-wrap"
-
-
- export GIT_PROXY_COMMAND="${dir}/git-proxy-command"
- export ALL_PROXY="socks5://127.0.0.1:9050"
-
-
- _GITNONYMOUS_OLDPS1="${PS1}"
- export PS1="${keyname}⚔ ${PS1}"
- export _GITNONYMOUS="${keyname}"
- fi
- fi
- else
- gitnonymous_usage true
- exit 2
- fi
|