Fix console of xen-pvm
[ext/instance-debootstrap.git] / create
diff --git a/create b/create
index 5933f0b..ff54976 100755 (executable)
--- a/create
+++ b/create
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# Copyright (C) 2007, 2008, 2009 Google Inc.
+# Copyright (C) 2007, 2008, 2009, 2012 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -49,11 +49,11 @@ else
 fi
 
 mke2fs -Fjq $filesystem_dev
-root_uuid=$($VOL_ID -u $filesystem_dev )
+root_uuid=$($VOL_ID $filesystem_dev )
 
 if [ -n "$swapdev" ]; then
   mkswap $swapdev
-  swap_uuid=$($VOL_ID -u $swapdev || true )
+  swap_uuid=$($VOL_ID $swapdev || true )
 fi
 
 TMPDIR=`mktemp -d` || exit 1
@@ -75,6 +75,7 @@ if [ -f "$CACHE_FILE" ]; then
 else
   if [ "$PROXY" ]; then
     export http_proxy="$PROXY"
+    export https_proxy="$PROXY"
   fi
   # INCLUDE will be empty if EXTRA_PKGS is null/empty, otherwise we
   # build the full parameter format from it
@@ -121,14 +122,45 @@ auto lo
 iface lo inet loopback
 EOF
 
-if [ -e $TMPDIR/etc/inittab ]; then
-  cat $TMPDIR/etc/inittab | sed -re 's/\stty1$/ console/' \
-    > $TMPDIR/etc/inittab.new
-  mv $TMPDIR/etc/inittab.new $TMPDIR/etc/inittab
-elif [ -e $TMPDIR/etc/event.d/tty1 ]; then
-  cat $TMPDIR/etc/event.d/tty1 | sed -re 's/tty1/console/' \
-    > $TMPDIR/etc/event.d/console
-  rm $TMPDIR/etc/event.d/tty1
+# for kvm, we should only activate a serial console if the
+# 'serial_console' parameter is set; for xen-pvm though, we should
+# always define a serial console
+SERIAL_PORT=""
+if [ "$INSTANCE_HV_serial_console" = "True" ]; then
+  SERIAL_PORT="ttyS0"
+elif [ "$HYPERVISOR" = "xen-pvm" ]; then
+  SERIAL_PORT="hvc0"
+fi
+
+if [ -n "$SERIAL_PORT" ]; then
+  if [ -e $TMPDIR/etc/inittab ]; then
+    # debian
+    echo "T0:23:respawn:/sbin/getty $SERIAL_PORT 38400" >> $TMPDIR/etc/inittab
+  elif [ -e $TMPDIR/etc/init ]; then
+    # ubuntu (eg. karmic)
+    cat > $TMPDIR/etc/init/${SERIAL_PORT}.conf <<EOF
+start on stopped rc RUNLEVEL=[2345]
+stop on runlevel [!2345]
+
+respawn
+exec /sbin/getty -8 38400 $SERIAL_PORT
+EOF
+  elif [ -e $TMPDIR/etc/event.d ]; then
+    # ubuntu (eg. intrepid)
+    cat > $TMPDIR/etc/event.d/${SERIAL_PORT}.conf <<EOF
+start on stopped rc2
+start on stopped rc3
+start on stopped rc4
+start on stopped rc5
+
+stop on runlevel 0
+stop on runlevel 1
+stop on runlevel 6
+
+respawn
+exec /sbin/getty 38400 ${SERIAL_PORT}
+EOF
+  fi
 fi
 
 RUN_PARTS=`which run-parts`