#!/bin/sh # This script is used to generate a complete template for openvz. # This script only take one mandatory argument, the template name # A second argument can be specified, it'll be the architecture of the template # TODO: # - integrate an arch option # - integrate a distro option # - integrate an option to install packages and config files # - integrate mirror override, instead of using the host one. # - use getopt or similar to handle parameters # - handle architectures correctly (you can't have ia64 built on top of i386 for example) # - write usage() # - Other things that I forgot.. DISTRO=hardy TARGET=$DISTRO MIRROR=`cat /etc/apt/sources.list | grep main | head -n1 | cut -d' ' -f2` if [ ! -e /usr/share/debootstrap/scripts/$DISTRO ]; then ln -sf /usr/share/debootstrap/scripts/hardy /usr/share/debootstrap/scripts/$DISTRO fi cd /opt ARCH=i386 if [ -n "$2" ]; then ARCH=$2 fi /usr/sbin/debootstrap --arch=$ARCH $DISTRO $TARGET $MIRROR for i in $(echo "proc sys dev"); do mount -o bind /$i $TARGET/$i done echo "deb $MIRROR $DISTRO main restricted universe multiverse" > $TARGET/etc/apt/sources.list echo "deb $MIRROR $DISTRO-updates main restricted universe multiverse" >> $TARGET/etc/apt/sources.list echo "deb $MIRROR $DISTRO-security main restricted universe multiverse" >> $TARGET/etc/apt/sources.list echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"' > $TARGET/etc/environment echo 'LANG="en_US.UTF-8"' >> $TARGET/etc/environment echo 'LANGUAGE="en_US.UTF-8"' >> $TARGET/etc/environment echo "openvz" > $TARGET/etc/hostname ( cat << 'EOF' 127.0.0.1 localhost # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts EOF ) > $TARGET/etc/hosts ( cat << 'EOF' #!/bin/sh locale-gen en_US.UTF-8 && update-locale ln -sf /usr/share/zoneinfo/America/Montreal /etc/localtime export DEBIAN_FRONTEND=noninteractive export DEBIAN_PRIORITY=critical apt-get update && apt-get dist-upgrade --yes apt-get install ubuntu-standard mc vim language-pack-en --no-install-recommends --yes apt-get autoremove --purge --yes # Maybe we should make KXX symlinks instead of removing it in case of update the template is screwed.. update-rc.d -f udev remove update-rc.d -f klogd remove rm /etc/event.d/tty* apt-get clean /etc/init.d/atd stop /etc/init.d/cron stop rm $0 EOF ) > $TARGET/runme.sh chroot $TARGET/ bash /runme.sh for i in $(echo "proc sys dev"); do umount $TARGET/$i done cd $TARGET tar -zcf /var/lib/vz/template/cache/$1.tar.gz * rm -Rf $TARGET