Last active
August 29, 2015 14:15
-
-
Save jacoelho/05bf3c14dc07ccaaded3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# From https://raw.githubusercontent.com/mtpereira/scripts/master/setup_blackbox.sh | |
# Manuel Tiago Pereira ([email protected]) | |
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="[email protected]: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