update list of debian-based distros
[build.git] / lbuild-initvm.sh
index ee669c1..19e2743 100755 (executable)
@@ -535,7 +535,7 @@ function package_method () {
     fcdistro=$1; shift
     case $fcdistro in
        f[0-9]*|centos[0-9]*|sl[0-9]*) echo yum ;;
-       lenny|etch) echo debootstrap ;;
+       squeeze|wheezy|oneiric|precise|quantal|raring|saucy) echo debootstrap ;;
        *) echo Unknown distro $fcdistro ;;
     esac 
 }
@@ -581,23 +581,26 @@ function setup_lxc() {
         exit 1
     fi
 
-    install_fedora
-    if [ $? -ne 0 ]; then
-        echo "failed to install fedora"
-        exit 1
-    fi
-
-    configure_fedora
-    if [ $? -ne 0 ]; then
-        echo "failed to configure fedora for a container"
-        exit 1
-    fi
-
-    if [ "$(echo $fcdistro | cut -d"f" -f2)" -le "14" ]; then
-        configure_fedora_init
-    else
-        configure_fedora_systemd
-    fi
+    pkg_method=$(package_method $fcdistro)
+    case $pkg_method in
+       yum)
+           install_fedora || { echo "failed to install fedora"; exit 1 ; }
+           configure_fedora || { echo "failed to configure fedora for a container"; exit 1 ; }
+           if [ "$(echo $fcdistro | cut -d"f" -f2)" -le "14" ]; then
+               configure_fedora_init
+           else
+               configure_fedora_systemd
+           fi
+           ;;
+       debootstrap)
+           echo "$COMMAND: no support for debootstrap-based systems - yet"
+           exit 1
+           ;;
+       *)
+           echo "$COMMAND:: unknown package_method - exiting"
+           exit 1
+           ;;
+    esac
 
     # Enable cgroup
     mkdir $rootfs_path/cgroup
@@ -607,7 +610,7 @@ function setup_lxc() {
     # and /etc/hosts for at least localhost
     [ -f $rootfs_path/etc/hosts ] || echo "127.0.0.1 localhost localhost.localdomain" > $rootfs_path/etc/hosts
     
-    # ssh access to lxc
+    # grant ssh access from host to guest
     mkdir $rootfs_path/root/.ssh
     cat /root/.ssh/id_rsa.pub >> $rootfs_path/root/.ssh/authorized_keys
     
@@ -674,13 +677,7 @@ function devel_or_vtest_tools () {
 
     pkg_method=$(package_method $fcdistro)
 
-    # check for .pkgs file based on pldistro
-    if [ -n "$BUILD_MODE" ] ; then
-       pkgsname=devel.pkgs
-    else
-       pkgsname=vtest.pkgs
-    fi
-    pkgsfile=$(pl_locateDistroFile $DIRNAME $pldistro $pkgsname)
+    pkgsfile=$(pl_locateDistroFile $DIRNAME $pldistro $PREINSTALLED)
 
     ### install individual packages, then groups
     # get target arch - use uname -i here (we want either x86_64 or i386)
@@ -718,13 +715,17 @@ function devel_or_vtest_tools () {
 }
 
 function post_install () {
+    lxc=$1; shift 
+    personality=$1; shift
     if [ -n "$BUILD_MODE" ] ; then
-       post_install_build "$@" 
+       post_install_build $lxc $personality
+       start_lxc $lxc
     else
-       post_install_myplc "$@"
+       post_install_myplc $lxc $personality
+       start_lxc $lxc
+       wait_for_ssh $lxc
     fi
     # setup localtime from the host
-    lxc=$1; shift 
     cp /etc/localtime $rootfs_path/etc/localtime
 }
 
@@ -785,7 +786,7 @@ PROFILE
     fi
 #
 EOF
-
+       
 }
 
 function post_install_myplc  () {
@@ -829,6 +830,16 @@ function start_lxc() {
   
     virsh -c lxc:// start $lxc
   
+    return 0
+}
+
+function wait_for_ssh () {
+    set -x
+    set -e
+    #trap failure ERR INT
+
+    lxc=$1; shift
+  
     echo $IP is up, waiting for ssh...
 
     #wait max 5 min for sshd to start 
@@ -847,7 +858,6 @@ function start_lxc() {
 
     # Thierry: this is fatal, let's just exit with a failure here
     [ -z $ssh_up ] && { echo "SSHD in container $lxc is not running" ; exit 1 ; } 
-
     return 0
 }
 
@@ -890,11 +900,19 @@ function main () {
     RESISTANT=""
     IFNAME=""
     LXC_OPTIONS=""
-    while getopts "f:d:p:i:" opt ; do
+
+    # the set of preinstalled packages - depends on vbuild or vtest
+    if [ -n "$VBUILD_MODE" ] ; then
+       PREINSTALLED=devel.pkgs
+    else
+       PREINSTALLED=vtest.pkgs
+    fi
+    while getopts "f:d:p:P:i:" opt ; do
        case $opt in
            f) fcdistro=$OPTARG;;
            d) pldistro=$OPTARG;;
            p) personality=$OPTARG;;
+           P) PREINSTALLED=$OPTARG;;
            i) IFNAME=$OPTARG;;
            *) usage ;;
        esac
@@ -1011,8 +1029,6 @@ function main () {
 
     post_install $lxc $personality
     
-    start_lxc $lxc
-
     echo $COMMAND Done
 }