diff --git a/src/freedombone-base-email b/src/freedombone-base-email index f74bc3f6..19ae0854 100755 --- a/src/freedombone-base-email +++ b/src/freedombone-base-email @@ -1514,7 +1514,8 @@ function create_gpg_subkey { chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg 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 } diff --git a/src/freedombone-pass b/src/freedombone-pass index 298e3495..285e2f58 100755 --- a/src/freedombone-pass +++ b/src/freedombone-pass @@ -57,9 +57,7 @@ MASTER_PASSWORD='' NO_PASSWORD_STORE_FILE=~/.nostore function get_backup_key_id { - MY_BACKUP_KEY_ID=$(gpg --list-keys "(backup key)" | \ - grep 'pub ' | awk -F ' ' '{print $2}' | \ - awk -F '/' '{print $2}') + MY_BACKUP_KEY_ID=$(gpg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//') if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then echo $"Error: gpg backup key was not found" return 58213 diff --git a/src/freedombone-splitkey b/src/freedombone-splitkey index 871f6ba7..df8f2fce 100755 --- a/src/freedombone-splitkey +++ b/src/freedombone-splitkey @@ -104,16 +104,14 @@ fi if [ ! $MY_EMAIL_ADDRESS ]; then MY_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME 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 echo $"gpg key for $MY_EMAIL_ADDRESS was not found" exit 3682 fi -MY_BACKUP_KEY_ID=$(gpg --list-keys "$MY_NAME (backup key)" | \ - grep 'pub ' | awk -F ' ' '{print $2}' | \ - awk -F '/' '{print $2}') +MY_BACKUP_KEY_ID=$(gpg --list-keys "$MY_NAME (backup key)" | sed -n '2p' | sed 's/^[ \t]*//') if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then echo $"gpg backup key for '$MY_NAME' was not found" exit 58213 diff --git a/src/freedombone-utils-backup b/src/freedombone-utils-backup index c450e5d1..9073ff90 100755 --- a/src/freedombone-utils-backup +++ b/src/freedombone-utils-backup @@ -84,7 +84,8 @@ function configure_backup_key { exit 43382 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" 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 @@ -251,7 +252,8 @@ function backup_directory_to_usb { restart_site exit 6 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 mkdir -p $USB_MOUNT/backup/${2} fi @@ -357,7 +359,8 @@ function backup_directory_to_friend { restart_site exit 43382 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 mkdir -p $SERVER_DIRECTORY/backup/${2} fi diff --git a/src/freedombone-utils-gpg b/src/freedombone-utils-gpg index bfa7ec3d..17300aa2 100755 --- a/src/freedombone-utils-gpg +++ b/src/freedombone-utils-gpg @@ -33,9 +33,9 @@ function gpg_pubkey_from_email { key_email_address=$2 key_id= 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 - 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 echo $key_id }