You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gitnonymous-setup 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. # figure out which directory we are stored in
  3. # https://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
  4. _GITNONYMOUS_SRC="${BASH_SOURCE[0]}"
  5. # resolve $_GITNONYMOUS_SRC until the file is no longer a symlink
  6. while [ -h "$_GITNONYMOUS_SRC" ]; do
  7. dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
  8. _GITNONYMOUS_SRC="$(readlink "$_GITNONYMOUS_SRC")"
  9. # if $_GITNONYMOUS_SRC was a relative symlink, we need to resolve it
  10. # relative to the path where the symlink file was located
  11. [[ $_GITNONYMOUS_SRC != /* ]] && _GITNONYMOUS_SRC="$DIR/$_GITNONYMOUS_SRC"
  12. done
  13. dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
  14. unset _GITNONYMOUS_SRC
  15. # set up our other variables
  16. confdir="${HOME}/.gitnonymous-${1}"
  17. sshfile="${confdir}/ssh/id_rsa"
  18. configfile="${confdir}/config"
  19. sshwrapperfile="${confdir}/git-ssh-wrap"
  20. if [ "$1" = "" ]
  21. then
  22. echo "Usage: $0 KEYNAME"
  23. else
  24. comment="${1}@anonymous"
  25. echo "-> Creating ${confdir}."
  26. mkdir -p "${confdir}/ssh"
  27. echo "-> Creating SSH key '${sshfile}'."
  28. echo "SSH key comment (public) is '${comment}'."
  29. ssh-keygen -C "${comment}" -f "${sshfile}"
  30. echo "-> Creating SSH wrapper '${sshwrapperfile}'."
  31. cat "${dir}/git-ssh-wrap" | sed "s/KEYNAME/${1}/" > "${sshwrapperfile}"
  32. chmod 755 "${sshwrapperfile}"
  33. echo "-> Creating config file '${configfile}'."
  34. cp ${dir}/config "${configfile}"
  35. echo
  36. echo " *** You should now edit '${configfile}' and set your own username and email. ***"
  37. echo
  38. fi