# Contributor: Matt Smith <mcs@darkregion.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=alpine-mirrors
pkgver=3.5.8
pkgrel=0
pkgdesc="List of Alpine Linux Mirrors"
url="https://alpinelinux.org/"
arch="noarch"
license="MIT"
depends=""
checkdepends="curl"
install=""
subpackages=""
source="mirrors.yaml"

build() {
	cd "$srcdir"
	awk '$1 == "-" && $2 ~ /^http:/ {print $2}' mirrors.yaml > MIRRORS.txt
}

check() {
	cd "$srcdir"
	local failed=""
	for i in $(cat MIRRORS.txt); do
		msg "testing $i"
		curl --head --connect-timeout 10 $i >/dev/null \
			|| failed="$failed $i"
	done
	if [ -n "$failed" ]; then
		error "Following mirrors failed:"
		for i in $failed; do
			echo $i
		done
		return 1
	fi
}

package() {
	install -D -m644 "$srcdir"/mirrors.yaml \
		"$pkgdir"/usr/share/alpine-mirrors/mirrors.yaml || return 1
	install -D -m644 "$srcdir"/MIRRORS.txt \
		"$pkgdir"/usr/share/alpine-mirrors/MIRRORS.txt || return 1
}

sha512sums="48e19199dd282aecf3e57c3c1a4d6be3434147571af8d04a4e1e3b0ddaf3db16c7ee6c7abade644150722d26881e16d6076026fdcba7a1e56e519b7fb083d015  mirrors.yaml"
