Skip to content

Instantly share code, notes, and snippets.

@jacoelho
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacoelho/05bf3c14dc07ccaaded3 to your computer and use it in GitHub Desktop.
Save jacoelho/05bf3c14dc07ccaaded3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# From https://raw.githubusercontent.com/mtpereira/scripts/master/setup_blackbox.sh
# Manuel Tiago Pereira (mt.pereira@gmail.com)
set -eu
gpg_create() {
local email="${1}"
local comment="${2}"
local password
local password2
while true
do
read -s -r -p "Enter your new gpg passphrase: " password
echo
read -s -r -p "Enter your new gpg passphrase (confirm): " password2
echo
[ "$password" = "$password2" ] && break
echo "Please try again"
done
local config=$(mktemp -t gpg-XXXXX)
echo "Creating GPG key..."
cat > ${config} <<EOF
%echo Generating a basic OpenPGP key
Key-Type: DSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: $(finger $(whoami) | egrep -o -w 'Name: .+' | sed -e 's/^Name: //')
Name-Comment: ${comment}
Name-Email: ${email}
Expire-Date: 0
Passphrase: ${password}
%commit
EOF
gpg --batch --gen-key ${config}
rm ${config}
}
blackbox_install() {
# check for blackbox
command -v blackbox_cat >/dev/null 2>&1 || {
# check for brew
command -v brew >/dev/null 2>&1 || {
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
}
brew tap jacoelho/brew || true
brew install jacoelho/brew/blackbox --with-gpg-agent
}
}
blackbox_add() {
local email="${1}"
local repository="${2}"
local tmpdir=$(mktemp -d -t vault-XXXXX)
echo "Adding GPG key to blackbox..."
git clone "${repository}" ${tmpdir}
cd ${tmpdir}
git checkout -b "${email}"
blackbox_addadmin ${email}
git commit -m "NEW ADMIN: ${email}' keyrings/live/pubring.gpg keyrings/live/trustdb.gpg keyrings/live/blackbox-admins.txt"
git push origin "${email}"
rm -rf ${tmpdir}
}
main() {
local email
local repository="git@github.com:croudcare/vault.git"
local comment="Generated on $(hostname) by $(whoami) for blackbox."
read -r -p "Enter your email: " email
blackbox_install
gpg_create ${email} "${comment}"
blackbox_add ${email} "${repository}"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment