Signed-off-by: Kaarle Ritvanen <kaarle.ritva...@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


------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to