From a36611a43af4a0f9b04bc64aeace59e3eb356cbf Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Mon, 13 May 2019 08:26:12 +0200 Subject: [PATCH] apt_key: refatoring Signed-off-by: Yoan Blanc --- bootstrap-salt.sh | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index f3c8112..cd28495 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -1866,6 +1866,26 @@ __apt_get_upgrade_noinput() { } # ---------- end of function __apt_get_upgrade_noinput ---------- +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __temp_gpg_pub +# DESCRIPTION: Create a temporary file for downloading a GPG public key. +#---------------------------------------------------------------------------------------------------------------------- +__temp_gpg_pub() { + if __check_command_exists mktemp; then + tempfile="$(mktemp /tmp/salt-gpg-XXXXXXXX.pub 2>/dev/null)" + + if [ -z "$tempfile" ]; then + echoerror "Failed to create temporary file in /tmp" + return 1 + fi + else + tempfile="/tmp/salt-gpg-$$.pub" + fi + + echo $tempfile +} # ----------- end of function __temp_gpg_pub ----------- + + #--- FUNCTION ------------------------------------------------------------------------------------------------------- # NAME: __apt_key_fetch # DESCRIPTION: Download and import GPG public key for "apt-secure" @@ -1874,8 +1894,13 @@ __apt_get_upgrade_noinput() { __apt_key_fetch() { url=$1 - # shellcheck disable=SC2086 - __fetch_url - "$url" | apt-key add -; return $? + tempfile = __temp_gpg_pub || return 1 + + __fetch_url "$tempfile" "$url" || return 1 + apt-key add "$tempfile" || return 1 + rm -f "$tempfile" + + return 0 } # ---------- end of function __apt_key_fetch ---------- @@ -1887,16 +1912,7 @@ __apt_key_fetch() { __rpm_import_gpg() { url=$1 - if __check_command_exists mktemp; then - tempfile="$(mktemp /tmp/salt-gpg-XXXXXXXX.pub 2>/dev/null)" - - if [ -z "$tempfile" ]; then - echoerror "Failed to create temporary file in /tmp" - return 1 - fi - else - tempfile="/tmp/salt-gpg-$$.pub" - fi + tempfile = __temp_gpg_pub || return 1 __fetch_url "$tempfile" "$url" || return 1 rpm --import "$tempfile" || return 1