skip gpg check when debootstrapping
[build.git] / lbuild-initvm.sh
index a8edc71..46a9b5a 100755 (executable)
@@ -24,7 +24,7 @@ export PATH=$PATH:/bin:/sbin
 DEFAULT_FCDISTRO=f21
 DEFAULT_PLDISTRO=lxc
 DEFAULT_PERSONALITY=linux64
-DEFAULT_MEMORY=1024
+DEFAULT_MEMORY=2048
 
 ##########
 # constant
@@ -73,7 +73,7 @@ function package_method () {
     fcdistro=$1; shift
     case $fcdistro in
        f[0-9]*|centos[0-9]*|sl[0-9]*) echo yum ;;
-       squeeze|wheezy|jessie|oneiric|precise|quantal|raring|saucy|trusty|utopic) echo debootstrap ;;
+       squeeze|wheezy|jessie|oneiric|precise|quantal|raring|saucy|trusty|utopic|vivid) echo debootstrap ;;
        *) echo Unknown distro $fcdistro ;;
     esac 
 }
@@ -361,14 +361,17 @@ EOF
 }    
 
 ##############################
+# apparently ubuntu exposes a mirrors list by country at
+# http://mirrors.ubuntu.com/mirrors.txt
 # need to specify the right mirror for debian variants like ubuntu and the like
 function debian_mirror () {
     fcdistro=$1; shift
     case $fcdistro in
        squeeze|wheezy|jessie) 
            echo http://ftp2.fr.debian.org/debian/ ;;
-       oneiric|precise|quantal|raring|saucy|trusty|utopic) 
-           echo http://mir1.ovh.net/ubuntu/ubuntu/ ;;
+       oneiric|precise|quantal|raring|saucy|trusty|utopic|vivid) 
+#          echo http://mir1.ovh.net/ubuntu/ubuntu/ ;;
+           echo http://www-ftp.lip6.fr/pub/linux/distributions/Ubuntu/archive/ ;;
        *) echo unknown distro $fcdistro; exit 1;;
     esac
 }
@@ -380,7 +383,7 @@ function debian_install () {
     mkdir -p $lxc_root
     arch=$(canonical_arch $personality $fcdistro)
     mirror=$(debian_mirror $fcdistro)
-    debootstrap --arch $arch $fcdistro $lxc_root $mirror
+    debootstrap --no-check-gpg --arch $arch $fcdistro $lxc_root $mirror
     # just like with fedora we ensure a few packages get installed as well
     # not started yet
     #virsh -c lxc:/// lxc-enter-namespace $lxc /usr/bin/$personality /bin/bash -c "apt-get update"
@@ -518,6 +521,7 @@ function write_lxc_xml_publicip () {
 EOF
 }
 
+# grant build guests the ability to do mknods
 function write_lxc_xml_natip () { 
     lxc=$1; shift
     cat <<EOF
@@ -530,6 +534,9 @@ function write_lxc_xml_natip () {
   </os>
   <features>
     <acpi/>
+    <capabilities policy='default'>
+      <mknod state='on'/>
+    </capabilities>
   </features>
   <vcpu>1</vcpu>
   <clock offset='utc'/>
@@ -706,23 +713,18 @@ PROFILE
 EOF
 }
 
+########################################
 # workaround for broken lxc-enter-namespace
-# relies on virsh net-dhcp-leases
-# when successful we store result in /vservers/<container>/ipv4
-# because the lease expires afer a while 
-function guest_ipv4_cached_or_from_virsh_leases() {
+# 1st version was relying on virsh net-dhcp-leases
+# however this was too fragile, would not work for fedora14 containers
+# WARNING: this code is duplicated in lbuild-nightly.sh
+function guest_ipv4() {
     lxc=$1; shift
-    network=default
-    
-    # place to cache result
-    cache=/vservers/$lxc/ipv4
-    ipv4=$(cat $cache 2> /dev/null)
-    [ -z "$ipv4" ] && ipv4=$(virsh net-dhcp-leases $network | sed -e 's,  *, ,g' | grep " $lxc " | grep ipv4 |  cut -d' ' -f6 | cut -d/ -f1)
-    echo $ipv4
-    # cache if needed
-    [ -n "$ipv4" -a ! -f $cache ] && echo $ipv4 > $cache
-    # always return 0
-    return 0
+
+    mac=$(virsh -c lxc:/// domiflist $lxc | egrep 'network|bridge' | awk '{print $5;}')
+    # sanity check
+    [ -z "$mac" ] && return 0
+    arp -en | grep "$mac" | awk '{print $1;}'
 }
 
 function wait_for_ssh () {
@@ -742,7 +744,7 @@ function wait_for_ssh () {
     counter=1
     while [ "$current_time" -lt "$stop_time" ] ; do
          echo "$counter-th attempt to reach sshd in container $lxc ..."
-        [ -z "$guest_ip" ] && guest_ip=$(guest_ipv4_cached_or_from_virsh_leases $lxc)
+        [ -z "$guest_ip" ] && guest_ip=$(guest_ipv4 $lxc)
         [ -n "$guest_ip" ] && ssh -o "StrictHostKeyChecking no" $guest_ip 'uname -i' && { 
                 success=true; echo "SSHD in container $lxc is UP on IP $guest_ip"; break ; } || :
          counter=$(($counter+1))