Convert gpg key ID to v2.x format

This commit is contained in:
Bob Mottram 2017-06-01 20:16:59 +01:00
parent 55e3f4a8ae
commit 7f303823ec
5 changed files with 14 additions and 14 deletions

View File

@ -1514,7 +1514,8 @@ function create_gpg_subkey {
chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
shred -zu /home/$MY_USERNAME/gpg-genkey.conf shred -zu /home/$MY_USERNAME/gpg-genkey.conf
MY_GPG_SUBKEY_ID=$(su -c "gpg --list-keys $MY_EMAIL_ADDRESS | grep 'pub '" - $MY_USERNAME | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
MY_GPG_SUBKEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_EMAIL_ADDRESS")
mark_completed $FUNCNAME mark_completed $FUNCNAME
} }

View File

@ -57,9 +57,7 @@ MASTER_PASSWORD=''
NO_PASSWORD_STORE_FILE=~/.nostore NO_PASSWORD_STORE_FILE=~/.nostore
function get_backup_key_id { function get_backup_key_id {
MY_BACKUP_KEY_ID=$(gpg --list-keys "(backup key)" | \ MY_BACKUP_KEY_ID=$(gpg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
grep 'pub ' | awk -F ' ' '{print $2}' | \
awk -F '/' '{print $2}')
if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then
echo $"Error: gpg backup key was not found" echo $"Error: gpg backup key was not found"
return 58213 return 58213

View File

@ -104,16 +104,14 @@ fi
if [ ! $MY_EMAIL_ADDRESS ]; then if [ ! $MY_EMAIL_ADDRESS ]; then
MY_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME MY_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
fi fi
KEYID=$(su -c "gpg --list-keys $MY_EMAIL_ADDRESS | grep 'pub '" - \
$MY_USERNAME | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') KEYID=$(su -c "gpg --list-keys $MY_EMAIL_ADDRESS" - $MY_USERNAME | sed -n '2p' | sed 's/^[ \t]*//')
if [ ${#KEYID} -lt 4 ]; then if [ ${#KEYID} -lt 4 ]; then
echo $"gpg key for $MY_EMAIL_ADDRESS was not found" echo $"gpg key for $MY_EMAIL_ADDRESS was not found"
exit 3682 exit 3682
fi fi
MY_BACKUP_KEY_ID=$(gpg --list-keys "$MY_NAME (backup key)" | \ MY_BACKUP_KEY_ID=$(gpg --list-keys "$MY_NAME (backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
grep 'pub ' | awk -F ' ' '{print $2}' | \
awk -F '/' '{print $2}')
if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then
echo $"gpg backup key for '$MY_NAME' was not found" echo $"gpg backup key for '$MY_NAME' was not found"
exit 58213 exit 58213

View File

@ -84,7 +84,8 @@ function configure_backup_key {
exit 43382 exit 43382
fi fi
fi fi
MY_BACKUP_KEY_ID=$(su -c "gpg --list-keys \"$MY_NAME (backup key)\" | grep 'pub '" - $MY_USERNAME | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
MY_BACKUP_KEY_ID=$(su -c "gpg --list-keys \"$MY_NAME (backup key)\"" - $MY_USERNAME | sed -n '2p' | sed 's/^[ \t]*//')
echo "Backup key: $MY_BACKUP_KEY_ID" echo "Backup key: $MY_BACKUP_KEY_ID"
MY_BACKUP_KEY=/home/$MY_USERNAME/backup_key MY_BACKUP_KEY=/home/$MY_USERNAME/backup_key
su -m root -c "gpg --homedir /home/$MY_USERNAME/.gnupg --output ${MY_BACKUP_KEY}_public.asc --armor --export $MY_BACKUP_KEY_ID" - $MY_USERNAME su -m root -c "gpg --homedir /home/$MY_USERNAME/.gnupg --output ${MY_BACKUP_KEY}_public.asc --armor --export $MY_BACKUP_KEY_ID" - $MY_USERNAME
@ -251,7 +252,8 @@ function backup_directory_to_usb {
restart_site restart_site
exit 6 exit 6
fi fi
MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
if [ ! -d $USB_MOUNT/backup/${2} ]; then if [ ! -d $USB_MOUNT/backup/${2} ]; then
mkdir -p $USB_MOUNT/backup/${2} mkdir -p $USB_MOUNT/backup/${2}
fi fi
@ -357,7 +359,8 @@ function backup_directory_to_friend {
restart_site restart_site
exit 43382 exit 43382
fi fi
ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
if [ ! -d $SERVER_DIRECTORY/backup/${2} ]; then if [ ! -d $SERVER_DIRECTORY/backup/${2} ]; then
mkdir -p $SERVER_DIRECTORY/backup/${2} mkdir -p $SERVER_DIRECTORY/backup/${2}
fi fi

View File

@ -33,9 +33,9 @@ function gpg_pubkey_from_email {
key_email_address=$2 key_email_address=$2
key_id= key_id=
if [[ $key_owner_username != "root" ]]; then if [[ $key_owner_username != "root" ]]; then
key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | head -n 1 | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') key_id=$(su -c "gpg --list-keys $key_email_address" - $key_owner_username | sed -n '2p' | sed 's/^[ \t]*//')
else else
key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | head -n 1 | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') key_id=$(gpg --list-keys $key_email_address | sed -n '2p' | sed 's/^[ \t]*//')
fi fi
echo $key_id echo $key_id
} }