-
Notifications
You must be signed in to change notification settings - Fork 16
/
gitnonymous-setup
executable file
·48 lines (45 loc) · 1.7 KB
/
gitnonymous-setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/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