setup-apkrepos.in 1.14 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/sh

PROGRAM=setup-apkrepos
PREFIX=

. $PREFIX/lib/libalpine.sh

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
# TODO: change tail command to a random mirror instead of last one in MIRRORS.txt
MIRROR=`wget -O - http://www.alpinelinux.org/alpine/MIRRORS.txt 2>&1 | grep http | awk -F 'ETA' '{print $NF}' | tail -n 1`

# Retrieve version from alpine-release if available
if [ -e /etc/alpine-release ]; then
	release=$(cut -f1 /etc/alpine-release)
	case "$release" in
		*_git*) repo="edge";;
		[0-9]*.[0-9]*.[0-9]*)
			# release in x.y.z format, cut last digit
			repo=v${release%.[0-9]*};;
	esac
	echo "$repo"
else
	while true; do
		printf "Enter repository branch from list below [v2.2]: \n"
		# Retrieve list of versions available on mirror 2.0 and above
		wget "$MIRROR" > /dev/null 2>&1 
		availablerepos=""
		for version in `links ./index.html -dump | grep "v[2-9]" | awk -F '/' '{print $1}'`; do

			availablerepos="$availablerepos $version"
		done
		rm index.html
		availablerepos="$availablerepos edge"
		for i in `echo $availablerepos`; do
			printf "$i\n"
		done
		default_read repo "v2.2"
		if [ $repo ]; then
			break
		fi
	done
41
fi
42 43 44

echo "${MIRROR}${repo}/main" >> /etc/apk/repositories
apk update