123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/usr/bin/env bash
-
- # figure out which directory we are stored in
- # https://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
- _GITNONYMOUS_SRC="${BASH_SOURCE[0]}"
- # resolve $_GITNONYMOUS_SRC until the file is no longer a symlink
- while [ -h "$_GITNONYMOUS_SRC" ]; do
- dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
- _GITNONYMOUS_SRC="$(readlink "$_GITNONYMOUS_SRC")"
- # if $_GITNONYMOUS_SRC was a relative symlink, we need to resolve it
- # relative to the path where the symlink file was located
- [[ $_GITNONYMOUS_SRC != /* ]] && _GITNONYMOUS_SRC="$DIR/$_GITNONYMOUS_SRC"
- done
- dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
- unset _GITNONYMOUS_SRC
-
- # set up our other variables
- confdir="${HOME}/.gitnonymous-${1}"
- sshfile="${confdir}/ssh/identity"
- configfile="${confdir}/config"
- sshwrapperfile="${confdir}/git-ssh-wrap"
-
- if [ "$1" = "" -o '-h' = "$1" -o '--help' = "$1" ]
- then
- echo "Usage: $0 KEYNAME [SSH-KEYGEN-PARAMETERS]"
- else
- id="${1}"
- shift
- comment="id@anonymous"
- echo "-> Creating ${confdir}."
- mkdir -p "${confdir}/ssh"
- echo "-> Creating SSH key '${sshfile}'."
- echo "SSH key comment (public) is '${comment}'."
- ssh-keygen -C "${comment}" -f "${sshfile}" "$@"
- echo "-> Creating SSH wrapper '${sshwrapperfile}'."
- cat "${dir}/git-ssh-wrap" | sed "s/KEYNAME/${id}/" > "${sshwrapperfile}"
- chmod 755 "${sshwrapperfile}"
- echo "-> Creating config file '${configfile}'."
- cp ${dir}/config "${configfile}"
- echo "-> Pubkey follows:"
- echo
- cat ${sshfile}.pub
- echo
- echo " *** You should now edit '${configfile}' and set your own pseudonymous username and email. ***"
- echo
- echo "-> To use your new identity:"
- echo ". ${0/-setup/} ${id}"
- fi
|