#!/bin/bash
. /etc/vz/vz.conf
if [ -z "$2" ];
then
echo "Usage: $0 <release> <ip> (mirror)"
exit 1
fi
_RELEASE=$1
_IP=$2
_MIRROR=${3:-http://debian.mirrors.ovh.net/debian/}
_VEID=$RANDOM
case "$(uname -m)" in
i?86) _ARCH=i386 ;;
x86_64) _ARCH="amd64" ;;
esac
# just in case $_VEID is empty
test -z "$_VEID" && exit 1
vzctl create $_VEID
vzctl mount $_VEID
rm -rf $VE_ROOT/$_VEID/*
debootstrap --arch $_ARCH $_RELEASE $VE_ROOT/$_VEID $_MIRROR
vzctl set $_VEID --nameserver inherit --ipadd $_IP --save
sed -i -e 's@\([[:space:]]\)\(/var/log/\)@\1-\2@' $VE_ROOT/$_VEID/etc/*syslog.conf
vzctl start $_VEID
sleep 5
vzctl exec2 $_VEID "systemctl mask systemd-udevd.service"
vzctl exec2 $_VEID "systemctl mask console-getty.service"
vzctl exec2 $_VEID "systemctl mask getty-static.service"
vzctl exec2 $_VEID "systemctl disable getty@tty2.service"
vzctl exec2 $_VEID "apt-get -y --force-yes install zsh vim"
vzctl exec2 $_VEID "dpkg --purge isc-dhcp-client isc-dhcp-common"
vzctl exec2 $_VEID "apt-get clean"
vzctl stop $_VEID
vzctl mount $_VEID
find $VE_ROOT/$_VEID/var/log -type f -delete
(cd $VE_ROOT/$_VEID; tar --numeric-owner -vzcf $TEMPLATE/cache/debian-$(cat $VE_ROOT/$_VEID/etc/debian_version)-$_ARCH-minimal.tar.gz .)
vzctl umount $_VEID
vzctl destroy $_VEID