From 612e62d7919a974ff29d7720922daaf6a808b75b Mon Sep 17 00:00:00 2001 From: B Stack Date: Thu, 27 Feb 2020 14:55:58 -0500 Subject: add use_top_result flag, and timestamp sorting --- obsmirror.sh/obsmirror.sh | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/obsmirror.sh/obsmirror.sh b/obsmirror.sh/obsmirror.sh index 86180f3..2e913fb 100755 --- a/obsmirror.sh/obsmirror.sh +++ b/obsmirror.sh/obsmirror.sh @@ -58,18 +58,24 @@ test -z "${thisuser}" && thisuser=obsmirror mkdir -p "${workdir}" ; chmod "0755" "${workdir}" ; chown "${thisuser}:$( id -G "${thisuser}" | awk '{print $1}' )" "${workdir}" cd "${workdir}" - # get mirrorlist of Packages.gz file and find the one that lists the most packages - step1="$( curl -s -L "${inurl}/Packages.gz.mirrorlist" )" - options="$( echo "${step1}" | grep -oE 'href="[^"]+">' | awk '!x[$0]++' | sed -r -e 's/^href="//;' -e 's/">$//;' | grep -iE '^(ht|f)tps?:\/\/.*Packages\.gz$' )" - results="$( - for entry in ${options} ; do - curl -s -L "${entry}" | zgrep -cE '^Package:' | sed -r -e "s@\$@ ${entry}@;" - done )" - topresult_line="$( echo "${results}" | sort -nr | head -n1 | sed -r -e 's/\/Packages\.gz$//;' )" - topresult_packagecount="$( echo "${topresult_line}" | awk '{print $1}' )" - topresult="$( echo "${topresult_line}" | awk '{print $2}' )" - echo "USING ${topresult} with ${topresult_packagecount} packages" 1>&2 - inurl="${topresult}" + test "${use_top_result}" = "yes" && { + # get mirrorlist of Packages.gz file and find the one that lists the most packages + step1="$( curl -s -L "${inurl}/Packages.gz.mirrorlist" )" + options="$( echo "${step1}" | grep -oE 'href="[^"]+">' | awk '!x[$0]++' | sed -r -e 's/^href="//;' -e 's/">$//;' | grep -iE '^(ht|f)tps?:\/\/.*Packages\.gz$' )" + echo "${options}" 1>&2 + results="$( + for entry in ${options} ; do + # use package count + #curl -s -L "${entry}" | zgrep -cE '^Package:' | sed -r -e "s@\$@ ${entry}@;" + # use last modified timestamp of Packages.gz file + wget --content-disposition --quiet "${entry}" -O tmpfile.$$ ; find tmpfile.$$ -printf "%T@ ${entry}\n" + done ; rm tmpfile.$$ )" + topresult_line="$( echo "${results}" | sort -nr | head -n1 | sed -r -e 's/\/Packages\.gz$//;' )" + topresult_packagecount="$( echo "${topresult_line}" | awk '{print $1}' )" + topresult="$( echo "${topresult_line}" | awk '{print $2}' )" + echo "USING ${topresult} with ${topresult_packagecount} packages" 1>&2 + inurl="${topresult}" + } step1="$( curl -s -L "${inurl}" )" echo "${step1}" | parse_obs_page_and_subdirs "${inurl}" "${tmpfile}" -- cgit