#!/bin/bash # Script to create an OpenVZ template for a specific Debian / Ubuntu # version DEFAULT_CONFFILE=/etc/egscripts/make-openvz-template.conf DEFAULT_CONFIGBASE=/etc/egscripts/openvz DEFAULT_CONFIGTEMPLATE=vps.basic DEFAULT_VZCONFDIR=/etc/vz DEFAULT_MIRROR=http://aptcache.egressive.com:3142/ubuntu DEFAULT_NAMESERVER=10.128.2.11 DEFAULT_VEID=666 DEFAULT_IP=10.128.2.99 # # Any of the variables below can be overriden either as environment variables # or in the configuration file. Either specified on the command line or from # the default above # CONFFILE=${CONFFILE-$DEFAULT_CONFFILE} MIRROR=${MIRROR-$DEFAULT_MIRROR} NAMESERVER=${NAMESERVER-$DEFAULT_NAMESERVER} VEID=${VEID-$DEFAULT_VEID} IP=${IP-$DEFAULT_IP} CONFIGBASE=${CONFIGBASE-$DEFAULT_CONFIGBASE} CONFIGTEMPLATE=${CONFIGTEMPLATE-$DEFAULT_CONFIGTEMPLATE} VZCONFDIR=${VZCONFDIR-$DEFAULT_VZCONFDIR} usage() { cat <> $VZCONFDIR/conf/$VEID.conf vzctl set $VEID --nameserver $NAMESERVER --save vzctl set $VEID --ipadd $IP --save # You will probably want to create a SUITE.sources.list file in th # config directory, otherwise the only apt source will be the $MIRROR if [ -f $CONFIGBASE/$SUITE.sources.list ] ; then cp $CONFIGBASE/$SUITE.sources.list $TARGET/etc/apt/sources.list fi vzctl start $VEID sleep 10 vzctl exec $VEID "rm /etc/event.d/tty*" vzctl exec $VEID "chmod 700 /root" vzctl exec $VEID "echo $SUITE-vztemplate > /etc/hostname" vzctl exec $VEID "aptitude update" vzctl exec $VEID "aptitude purge -y ${PURGE_PACKAGES}" vzctl exec $VEID "aptitude install -y ${INSTALL_PACKAGES}" vzctl exec $VEID "ln -s /bin/true /sbin/modprobe" vzctl exec $VEID "aptitude -y safe-upgrade" # Init will hang on klogd if not disabled vzctl exec $VEID "update-rc.d -f klogd remove" # /etc/mtab must be a link to /proc/mounts vzctl exec $VEID "rm -f /etc/mtab" vzctl exec $VEID "ln -s /proc/mounts /etc/mtab" vzctl exec $VEID "update-rc.d -f mtab.sh remove" # Puppet is always required vzctl exec $VEID "aptitude install -y puppet" # Clean apt cache vzctl exec $VEID "aptitude -y clean" if [ -f $CONFIGBASE/$SUITE.puppet.conf ] ; then cp $CONFIGBASE/$SUITE.puppet.conf $TARGET/etc/puppet/puppet.conf fi vzctl stop $VEID vzctl set $VEID --ipdel all --save if [ -f $TARGET/etc/lsb-release ] ; then . $TARGET/etc/lsb-release TARNAME=${DISTRIB_ID}-${DISTRIB_CODENAME}-${DISTRIB_RELEASE} else TARNAME=${SUITE} fi pushd $VE_PRIVATE echo -n "Creating $TEMPLATE/cache/$OSTEMPLATE.tar.gz ... " tar -zcf $TEMPLATE/cache/$OSTEMPLATE.tar.gz . echo "done" popd vzctl destroy $VEID