Index: scripts/vm-builder/vm-builder.spec =================================================================== --- scripts/vm-builder/vm-builder.spec (revision 0) +++ scripts/vm-builder/vm-builder.spec (revision 0) @@ -0,0 +1,118 @@ +# GOTCHA: Make sure to use the -h option on tar to dereference symlinks when +# creating the source archive. This prevents a broken symlink and allows us +# to not duplicate the LICENSE file twice in the svn repository + +%define tm_srcpath /bld/shared/source/vm-builder +%define tm_devtag vm-builder_1_3 +%define tm_modules syseng/vm-builder +%define tm_skiptag 0 + +%define TM_Component vm-builder +%define app_prefix /usr + +Name: %{TM_Component} +Summary: Scripts for provisioning new virtual machines. +Packager: Jeff Schroeder +Version: 1.3 +Release: 1 +Source: %{TM_Component}-%{version}-%{release}.tar.gz +License: GPL +Vendor: Ticketmaster, Inc +Group: Applications/System +BuildRoot: %{_tmppath}/%{name} +BuildArch: noarch + +%description +Easily provision new VMWare GSX virtual machines in a scriptable fashion. + +%prep +rm -rf %{buildroot} +%setup -q -n %{name}-%{version}-%{release} + +#%build + +%install +#!/bin/bash +# Since we use bash brace expansion, lets make sure we are using bash +[ "$RPM_BUILD_ROOT" != "/" ] && [ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT +%{__mkdir_p} $RPM_BUILD_ROOT/etc/%{TM_Component} +%{__mkdir_p} $RPM_BUILD_ROOT%{app_prefix}/bin +%{__mkdir_p} $RPM_BUILD_ROOT%{app_prefix}/{lib,libexec}/%{TM_Component} +%{__mkdir_p} $RPM_BUILD_ROOT/home/%{TM_Component}/{images/ks,template/linux,template/win2k3} +%{__mkdir_p} $RPM_BUILD_ROOT%{app_prefix}/share/%{TM_Component}/doc + +%{__chmod} 0755 $RPM_BUILD_ROOT%{app_prefix}/libexec +%{__chmod} 0755 -R $RPM_BUILD_ROOT/home/%{TM_Component} + +%{__install} -p -m 0755 vm-builder $RPM_BUILD_ROOT%{app_prefix}/bin/vm-builder +%{__install} -p -m 0755 vm-functions $RPM_BUILD_ROOT%{app_prefix}/lib/%{TM_Component}/vm-functions +%{__install} -p -m 0755 {new_vmware_config,setup-vm-builder.sh} $RPM_BUILD_ROOT%{app_prefix}/libexec/%{TM_Component} +%{__install} -p -m 0644 doc/{TODO,LICENSE,README} $RPM_BUILD_ROOT%{app_prefix}/share/%{TM_Component}/doc +%{__install} -p -m 0644 conf/vmware-gsx.conf $RPM_BUILD_ROOT/etc/%{TM_Component}/vmware-gsx.conf +%{__install} -p -m 0755 conf/template-linux.vmx $RPM_BUILD_ROOT/home/%{TM_Component}/template/linux/template.vmx +%{__install} -p -m 0755 conf/template-win2k3.vmx $RPM_BUILD_ROOT/home/%{TM_Component}/template/win2k3/template.vmx + +%clean +rm -rf %{buildroot} + +%post +cat << EOF + +Run "%{TM_Component} -s" as root to fetch the proper boot images for +CentOS 4.6, 5.1, and set them up as an example. You will need a working +kickstart ks.cfg on a webserver somewhere to put into the isolinux.cfg +and blank vmware disk images (*.vmdk). +EOF + +%files +%defattr(-,root,root) +%dir /home/%{TM_Component} +%dir /home/%{TM_Component}/images +%dir /home/%{TM_Component}/images/ks +%dir /home/%{TM_Component}/template +%dir /home/%{TM_Component}/template/linux +%dir /home/%{TM_Component}/template/win2k3 +%dir /etc/%{TM_Component} +%dir %{app_prefix}/libexec/%{TM_Component} +%dir %{app_prefix}/lib/%{TM_Component} +%dir %{app_prefix}/share/%{TM_Component} +%dir %{app_prefix}/share/%{TM_Component}/doc + +/home/%{TM_Component}/template/linux/template.vmx +/home/%{TM_Component}/template/win2k3/template.vmx + +%{app_prefix}/bin/vm-builder +%{app_prefix}/share/%{TM_Component}/doc/* +%{app_prefix}/lib/%{TM_Component}/vm-functions +%{app_prefix}/libexec/%{TM_Component}/* +%config(noreplace) /etc/%{TM_Component}/vmware-gsx.conf + +%changelog +* Wed Dec 20 2007 Jeff Schroeder vm-builder 1.3-1 +- vm-builder.spec: Use bash for bashisms and flesh out %files +- setup-vm-builder: More checks, use $EDITOR, and normalize iso naming +- vm-builder: Added -s option to download and setup boot images along with + better cleanup when a directory is created but the script fails +- vm-functions: Moved to /usr/lib/vm-functions, added -s, and nuke_it() +- Back to tabs instead of spaces *le sigh* + +* Wed Dec 19 2007 Jeff Schroeder vm-builder 1.2-1 +- Remove all Ticketmaster-isms and incorporate changes suggested by Phil +- vm-builder: Removed pointless vmlist checks and added /etc/vmware checks +- setup-vm-builder: Include vmware-gsx.conf and be generally more intelligent +- setup-vm-builder: Add in CentOS 4.6 along with 5.1 +- vmware-gsx.conf: Removed unused variables and add autodetection for paths + using /etc/vmware/config +- Add vmx templates for Linux and Windows 2003 doh! +- find . -type f | xargs sed -i -e 's/\t/ /g' tabs to spaces consistently + +* Tue Dec 18 2007 Jeff Schroeder vm-builder 1.1-1 +- Fix all of the pathing and rename /usr/bin/new_server to /usr/bin/vm-builder +- Set up everything and rewrite the docs for the open source release. +- Move everything from /$CLASS/shared/* Ticketmaster-ism to FHS compliant paths +- Add setup-vm-builder.sh script to set everything up for CentOS 5.1 vms + +* Mon Dec 17 2007 Jeff Schroeder vm-builder 1.0-1 +- vm-builder: Make the error checking more robust and fail politely + instead of spewing nasty errors and then continuing. +- Write a proper README file. Property changes on: scripts/vm-builder/vm-builder.spec ___________________________________________________________________ Name: svn:keywords + Date Author Revision Id HeadURL Index: scripts/vm-builder/new_vmware_config =================================================================== --- scripts/vm-builder/new_vmware_config (revision 0) +++ scripts/vm-builder/new_vmware_config (revision 0) @@ -0,0 +1,109 @@ +#!/bin/bash + +############################################################################## +# Usage: new_vmware_config -h [HOSTNAME] -d [DISTRO] -m [MEMORY] # +# # +# This is a rewrite of make_vm_config from perl to shell. Using perl # +# to do shell oriented kinds of things and really *basic* text manipulation # +# is overkill. This seems like the right tool for the job. -Jeff Schroeder # +# # +############################################################################## + +# -*- mode: sh; -*- +# vim:textwidth=78: + +# $Id$ + +# +# 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 3 of the License. +# +# 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, see . +# +# Written by: Jeff Schroeder +# (C) Copyright Ticketmaster, Inc. 2007 +# + + +CONF='/etc/vm-builder/vmware-gsx.conf' +FUNCTIONS='/usr/lib/vm-builder/vm-functions' + +# These are critical so bail out if they don't load +if [ -f "$CONF" -a -f "$FUNCTIONS" ]; then + . $CONF + . $FUNCTIONS +else + echo "ERROR: Could not load required include files!" >&2 + exit 1 +fi + +DESCRIPTION='Create a new VMWare machine configuration. +This works with Linux and Windows servers.' + +# Parsing and testing arvg all smart like +parse_argv $* + +ISO="${IMAGEDIR}/${DISTRO}.iso" +NEWCONFIG="${NEWSERVER}/${SERVER}.vmx" + +case $DISTRO in + *win2k3*) + TEMPLATE_DIR="$TEMPLATES/win2k3" + ;; + *) + TEMPLATE_DIR="$TEMPLATES/linux" + ;; +esac + +[ -d $TEMPLATE_DIR ] || error "Template dir: $TEMPLATE_DIR is invalid" +[ -d '/etc/vmware' ] || error "/etc/vmware does not exist" + +TEMPLATE="$TEMPLATE_DIR/template.vmx" + +# A few checks to prevent harmless VMControl errors on windows vms +if (grep -qs 'floppy0.present = "FALSE"' $TEMPLATE); then + export FLOPPY="false" +fi +if (grep -qs 'ide1:0.present = "FALSE"' $TEMPLATE); then + export IDE_CONNECT="false" +fi + +# Ah shell... how I love thee. Where else could nifty tricks be so simple? +[ -f "$ISO" ] || error "Boot image $ISO is not a file" + +[ -f "$TEMPLATE" ] || error "Missing template.vmx" + +if [ -d "$NEWSERVER" ]; then + error "Configuration file for $NEWSERVER already exists" +else + mkdir -p $NEWSERVER +fi + +cd "$TEMPLATE_DIR" || error "Cant change into $TEMPLATE_DIR" + +# If there aren't any vmware disk images, chances are the vm won't boot +[ "$(ls *.vmdk >/dev/null 2>&1; echo $?)" -eq 0 ] \ + || error "No VMWare *.vmdk disk files in $(pwd)" + + +# Copy disk images over to the new directory +for file in *.vmdk; do + cp $file "$NEWSERVER" +done + +# The previous version of this script was perl just to do this sed-foo +sed -e "s#%%NAME%%#$SERVER#g" \ + -e "s#%%MEM%%#$MEM#g" \ + -e "s#%%ISO_IMAGE%%#$ISO#g" \ + < $TEMPLATE > $NEWCONFIG || error "Creating $NEWCONFIG failed" + +# Chown / chmod everything over in one big go +/bin/chown -R vmware:vmware $NEWSERVER +/bin/chmod -R 755 $NEWSERVER Property changes on: scripts/vm-builder/new_vmware_config ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Date Author Revision Id HeadURL Index: scripts/vm-builder/conf/template-win2k3.vmx =================================================================== --- scripts/vm-builder/conf/template-win2k3.vmx (revision 0) +++ scripts/vm-builder/conf/template-win2k3.vmx (revision 0) @@ -0,0 +1,41 @@ +#!/usr/bin/vmware +#$Id$ +# + +config.version = "7" +virtualHW.version = "3" + +scsi0.present = "TRUE" +scsi0:0.present = "FALSE" +scsi0:0.fileName = "windows.vmdk" + +ide1:0.present = "FALSE" +ide1:0.fileName = "/dev/hdd" +ide1:0.deviceType = "atapi-cdrom" +ide0:0.present = "TRUE" +ide0:0.fileName = "windows-0.vmdk" +ide1:0.startConnected = "FALSE" +ide1:0.clientDevice = "TRUE" + +floppy0.present = "FALSE" +floppy0.startConnected = "FALSE" +floppy0.fileName = "/dev/fd0" + +Ethernet0.present = "TRUE" +usb.present = "FALSE" +mouse.hostType = "imps2" +mouse.fileName = "/dev/input/mice" + +displayName = "%%NAME%%" +machine.id = "%%NAME%%" +memsize = "%%MEM%%" +tools.syncTime = "TRUE" + +guestOS = "winNetStandard" +autostart = "poweron" +priority.grabbed = "normal" +priority.ungrabbed = "normal" +powerType.powerOff = "default" +powerType.powerOn = "default" +powerType.suspend = "default" +powerType.reset = "default" Property changes on: scripts/vm-builder/conf/template-win2k3.vmx ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Date Author Revision Id HeadURL Index: scripts/vm-builder/conf/template-linux.vmx =================================================================== --- scripts/vm-builder/conf/template-linux.vmx (revision 0) +++ scripts/vm-builder/conf/template-linux.vmx (revision 0) @@ -0,0 +1,48 @@ +#!/usr/bin/vmware +#$Id$ + +config.version = "8" +virtualHW.version = "4" + +memsize = "%%MEM%%" + +scsi0.present = "TRUE" +# lsilogic is required to boot RHEL/CentOS 4.x and newer +# it is backwards compatible with RHEL3 +scsi0.virtualDev = "lsilogic" +scsi0:0.present = "TRUE" +scsi0:0.fileName = "linux.vmdk" +scsi0:0.writeThrough = "TRUE" +scsi0:0.redo = "" + +ide1:0.present = "TRUE" +ide1:0.fileName = "%%ISO_IMAGE%%" +ide1:0.deviceType = "cdrom-image" +ide1:0.startConnected = "FALSE" + +floppy0.fileName = "/dev/fd0" +Ethernet0.present = "TRUE" +usb.present = "FALSE" + +displayName = "%%NAME%%" +machine.id = "%%NAME%%" + +guestOS = "redhat" +autostart = "poweron" + +priority.grabbed = "normal" +priority.ungrabbed = "normal" +powerType.powerOff = "soft" +powerType.powerOn = "hard" +powerType.suspend = "hard" +powerType.reset = "soft" + +floppy0.startConnected = "FALSE" +floppy0.fileType = "file" + +Ethernet0.addressType = "generated" +# Auto create bios info +uuid.action = "create" + +# Sync with the host OS every minute +tools.syncTime = "TRUE" Property changes on: scripts/vm-builder/conf/template-linux.vmx ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Date Author Revision Id HeadURL Index: scripts/vm-builder/conf/vmware-gsx.conf =================================================================== --- scripts/vm-builder/conf/vmware-gsx.conf (revision 0) +++ scripts/vm-builder/conf/vmware-gsx.conf (revision 0) @@ -0,0 +1,24 @@ +#!/bin/bash +# $Id$ +# Part of vm-builder see: http://groups.google.com/group/sysprovision + +BASEDIR=/home/vm-builder +BINDIR=/usr/libexec/vm-builder + +# Instead of hardcoding the paths, try to grok something useful +VMWARE_CMD="$(awk -F\" '/^control.fullpath/{print $2}' /etc/vmware/config)" +VMDIR="$(awk -F\" '/^vmdir/{print $2}' /etc/vmware/config)" + +# Set a default distro if none is specified +# Run /usr/libexec/vm-builder/setup-vm-builder.sh to get it +DISTRO_VERSION='centos5.1_i386' + +# Set the default ram to 128M +MEM=${MEM:=128} + +IMAGEDIR="${BASEDIR}/images/ks" + +# Make a pretty comma seperated list of available images +DISTROS=`cd $IMAGEDIR; ls -m *.iso 2>/dev/null | sed 's:\.iso$::g'` + +TEMPLATES=${BASEDIR}/template Property changes on: scripts/vm-builder/conf/vmware-gsx.conf ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Date Author Revision Id HeadURL Index: scripts/vm-builder/doc/LICENSE =================================================================== --- scripts/vm-builder/doc/LICENSE (revision 0) +++ scripts/vm-builder/doc/LICENSE (revision 0) @@ -0,0 +1 @@ +link ../../../LICENSE \ No newline at end of file Property changes on: scripts/vm-builder/doc/LICENSE ___________________________________________________________________ Name: svn:special + * Index: scripts/vm-builder/doc/TODO =================================================================== --- scripts/vm-builder/doc/TODO (revision 0) +++ scripts/vm-builder/doc/TODO (revision 0) @@ -0,0 +1,15 @@ +TODO as of Dec 18, 2007 + + - Dig my head back into nroff and write a proper man page. + + - Write a cheesy Makefile to install it for those on the bleeding edge + + - Move these scripts to use libvirt's command line tools. This allows us + transparent support of Xen, Qemu, and KVM. (http://www.libvirt.org). + Backwards compatibility will stay in for VMWare GSX. This is a longterm + goal that won't happen anytime in the near future.. + + - Better error checking of the disk images and gracefully recover from + failures when they were built incorrectly. + +-Jeff Schroeder Property changes on: scripts/vm-builder/doc/TODO ___________________________________________________________________ Name: svn:keywords + Date Author Revision Id HeadURL Index: scripts/vm-builder/doc/README =================================================================== --- scripts/vm-builder/doc/README (revision 0) +++ scripts/vm-builder/doc/README (revision 0) @@ -0,0 +1,54 @@ + +vm-builder - A tool to automate virtual machine creation and setup. + +(C) 2007 Ticketmaster, Inc. + +Introduction +------------ + +This was originally created as a tool to scratch an itch. Creating new +virtual machines using VMWare Server is a manual process. Instead of using +vmware-server-console, why not write a script that does the same thing? + + +Installation +------------ + +1. Install vm-builder using the included rpm or a stable snapshot. + +2. Run /usr/libexec/vm-builder/setup-vm-builder.sh. It will download +i386 and 64 bit CentOS images and set everything up for vm-builder to +work. The only thing it requires is a working ks.cfg on a server somewhere. + +3. Use vmware-server-console to create linux disk images. Name the image +linux.vmdk and copy them to /home/vm-builder/template/linux/. An example +would be linux-s001.vmdk, linux-s002.vmdk, linux-s003.vmdk, and linux.vmdk. + +3. Run vm-builder! The setup script gives you an example. Running it by +itsself will show you the images available for it to use. It will mount +the iso as a vmware drive, turn on the virtual machine, and start the +kickstart. After it is done, you should have a fresh install. Make sure +to have the 'rootpw' line in your ks.cfg so you can login as root. + + +Feedback +-------- + +vm-builder is part of the 'provision' project located at +http://sysprovision.googlecode.com/ . It can be discussed on the provision +google group (http://groups.google.com/group/sysprovision). + + +Getting The Source +------------------ + +Sources are available from googlecode in the Provision svn repository: +http://sysprovision.googlecode.com/svn/trunk/scripts/vm-builder + +$ svn checkout http://sysprovision.googlecode.com/svn/trunk/scripts/vm-builder vm-builder + + +License +------- + +vm-builder is released under GPLv3. Property changes on: scripts/vm-builder/doc/README ___________________________________________________________________ Name: svn:keywords + Date Author Revision Id HeadURL Index: scripts/vm-builder/vm-builder =================================================================== --- scripts/vm-builder/vm-builder (revision 0) +++ scripts/vm-builder/vm-builder (revision 0) @@ -0,0 +1,119 @@ +#!/bin/bash + +############################################################################## +# Usage: vm-builder -h [HOSTNAME] -d [DISTRO] -m [MEMORY] # +# # +# Creating virtual machines through the gui is slow and tedious. This script # +# automates creating Linux or windows virtual machines from templates. # +# # +# [DISTRO] and [MEMORY] are optional and defaults are set in vmware-gsx.conf # +# # +############################################################################## + +# -*- mode: sh; -*- +# vim:textwidth=78: + +# $Id$ + +# +# 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 3 of the License. +# +# 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, see . +# +# Written by: Jeff Schroeder +# (C) Copyright Ticketmaster, Inc. 2007 +# + +CONF='/etc/vm-builder/vmware-gsx.conf' +FUNCTIONS='/usr/lib/vm-builder/vm-functions' + +# These are critical so bail out if they don't load +if [ -f "$CONF" -a -f "$FUNCTIONS" ]; then + . $CONF + . $FUNCTIONS +else + echo "ERROR: Could not load required include files!" >&2 + exit 1 +fi + +DESCRIPTION="Provision a new VMWare virtual machine. +This works with Linux and Windows servers." + +# Parsing and testing arvg all smart like +parse_argv $* + +# -s will download and prep the images for usage +if [ $SETUP -eq 1 ]; then + /usr/libexec/vm-builder/setup-vm-builder.sh + exit 0 +fi + +# A few sanity checks to keep from doing something stupid +[ ! -z "$DISTROS" ] || error "No boot images available. Try vm-builder -s" + +[ -d "${VMDIR}/$SERVER/" ] \ + && error "${VMDIR}/$SERVER/ exists so not doing anything" + +[ -x $VMWARE_CMD ] || error "$VMWARE_CMD is not executable" + +[ -f "$($VMWARE_CMD -l 2>/dev/null| grep -q "$SERVER")" ] \ + && error "$SERVER is already a registered virtual machine. Skipping" + +[ -f "/etc/vmware/not_configured" ] \ + && error "VMWare is not configured. Run vmware-config.pl" + +[ -d '/etc/vmware' -a "$(id -u vmware >/dev/null 2>&1; echo $?)" -eq 0 ] || \ + error "Please setup VMWare GSX Server" + +# Not everyone has fping installed by default +if [ -x "`which fping 2>/dev/null`" ]; then + if (fping -q $SERVER); then + error "$SERVER is alive and pingable! Croaking" + fi +elif [ -x "`which ping 2>/dev/null`" ]; then + if (ping -W 2 -c2 -q $SERVER >/dev/null 2>&1); then + error "$SERVER is alive and pingable! Goodbye" + fi +fi + +echo "Creating $SERVER as $DISTRO with ${MEM}MB of ram" + +if (! ${BINDIR}/new_vmware_config -h $SERVER -d $DISTRO -m $MEM); then + error "Could not create config for $SERVER, no cookie for you" "noexit" + nuke_it "$NEWSERVER" +fi + + + +if (! su - vmware -c "${VMWARE_CMD} -s register ${VMDIR}/${SERVER}/${SERVER}.vmx >/dev/null"); then + error "Could not register $SERVER, sorry" "noexit" + nuke_it "$NEWSERVER" +fi + +if (! su - vmware -c "${VMWARE_CMD} ${VMDIR}/${SERVER}/${SERVER}.vmx start hard >/dev/null"); then + error "Could not start $SERVER" "noexit" + nuke_it "$NEWSERVER" +fi + +if [ "$IDE_CONNECT" != "false" ]; then + sleep 1 + su - vmware -c "${VMWARE_CMD} ${VMDIR}/${SERVER}/${SERVER}.vmx connectdevice ide1:0 >/dev/null" +fi + +if [ "$FLOPPY" != "false" ]; then + echo "Sleeping 2 minutes and then removing floppy disk device..." + sleep 120 + + # Crude way to remove the virtual floppy before the machine reboots + su - vmware -c "${VMWARE_CMD} ${VMDIR}/${SERVER}/${SERVER}.vmx disconnectdevice ide1:0 >/dev/null 2>/dev/null" +fi + +echo "$SERVER should be booting, use vmware-server-console to view it's status" Property changes on: scripts/vm-builder/vm-builder ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Date Author Revision Id HeadURL Index: scripts/vm-builder/vm-functions =================================================================== --- scripts/vm-builder/vm-functions (revision 0) +++ scripts/vm-builder/vm-functions (revision 0) @@ -0,0 +1,98 @@ +#!/bin/bash + +############################################################################# +# # +# vm-functions: Shared functions for vm-builder. Duplication is bad mm'kay? # +# # +############################################################################# + +# -*- mode: sh; -*- +# vim:textwidth=78: + +# $Id$ + +# +# 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 3 of the License. +# +# 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, see . +# +# Written by: Jeff Schroeder +# (C) Copyright Ticketmaster, Inc. 2007 +# + + +function usage() { + if [ -z "$DISTROS" ]; then + DISTROS='NONE! Try "vm-builder -s"' + fi + +cat << EOF >&2 +Usage: $0: -h [HOSTNAME] [OPTIONS] + -d [DISTRO] + -m [MEMORY] + -s Download and setup the boot images + +Available distros: $DISTROS + +$DESCRIPTION + +Defaults: $DISTRO_VERSION and ${MEM}MB of memory +[DISTRO] and [MEMORY] optional. +EOF + exit 1 +} + +function error() { + echo >&2 + echo -e "ERROR: $1" '\b!' >&2 + echo >&2 + + # Sometimes we want to cleanup before exiting + if [ "$2" != "noexit" ]; then + exit 1 + fi +} + +function nuke_it() { + [ "$1" ] || return 1 + + # Protect the user from stupidity if they mess up thier config file + if [ ! -z $1 -a $1 != '/' -a $1 != '/var' -a $1 != '/usr' -a $1 != '/home' ] + then + echo rm -rfv "$1" >&2 + exit 1 + fi +} + +function parse_argv() { + SETUP=0 + + while getopts ':h:d:m:s' opt; do + case $opt in + h ) SERVER="$OPTARG" ;; + d ) DISTRO="$OPTARG" ;; + m ) MEM="$OPTARG" ;; + s ) SETUP=1; return 0 ;; + * ) usage ;; + esac + done + + # Actually test if you have the arguments after trying to set them + [ -z "$SERVER" ] && usage + + # Make sure something like 512M or 512m wasn't passed + [ -z "$(echo $MEM | tr -d '[0-9]')" ] || usage + + # Set to the default from vm-vmware.conf if no distro specified via -d + [ -z "$DISTRO" ] && DISTRO="$DISTRO_VERSION" + + NEWSERVER="${VMDIR}/${SERVER}" +} Property changes on: scripts/vm-builder/vm-functions ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Date Author Revision Id HeadURL Index: scripts/vm-builder/setup-vm-builder.sh =================================================================== --- scripts/vm-builder/setup-vm-builder.sh (revision 0) +++ scripts/vm-builder/setup-vm-builder.sh (revision 0) @@ -0,0 +1,129 @@ +#!/bin/bash + +############################################################################## +# # +# setup-vm-builder.sh - Download CentOS boot images and set them up for use # +# by vm-builder. This is a basic example of what needs # +# to be done. Make *SURE* to properly set the ks= line # +# to a valid ks.cfg. # +# # +############################################################################## + +# -*- mode: sh; -*- +# vim:textwidth=78: + +# $Id$ + +# +# 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 3 of the License. +# +# 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, see . +# +# Written by: Jeff Schroeder +# (C) Copyright Ticketmaster, Inc. 2007 +# + +# Exits on any error +set -e + +if [ -f '/etc/vm-builder/vmware-gsx.conf' ]; then + . /etc/vm-builder/vmware-gsx.conf +else + echo "ERROR: Could not load required configuration file!" >&2 + exit 1 +fi + + +if [ "$(id -u 2>/dev/null)" != "0" ]; then + echo "ERROR: try sudo $0 or running it as root" >&2 + exit 255 +fi + +TEMPDIR="$(mktemp -d)" + +mkdir -p ${IMAGEDIR} ${TEMPLATES}/{linux,win2k3} + +mkdir -p ${TEMPDIR}/{ro,rw} +cd "$TEMPDIR" + +# Download CentOS 4.6 and 5.1 images to setup and use +for dist in 4.6 5.1; do + + # Download disk images for both 32 and 64 bit x86 installs + for arch in i386 x86_64; do + + filename="centos${dist}_${arch}.iso" + + # Lets not overwrite existing files + if [ -e "${IMAGEDIR}/${filename}" ]; then + echo "${IMAGEDIR}/${filename} already exists. Skipping" >&2 + continue + fi + + if [ ! -x "$(which mkisofs)" ]; then + echo "ERROR: install mkisofs or make sure it is in \$PATH" + exit 1 + fi + + echo -n "Downloading CentOS ${dist} for ${arch}... " + wget -q -o ${TEMPDIR}/wget.log -c http://mirrors.usc.edu/pub/linux/distributions/centos/${dist}/os/${arch}/images/boot.iso \ + -O ${TEMPDIR}/${filename} \ + || { echo "Could not download boot.iso"; exit 1; } + echo "done" + + mount -t iso9660 -o loop ${TEMPDIR}/${filename} ro/ + rsync -a ro/ rw/ + + cat << EOF > rw/isolinux/isolinux.cfg +default linux +prompt 1 +timeout 1 +label linux +kernel vmlinuz +##### EDIT THE ks= LINE TO A VALID ks.cfg. THIS IS CENTOS $dist FOR $arch +append initrd=initrd.img text ramdisk_size=8192 ks=http://your.kickstartserver/kickstart/centos${dist}-${arch}-ks.cfg ksdevice=eth0 keeppxe nofb +EOF + + chmod 644 rw/isolinux/isolinux.cfg + + # Some people are weird and prefer emacs or nano + if [ "$EDITOR" ]; then + $EDITOR rw/isolinux/isolinux.cfg + else + vi rw/isolinux/isolinux.cfg + fi + + # Seriously, I hate mkisofs. This was a pain to figure out + mkisofs -o ${BASEDIR}/images/ks/${filename} \ + -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \ + -boot-load-size 5 -boot-info-table -l -R -r rw/ >/dev/null 2>&1 \ + || { echo "$filename" creation failed; exit 1; } + + echo "Wrote: ${IMAGEDIR}/${filename}" + + umount ro + rm -rf ro/* rw/* + done +done + +rm -rf "$TEMPDIR" + +cat << EOF + +vm-builder is now setup! Just run vm_builder with no arguments to +see a list of of available installation images to choose from. If you +didn't put a valid ks= line in the configuration when they were opened, +you can remove them from /etc/vm-builder/images/ks/*.iso and run this +again. + +Example Usage: +# vm-builder -d centos5.1_i386 -h web001.yourdomain.com -m 256 +EOF Property changes on: scripts/vm-builder/setup-vm-builder.sh ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Date Author Revision Id HeadURL