From 52ded095e05aa04a9fd798e885975f5d0ca3d3d3 Mon Sep 17 00:00:00 2001 From: Shubham Shinde Date: Tue, 26 Nov 2024 19:43:58 +0530 Subject: [PATCH] Update install.sh script and the puppet_agent and facts submodules --- install.sh | 35 ++++++++++++++++++++++++++++++++++- modules/facts | 2 +- modules/puppet_agent | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 2bb7772..375f59b 100755 --- a/install.sh +++ b/install.sh @@ -234,6 +234,9 @@ ID="$(munge_name "$ID")" family="$(munge_name "$family")" #!/usr/bin/env bash + +set -e + # Install puppet-agent as a task # # From https://github.com/petems/puppet-install-shell/blob/master/install_puppet_5_agent.sh @@ -301,6 +304,11 @@ assert_unmodified_apt_config() { fi } +# Check whether apt-helper is available +exists_apt_helper() { + test -x /usr/lib/apt/apt-helper +} + # Check whether python3 and urllib.request are available exists_python3_urllib() { python3 -c 'import urllib.request' >/dev/null 2>&1 @@ -662,6 +670,27 @@ do_fetch() { return 0 } +do_apt_helper() { + info "Trying apt-helper..." + run_cmd "/usr/lib/apt/apt-helper download-file '$1' '$2'" 2>$tmp_stderr + rc=$? + + # check for 404 + grep "E: Failed to fetch .* 404 " $tmp_stderr 2>&1 >/dev/null + if test $? -eq 0; then + critical "ERROR 404" + unable_to_retrieve_package + fi + + # check for bad return status or empty output + if test $rc -ne 0 && test ! -s "$2" ; then + capture_tmp_stderr "apthelper" + return 1 + fi + + return 0 +} + do_python3_urllib() { info "Trying python3 (urllib.request)..." run_cmd "python3 -c 'import urllib.request ; urllib.request.urlretrieve(\"$1\", \"$2\")'" 2>$tmp_stderr @@ -755,7 +784,11 @@ do_download() { do_python3_urllib $1 $2 && return 0 fi - critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple/perl-File-Fetch/python3 is found" + if exists_apt_helper; then + do_apt_helper $1 $2 && return 0 + fi + + critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple/perl-File-Fetch/python3/apt-helper is found" unable_to_retrieve_package } diff --git a/modules/facts b/modules/facts index 0f413a6..9792035 160000 --- a/modules/facts +++ b/modules/facts @@ -1 +1 @@ -Subproject commit 0f413a6a30e93001d1da44e25efc141205ddf549 +Subproject commit 9792035f3a6ad6a31e2de2959dddf1da998edcd6 diff --git a/modules/puppet_agent b/modules/puppet_agent index 4ba46ba..7a5bedd 160000 --- a/modules/puppet_agent +++ b/modules/puppet_agent @@ -1 +1 @@ -Subproject commit 4ba46baaa9dc68d2a8adf35b335a405944cea9a9 +Subproject commit 7a5bedd21b0a55da754479e4cc7e2297595d9fb1