]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-alpine: automatic repository selection
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Wed, 26 Jun 2013 08:14:59 +0000 (11:14 +0300)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 27 Jun 2013 13:47:38 +0000 (08:47 -0500)
pick random server from mirror list
use the latest stable release

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
templates/lxc-alpine.in

index cdf2743701f1e99eedd0f5fa5605693d45a1fa9e..b39db1650a65aaea62b857c8a75a9603531fc72c 100644 (file)
@@ -4,14 +4,33 @@ key_sha256sums="9c102bcc376af1498d549b77bdbfa815ae86faa1d2d82f040e616b18ef2df2d4
 2adcf7ce224f476330b5360ca5edb92fd0bf91c92d83292ed028d7c4e26333ab  alpine-devel@lists.alpinelinux.org-4d07755e.rsa.pub"
 
 get_static_apk () {
+    wget="wget -q -O -"
+    pkglist=alpine-keys:apk-tools-static
+    auto_repo_dir=
+
+    if [ -z "$repository" ]; then
+        url=http://wiki.alpinelinux.org/cgi-bin/dl.cgi
+        echo -n "Determining the latest release... "
+        release=$($wget $url/.latest.$apk_arch.txt | \
+            cut -d " " -f 3 | cut -d / -f 1 | uniq)
+        if [ -z "$release" ]; then
+            echo failed
+            return 1
+        fi
+        echo $release
+        auto_repo_dir=$release/main
+        repository=$url/$auto_repo_dir
+        pkglist=$pkglist:alpine-mirrors
+    fi
+
     rootfs="$1"
     echo "Using static apk from $repository/$apk_arch"
-    wget="wget -q -O - $repository/$apk_arch"
+    wget="$wget $repository/$apk_arch"
 
     # parse APKINDEX to find the current versions
     static_pkgs=$($wget/APKINDEX.tar.gz | \
         tar -Oxz APKINDEX | \
-        awk -F: -v pkglist="alpine-keys:apk-tools-static" '
+        awk -F: -v pkglist=$pkglist '
             BEGIN { split(pkglist,pkg) }
             $0 != "" { f[$1] = $2 }
             $0 == "" { for (i in pkg)
@@ -41,6 +60,14 @@ get_static_apk () {
     APK=$rootfs/sbin/apk.static
     openssl dgst -verify $rootfs/etc/apk/keys/$keyname \
         -signature "$APK.SIGN.RSA.$keyname" "$APK" || return 1
+
+    if [ "$auto_repo_dir" ]; then
+        mirror_list=$rootfs/usr/share/alpine-mirrors/MIRRORS.txt
+        mirror_count=$(wc -l $mirror_list | cut -d " " -f 1)
+        repository=$(sed $(expr $RANDOM % $mirror_count + 1)\!d \
+            $mirror_list)$auto_repo_dir
+        echo "Selecting mirror $repository"
+    fi
 }
 
 install_alpine() {