From 6c4bbf60d18f8e333fd7b11e7d449b52e6911b14 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Fri, 4 Jul 2008 19:45:54 +0000 Subject: [PATCH] Start autogenerating the create script This patch changes the create script to be autogenerated so that we can use the configure-time variables. Reviewed-by: imsnah --- .gitignore | 6 +++ Makefile.am | 13 ++++++- create | 124 ----------------------------------------------------------- create.in | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 125 deletions(-) delete mode 100755 create create mode 100755 create.in diff --git a/.gitignore b/.gitignore index b718fc7..ee576da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # gitignore rules +# autotools results /Makefile /Makefile.in /aclocal.m4 @@ -7,4 +8,9 @@ /config.log /config.status /configure + +# built scripts +/create + +# archives /ganeti-instance-debootstrap-*.tar.gz diff --git a/Makefile.am b/Makefile.am index 50f164e..991df92 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,18 @@ osname=$(subst ganeti-instance-,,$(PACKAGE)) osdir=$(datadir)/ganeti/os/$(osname) -dist_os_SCRIPTS = create import export rename +os_SCRIPTS = create +dist_os_SCRIPTS = import export rename dist_os_DATA = ganeti_api_version dist_doc_DATA = COPYING NEWS README + +EXTRA_DIST = create.in + +do_subst = sed -e 's,[@]sysconfdir[@],$(sysconfdir),g' + +create: create.in Makefile + $(do_subst) < $< > $@ + chmod +x $@ + +CLEANFILES = create diff --git a/create b/create deleted file mode 100755 index 562fa7d..0000000 --- a/create +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2007 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 -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. - -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" - -TEMP=`getopt -o i:b:s: -n '$0' -- "$@"` - -if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi - -# Note the quotes around `$TEMP': they are essential! -eval set -- "$TEMP" - -while true; do - case "$1" in - -i) instance=$2; shift 2;; - - -b) blockdev=$2; shift 2;; - - -s) swapdev=$2; shift 2;; - - --) shift; break;; - - *) echo "Internal error!"; exit 1;; - esac -done -if [ -z "$instance" -o -z "$blockdev" -o -z "$swapdev" ]; then - echo "Missing -i or -b or -s argument!" - exit 1 -fi - -mkswap $swapdev -mke2fs -Fjq $blockdev -TMPDIR=`mktemp -d` || exit 1 -trap "umount $TMPDIR; rmdir $TMPDIR" EXIT - -# If it's not a block device try to mount it via loopback device. -# This is needed for file disks. -MOUNT_OPTIONS="" -if [ ! -b $blockdev ]; then - MOUNT_OPTIONS="$MOUNT_OPTIONS -o loop" -fi -mount $MOUNT_OPTIONS $blockdev $TMPDIR - -# remove the cache file if it's old (> 2 weeks) and writable by the owner (the -# default due to the standard umask) -if [ -f "$CACHE_FILE" ]; then - find "$CACHE_FILE" -perm -0200 -daystart -mtime +14 -print0 | \ - xargs -r0 rm -f -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 - - # remove the downloaded debs, as they are no longer needed - find "$TMPDIR/var/cache/apt/archives" -type f -name '*.deb' -print0 | \ - xargs -r0 rm -f - - # 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 - TMP_CACHE=`mktemp "${CACHE_FILE}.XXXXXX"` - tar cf "$TMP_CACHE" -C $TMPDIR . - mv -f "$TMP_CACHE" "$CACHE_FILE" - fi -fi - -cp -p /etc/hosts $TMPDIR/etc/hosts -cp -p /etc/resolv.conf $TMPDIR/etc/resolv.conf -echo $instance > $TMPDIR/etc/hostname -echo $instance > $TMPDIR/etc/mailname - -cat > $TMPDIR/etc/fstab < -/dev/sda / ext3 defaults 0 1 -/dev/sdb swap swap defaults 0 0 -proc /proc proc defaults 0 0 -EOF - -cat > $TMPDIR/etc/network/interfaces <&2 ; exit 1 ; fi + +# Note the quotes around `$TEMP': they are essential! +eval set -- "$TEMP" + +while true; do + case "$1" in + -i) instance=$2; shift 2;; + + -b) blockdev=$2; shift 2;; + + -s) swapdev=$2; shift 2;; + + --) shift; break;; + + *) echo "Internal error!"; exit 1;; + esac +done +if [ -z "$instance" -o -z "$blockdev" -o -z "$swapdev" ]; then + echo "Missing -i or -b or -s argument!" + exit 1 +fi + +mkswap $swapdev +mke2fs -Fjq $blockdev +TMPDIR=`mktemp -d` || exit 1 +trap "umount $TMPDIR; rmdir $TMPDIR" EXIT + +# If it's not a block device try to mount it via loopback device. +# This is needed for file disks. +MOUNT_OPTIONS="" +if [ ! -b $blockdev ]; then + MOUNT_OPTIONS="$MOUNT_OPTIONS -o loop" +fi +mount $MOUNT_OPTIONS $blockdev $TMPDIR + +# remove the cache file if it's old (> 2 weeks) and writable by the owner (the +# default due to the standard umask) +if [ -f "$CACHE_FILE" ]; then + find "$CACHE_FILE" -perm -0200 -daystart -mtime +14 -print0 | \ + xargs -r0 rm -f +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 + + # remove the downloaded debs, as they are no longer needed + find "$TMPDIR/var/cache/apt/archives" -type f -name '*.deb' -print0 | \ + xargs -r0 rm -f + + # 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 + TMP_CACHE=`mktemp "${CACHE_FILE}.XXXXXX"` + tar cf "$TMP_CACHE" -C $TMPDIR . + mv -f "$TMP_CACHE" "$CACHE_FILE" + fi +fi + +cp -p /etc/hosts $TMPDIR/etc/hosts +cp -p /etc/resolv.conf $TMPDIR/etc/resolv.conf +echo $instance > $TMPDIR/etc/hostname +echo $instance > $TMPDIR/etc/mailname + +cat > $TMPDIR/etc/fstab < +/dev/sda / ext3 defaults 0 1 +/dev/sdb swap swap defaults 0 0 +proc /proc proc defaults 0 0 +EOF + +cat > $TMPDIR/etc/network/interfaces <