diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index 8ef13fd282..91adfed726 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -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}