mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-29 13:52:20 +00:00
fix(go-xcat): install the apt key without apt-key
apt 3, which Ubuntu 26.04 ships, has no apt-key, so go-xcat stopped with "import xcat apt key failed" before it configured a repository. On Ubuntu 18.04 to 24.04, apt-key also fails when gnupg is not installed, and go-xcat does not install it. Decode the armored key with base64 and install it as the binary keyring /etc/apt/trusted.gpg.d/xcat.gpg. Every apt release reads that file, while apt 1.0 and 1.2 on Ubuntu 14.04 and 16.04 ignore an armored key there. The key stays trusted for all repositories, as it was with apt-key. A complete uninstall removes the key with the repository files. As with apt-key, a download that holds no public key stops go-xcat and leaves the installed key in place. go-xcat refuses a download whose armored blocks do not all end with their END line, as a truncated download does. It accepts the keyring only when it starts with a public key packet, the check apt applies to a binary keyring.
This commit is contained in:
@@ -185,6 +185,7 @@ function version()
|
||||
|
||||
GO_XCAT_DEFAULT_BASE_URL="http://xcat.org/files/xcat/repos"
|
||||
GO_XCAT_DEFAULT_INSTALL_PATH="/install/xcat"
|
||||
GO_XCAT_APT_KEY_FILE="/etc/apt/trusted.gpg.d/xcat.gpg"
|
||||
|
||||
# The package list of xcat-core
|
||||
GO_XCAT_CORE_PACKAGE_LIST=()
|
||||
@@ -1646,7 +1647,17 @@ function add_xcat_core_repo_apt()
|
||||
local tmp="${TMP_DIR}/tmp_xcat.key"
|
||||
download_file "${url}" "${tmp}"
|
||||
warn_if_bad "$?" "download xcat apt key failed" || return 1
|
||||
apt-key add "${tmp}"
|
||||
# apt 3 has no apt-key, and apt before 1.4 reads only binary keyrings, which start with 0x98, 0x99 or 0xc6.
|
||||
# A truncated download has a block without its END line, so it is refused.
|
||||
awk '/^-----BEGIN PGP PUBLIC KEY BLOCK-----$/ { o = h = 1; b = 0; next }
|
||||
/^-----END PGP PUBLIC KEY BLOCK-----$/ { if (!o) bad = 1; o = h = b = 0; n++; next }
|
||||
h && /^$/ { h = 0; b = 1; next }
|
||||
b && /^=/ { b = 0; next }
|
||||
b { print }
|
||||
END { exit (bad || o || !n) }' "${tmp}" >"${tmp}.b64" &&
|
||||
base64 -d "${tmp}.b64" >"${tmp}.gpg" 2>/dev/null &&
|
||||
od -An -tx1 -N1 "${tmp}.gpg" | grep -qE '^ (98|99|c6)$' &&
|
||||
install -D -m 0644 "${tmp}.gpg" "${GO_XCAT_APT_KEY_FILE}"
|
||||
warn_if_bad "$?" "import xcat apt key failed" || return 1
|
||||
case "${ver}" in
|
||||
"devel")
|
||||
@@ -2194,6 +2205,7 @@ function trash_xcat()
|
||||
rm -rf /etc/xcat
|
||||
rm -rf /etc/xcatdockerca
|
||||
rm -f /etc/apt/sources.list.d/xcat-{core,dep}.list
|
||||
rm -f "${GO_XCAT_APT_KEY_FILE}"
|
||||
rm -f /etc/yum.repos.d/xCAT-{core,dep,dep-common}.repo{,.nouse}
|
||||
rm -f /etc/yum.repos.d/xcat-{core,dep,dep-common}.repo
|
||||
rm -f /etc/zypp/repos.d/xCAT-{core,dep,dep-common}.repo{,.nouse}
|
||||
|
||||
Reference in New Issue
Block a user