3
# Copyright (C) 2023 Etersoft
4
# Copyright (C) 2023 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
load_helper epm-sh-altlinux
24
__epm_get_file_from_url()
28
tmpfile=$(mktemp) || fatal
29
remove_on_exit $tmpfile
30
eget -O "$tmpfile" "$url" >/dev/null
34
__epm_addkey_altlinux()
39
if is_url "$url" ; then
40
name="$(basename "$url" .gpg)"
48
if is_url "$url" ; then
58
[ -n "$2" ] && name="$2"
60
[ -s /etc/apt/vendors.list.d/$name.list ] && return
62
# TODO: get this info from the gpg key
63
cat << EOF | sudorun tee /etc/apt/vendors.list.d/$name.list
65
FingerPrint "$fingerprint";
69
if [ -n "$url" ] ; then
70
local tmpfile=$(__epm_get_file_from_url $url) || fatal
71
sudocmd gpg --no-default-keyring --keyring /usr/lib/alt-gpgkeys/pubring.gpg --import $tmpfile
81
if is_url "$url" ; then
82
name="$(basename "$url" .rsa)"
89
local target="/etc/apk/keys/$name.rsa"
91
[ -s $target ] && return
93
local tmpfile=$(__epm_get_file_from_url $url) || fatal
94
sudocmd cp $tmpfile $target
103
if is_url "$url" ; then
104
name="$(basename "$url" .gpg)"
113
[ -n "$3" ] && name="$3"
115
# TODO: missed name, nametext, gpgkeyurl (disable gpgcheck=1)
117
local target="/etc/yum.repos.d/$name.repo"
118
[ -s $target ] && return
121
tmpfile=$(mktemp) || fatal
122
remove_on_exit $tmpfile
132
sudocmd cp $tmpfile $target
141
if is_url "$url" ; then
142
name="$(basename "$url" .gpg)"
148
local fingerprint="$1"
151
[ -n "$3" ] && name="$3"
153
# FIXME: check by GPG PUBKEY
154
[ -s /etc/apt/trusted.gpg.d/$name.gpg ] && return
156
if [ -z "$fingerprint" ] ; then
157
local tmpfile=$(__epm_get_file_from_url $url) || fatal
158
if cat $tmpfile | head -n3 | grep -- "-----BEGIN PGP PUBLIC KEY BLOCK-----" ; then
159
# This is a GnuPG extension to OpenPGP
160
cat $tmpfile | a= gpg --dearmor >$tmpfile
162
sudocmd apt-key add $tmpfile
164
# if [ ! -f /etc/apt/trusted.gpg.d/$name.gpg ]; then
165
# epm tool eget -q -O /etc/apt/trusted.gpg.d/$name.gpg https://example.com/$name.gpg > /dev/null
166
# chmod 0644 /etc/apt/trusted.gpg.d/$name.gpg
171
sudocmd apt-key adv --keyserver "$url" --recv "$fingerprint"
178
if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ -z "$1" ] ; then
179
echo "Usage: $ epm repo addkey [name] [url] [fingerprint/gpgkey] [comment/name]"
186
case $BASEDISTRNAME in
188
__epm_addkey_altlinux "$@"
192
__epm_addkey_alpine "$@"
199
__epm_addkey_deb "$@"
202
__epm_addkey_dnf "$@"