#!/bin/ash

# =============================================================================
# Import PGP keys
# Copyright (C) SFR 2016
# License: GNU GPL Version 3 or later
# Requirements: gpg2/gpg, Xdialog
# =============================================================================

export TEXTDOMAIN=fatdog
export OUTPUT_CHARSET=UTF-8

APPTITLE="$(gettext "Import PGP keys")"
ICON_OK="/usr/local/lib/X11/pixmaps/ok.xpm"
ICON_ERROR="/usr/local/lib/X11/pixmaps/error.xpm"

which gpg2 >/dev/null 2>&1 && GPG=gpg2 || GPG=gpg

# -----------------------------------------------------------------------------

[ -e "$1" ] || exit 1

# In case of accidental click
Xdialog --title "${APPTITLE}" \
		--backtitle "$1" \
		--yesno "$(gettext "Do you want to import/merge keys from this file?")" 0 0
[ $? -ne 0 ] && exit

# Import
RESULT="$(${GPG} --import "${1}" 2>&1)"

# Icon depends on return code
if [ $? -eq 0 ]; then
	ICON="${ICON_OK}"
else
	ICON="${ICON_ERROR}"
fi

# Show the result
Xdialog --title "${APPTITLE}" \
		--icon "${ICON}" \
		--backtitle "${1}" \
		--infobox "${RESULT}" 0 0 999999999

exit

###############################################################################
