#!/bin/bash # # A script that generates PGP/GPG keys and saves them to a file. # Copyright (C) 2009 Bogdan 'bogdro' Drozdowski # # # Usage: bash pgpgen-bash.sh [name] # name - an optional filename for the keys to output. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 3 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foudation: # Free Software Foundation # 51 Franklin Street, Fifth Floor # Boston, MA 02110-1301 # USA name= if ( test "x$1" != "x" ); then name=$1 else for ((i=0; i<4000000000; i++)); do if [ ! -e pgp$i-priv.asc ]; then break; fi done name=pgp$i; fi gpg --gen-key # get the newest key's ID number (field 6 is the date, field 5 is the key ID): id=`gpg --list-keys --with-colons | egrep '^pub' | sed 's/:/ /g' | sort -k 6,6 | awk '{print $5}' | tail -1` # export the key: gpg --output $name-priv.asc --textmode --export-secret-keys --armor $id && \ gpg --output $name-pub.asc --textmode --export --armor $id && \ zip $name-keys $name-priv.asc $name-pub.asc && \ gpg --delete-secret-and-public-key $id