[lxc-devel] [PATCH] lxc-alpine: download statically compiled package manager if not available on host

Kaarle Ritvanen kaarle.ritvanen at datakunkku.fi
Tue May 14 16:27:32 UTC 2013


Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen at datakunkku.fi>
---
 templates/lxc-alpine.in | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 98347ed..528ebca 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -1,6 +1,9 @@
 #!/bin/sh
 
 install_alpine() {
+    apk=${APK:-apk}
+    apk_opts=
+    
     rootfs="$1"
     shift
     mkdir -p "$rootfs"/etc/apk || return 1
@@ -10,11 +13,32 @@ install_alpine() {
     else
         cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
     fi
-    opt_arch=
+    
     if [ -n "$apk_arch" ]; then
-        opt_arch="--arch $apk_arch"
+        apk_opts="--arch $apk_arch"
     fi
-    ${APK:-apk} add -U --initdb --root $rootfs $opt_arch "$@" alpine-base
+    
+    if ! which $apk &> /dev/null; then
+        wget="wget -O - $repository/x86"
+        
+        apk_version=$($wget/APKINDEX.tar.gz | \
+            tar -Oxz APKINDEX | \
+            sed 's/^$//;Ta;x;
+                 s/^\(.*\n\)P:apk-tools-static\(\n.*\)$/\1\2/;Tb;
+                 s/^\(.*\n\)V:\([^\n]\+\)\(\n.*\)$/\2/;t;
+                 :a;H;:b;d')
+        [ "$apk_version" ] || return 1
+        
+        apk=$(mktemp /tmp/apk.static.XXXXXX)
+        trap "rm -f $apk" EXIT
+        $wget/apk-tools-static-$apk_version.apk | \
+            tar -Oxz sbin/apk.static > $apk || return 1
+        chmod u+x $apk
+        
+        apk_opts="$apk_opts --allow-untrusted"
+    fi
+    
+    $apk add -U --initdb --root $rootfs $apk_opts "$@" alpine-base
 }
 
 configure_alpine() {
-- 
1.8.1.4





More information about the lxc-devel mailing list