commit:     4af8d661243e0da0b17210a8ddd788a92b19d19b
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu May 26 18:11:34 2016 +0000
Commit:     Alex Legler <a3li <AT> gentoo <DOT> org>
CommitDate: Fri May 27 11:55:37 2016 +0000
URL:        https://gitweb.gentoo.org/sites/www.git/commit/?id=4af8d661

update-downloads: rewrite to make it easier to manage

This also adds hppa netboot images to the list.

 bin/update-downloads.sh | 98 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 77 insertions(+), 21 deletions(-)

diff --git a/bin/update-downloads.sh b/bin/update-downloads.sh
index 8dea718..3b0b894 100755
--- a/bin/update-downloads.sh
+++ b/bin/update-downloads.sh
@@ -1,24 +1,80 @@
 #!/bin/bash
-ARCHES=(amd64 x86 alpha arm hppa ia64 mips ppc s390 sh sparc)
+# TODO: fix this handling for temp files and if one of the downloads fails but 
not others.
 
-echo -n 'Updating downloads...'
+URI_BASE="http://distfiles.gentoo.org/releases";
 
-# TODO: fix this handling for temp files and if one of the downloads fails but 
not others.
-for arch in "${ARCHES[@]}"; do
-  mkdir -p _data/downloads/${arch}/
-  wget -T 60 
"http://distfiles.gentoo.org/releases/${arch}/autobuilds/latest-iso.txt"; -O 
_data/downloads/${arch}/iso.txt 2>/dev/null
-  wget -T 60 
"http://distfiles.gentoo.org/releases/${arch}/autobuilds/latest-stage3.txt"; -O 
_data/downloads/${arch}/stage3.txt 2>/dev/null
-
-  if [ ${arch} = "amd64" ]; then
-    wget -T 60 
"http://distfiles.gentoo.org/releases/amd64/autobuilds/latest-admincd-amd64.txt";
 -O - >> _data/downloads/${arch}/iso.txt 2>/dev/null
-  elif [ ${arch} = "s390" ]; then
-    wget -T 60 
"http://distfiles.gentoo.org/releases/s390/autobuilds/latest-netboot-s390-initramfs.txt";
 -O - >> _data/downloads/${arch}/iso.txt 2>/dev/null
-    wget -T 60 
"http://distfiles.gentoo.org/releases/s390/autobuilds/latest-netboot-s390-kernel.txt";
 -O - >> _data/downloads/${arch}/iso.txt 2>/dev/null
-    wget -T 60 
"http://distfiles.gentoo.org/releases/s390/autobuilds/latest-netboot-s390x-initramfs.txt";
 -O - >> _data/downloads/${arch}/iso.txt 2>/dev/null
-    wget -T 60 
"http://distfiles.gentoo.org/releases/s390/autobuilds/latest-netboot-s390x-kernel.txt";
 -O - >> _data/downloads/${arch}/iso.txt 2>/dev/null
-  elif [ ${arch} = "x86" ]; then
-    wget -T 60 
"http://distfiles.gentoo.org/releases/x86/autobuilds/latest-admincd-x86.txt"; -O 
- >> _data/downloads/${arch}/iso.txt 2>/dev/null
-  fi
-done
-
-echo 'done.'
+ARCHES=(alpha amd64 arm hppa ia64 mips ppc s390 sh sparc x86)
+
+usage() {
+       cat <<EOF
+Usage: update-downloads.sh
+
+Helper script that runs on the servers to refresh the files that back the
+downloads page: https://gentoo.org/downloads/
+EOF
+       exit 0
+}
+
+fetch() {
+       wget -T 60 -q "$@"
+}
+
+# Append extra images to the specified list.
+# append_list <local file> <list of remote urls to append>
+append_list() {
+       local list=$1 file
+       shift
+       for file in "$@" ; do
+               fetch -O - >>"${list}" "${uri_base}/${file}"
+       done
+}
+
+update_amd64() {
+       append_list "${boot_list}" "latest-admincd-amd64.txt"
+}
+
+update_hppa() {
+       append_list "${boot_list}" latest-netboot-hppa{32,64}.txt
+}
+
+update_s390() {
+       append_list "${boot_list}" 
latest-netboot-s390{,x}-{initramfs,kernel}.txt
+}
+
+update_x86() {
+       append_list "${boot_list}" "latest-admincd-x86.txt"
+}
+
+# Update the bootable & stage lists.
+update_arch() {
+       local arch=$1
+       local uri_base="${URI_BASE}/${arch}/autobuilds"
+       local list_base="_data/downloads/${arch}"
+       local boot_list="${list_base}/iso.txt"
+       local stage_list="${list_base}/stage3.txt"
+
+       mkdir -p "${list_base}"
+       fetch "${uri_base}/latest-iso.txt" -O "${boot_list}"
+       fetch "${uri_base}/latest-stage3.txt" -O "${stage_list}"
+       if [[ $(type -t "update_${arch}") == "function" ]] ; then
+               update_${arch}
+       fi
+}
+
+main() {
+       if [[ $# -ne 0 ]] ; then
+               usage
+       fi
+
+       # Make sure we're in the top level dir.
+       cd "$(dirname "$0")"/..
+
+       local arch
+       printf 'Updating ... '
+       for arch in "${ARCHES[@]}" ; do
+               printf '%s ' "${arch}"
+               update_arch "${arch}"
+       done
+       echo '... done'
+}
+main "$@"

Reply via email to