#!/bin/bash
#Importing gpg key via cli
#https://d.sb/2016/11/gpg-inappropriate-ioctl-for-device-errors
FILE="$1"
GPG_KEY="$2"
TMP_KEY_PATH="/tmp_key.gpg"

if [[ ! -f "$GPG_KEY" ]]; then
    cat <<EOF > "$TMP_KEY_PATH"
$GPG_KEY
EOF
    GPG_KEY="$TMP_KEY_PATH"
fi

#Only seems to import files, not STDIN.
#gpg --import does not work with 'rpm -K'
rpm --import "$GPG_KEY"
rm -f "$TMP_KEY_PATH"

rpm -K $FILE

exit $?