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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/identity"
  18. configfile="${confdir}/config"
  19. sshwrapperfile="${confdir}/git-ssh-wrap"
  20. if [ "$1" = "" -o '-h' = "$1" -o '--help' = "$1" ]
  21. then
  22. echo "Usage: $0 KEYNAME [SSH-KEYGEN-PARAMETERS]"
  23. else
  24. id="${1}"
  25. shift
  26. comment="id@anonymous"
  27. echo "-> Creating ${confdir}."
  28. mkdir -p "${confdir}/ssh"
  29. echo "-> Creating SSH key '${sshfile}'."
  30. echo "SSH key comment (public) is '${comment}'."
  31. ssh-keygen -C "${comment}" -f "${sshfile}" "$@"
  32. echo "-> Creating SSH wrapper '${sshwrapperfile}'."
  33. cat "${dir}/git-ssh-wrap" | sed "s/KEYNAME/${id}/" > "${sshwrapperfile}"
  34. chmod 755 "${sshwrapperfile}"
  35. echo "-> Creating config file '${configfile}'."
  36. cp ${dir}/config "${configfile}"
  37. echo "-> Pubkey follows:"
  38. echo
  39. cat ${sshfile}.pub
  40. echo
  41. echo " *** You should now edit '${configfile}' and set your own pseudonymous username and email. ***"
  42. echo
  43. echo "-> To use your new identity:"
  44. echo ". ${0/-setup/} ${id}"
  45. fi