aboutsummaryrefslogtreecommitdiff
blob: 3b0b8942faf90b29f508578a567052578d9fa91b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# TODO: fix this handling for temp files and if one of the downloads fails but not others.

URI_BASE="http://distfiles.gentoo.org/releases"

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 "$@"