Rework the create script
authorIustin Pop <iustin@google.com>
Fri, 4 Jul 2008 20:08:10 +0000 (20:08 +0000)
committerIustin Pop <iustin@google.com>
Fri, 4 Jul 2008 20:08:10 +0000 (20:08 +0000)
This patch changes much of the internals of the create script:
  - we no longer harcode the variables suite, extrapkgs, mirror, etc.
    but instead read them from a config file
  - since we can install multiple suited, the cache filename is
    arch and suite dependant
  - ship a defaults file (but do not install it, that is easier done in
    the packaging)

The defaults file does not have any extra settings activated, so the
default values from the create script will be used. The patch also
changes the script to install in this default mode debian lenny and not
etch.

Reviewed-by: imsnah

create.in
defaults [new file with mode: 0644]

index 1dc5e4b..ef32831 100755 (executable)
--- a/create.in
+++ b/create.in
 
 set -e
 
-# Customize this if you need another mirror, or set to empty to get the
-# node's sources.list
-MIRROR="http://ftp.debian.org/debian"
-DPKG_ARCH="`dpkg --print-architecture`"
-CACHE_FILE="cache-${DPKG_ARCH}.tar"
+DEFAULT_FILE="@sysconfdir@/default/ganeti-instance-debootstrap"
+if [ -f "$DEFAULT_FILE" ]; then
+    . "$DEFAULT_FILE"
+fi
+
+# note: we don't set a default mirror since debian and ubuntu have
+# different defaults, and it's better to use the default
+
+# only if the user want to specify a mirror in the defaults file we
+# will use it, this declaration is to make sure the variable is set
+: ${MIRROR:=""}
+: ${SUITE:="lenny"}
+: ${ARCH:=""}
+: ${EXTRA_PKGS:=""}
+
+DPKG_ARCH=${ARCH:-`dpkg --print-architecture`}
+CACHE_FILE="cache-${SUITE}-${DPKG_ARCH}.tar"
 
 TEMP=`getopt -o i:b:s: -n '$0' -- "$@"`
 
@@ -73,14 +85,13 @@ fi
 if [ -f "$CACHE_FILE" ]; then
   tar xf "$CACHE_FILE" -C $TMPDIR
 else
-  # On i386, we need the xen-specific library
-  if [ "$DPKG_ARCH" = "i386" ]; then
-    EXTRAPKG="linux-image-xen-686 libc6-xen"
-  elif [ "$DPKG_ARCH" = "amd64" ]; then
-    EXTRAPKG="linux-image-xen-amd64"
-  fi
-
-  debootstrap --include="$EXTRAPKG" etch $TMPDIR $MIRROR
+  # INCLUDE will be empty if EXTRA_PKGS is null/empty, otherwise we
+  # build the full parameter format from it
+  INCLUDE=${EXTRA_PKGS:+"--include=$EXTRA_PKGS"}
+  debootstrap \
+    --arch "$DPKG_ARCH" \
+    $INCLUDE \
+    "$SUITE" $TMPDIR $MIRROR
 
   # remove the downloaded debs, as they are no longer needed
   find "$TMPDIR/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
@@ -88,7 +99,6 @@ else
 
   # remove the persistent-net rules, otherwise it will remember the node's
   # interfaces as eth0, eth1, ...
-
   rm -f "$TMPDIR/etc/udev/rules.d/z25_persistent-net.rules"
 
   if [ ! -e no_cache ]; then
diff --git a/defaults b/defaults
new file mode 100644 (file)
index 0000000..b320c08
--- /dev/null
+++ b/defaults
@@ -0,0 +1,30 @@
+# ganeti-instance-debootstrap defaults file
+
+# if you want to change from the default of installing debian stable
+# on the next instance, customize this file before the instance
+# installation
+
+# MIRROR: do not customize MIRROR if you want to be able to install
+# both debian and ubuntu, since they have different defaults; or
+# customize it before each install
+# MIRROR="http://ftp.debian.org/debian"
+
+# ARCH: define ARCH only if you want a different architecture than the
+# current one; the known use case is to install a 32-bit instance on a
+# 64-bit node; choose either "i386" or "amd64":
+# ARCH="i386"
+
+# SUITE: change suite to any of the ones supported by deboostrap; this
+# could be unstable, etch, etc.:
+# SUITE="lenny"
+
+# EXTRA_PKGS: depending on the suite and architecture you are using,
+# different extra packages are needed for Xen support; if you are not
+# using Xen, then Xen packages should not be installed and you should
+# use a different, if any, value for it
+
+# for etch/lenny i386:
+# EXTRA_PKGS="linux-image-xen-686,libc6-xen"
+
+# for etch amd64 (lenny doesn't have xen support in amd64):
+# EXTRA_PKGS="linux-image-xen-amd64"