summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-02-27 14:55:58 -0500
committerB Stack <bgstack15@gmail.com>2020-02-27 14:55:58 -0500
commit612e62d7919a974ff29d7720922daaf6a808b75b (patch)
tree3479a2ee9bf0a9d0e039f0b3c174bbe6aab6ef82
parentrefactor again (diff)
downloadformer-gists-612e62d7919a974ff29d7720922daaf6a808b75b.tar.gz
former-gists-612e62d7919a974ff29d7720922daaf6a808b75b.tar.bz2
former-gists-612e62d7919a974ff29d7720922daaf6a808b75b.zip
add use_top_result flag, and timestamp sorting
-rwxr-xr-xobsmirror.sh/obsmirror.sh30
1 files 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}"
bgstack15