#! /bin/sh # (C) copyleft The Anarcat 2006-2007 # GPL of course # those packages are not going to be installed REMOVE_PACKAGES="sparc-utils,dhcp-client,lilo,makedev,pcmcia-cs,ppp,pppconfig,pppoe,pppoeconf,setserial,syslinux,fdutils,libpcap0,iptables,pciutils,exim4" INCLUDE_PACKAGES="nullmailer,less,subversion" # command line parsing... NAME=$1 HOSTNAME=${NAME} SIZE=$2 NET=$3 DIST=${4:-etch} MIRROR=${5-http://debian.mirror.iweb.ca/debian/} DBOPTS="${6} --exclude=$REMOVE_PACKAGES" # some defaults SOURCES=/etc/vservers/${DIST}-sources.list VSERVER_ROOT=/vservers if [ $# -lt 3 ] then cat < [ [ []]] name: the vserver name size: the size of the LV to create net: the ip (e.g. eth0:192.168.0.100/24) distro: the distro to bootstrap with (e.g. defaults to ${DIST}), use "skeleton" for a barebones vserver mirror: the mirror to use (defaults to ${MIRROR}, not used for "skeleton") dbopts: other options to debootstrap (not used for "skeleton") EOF exit fi # figure out the name of the LVM device DEVICE=/dev/mapper/vserver--data-`echo $NAME | sed 's/-/--/g'` echo "** Creating ${SIZE} vserver ${NAME} on ${NET} with distro ${DIST} on mirror ${MIRROR} (debopts: ${DBOPTS})" echo creating partition lvcreate -L${SIZE} -n${NAME} vserver-data > /dev/null echo formatting $DEVICE mkfs -t ext3 -j $DEVICE > /dev/null echo adding to fstab echo "${DEVICE} ${VSERVER_ROOT}/${NAME} ext3 defaults 0 2" >> /etc/fstab echo mounting mkdir -p ${VSERVER_ROOT}/${NAME} mount ${VSERVER_ROOT}/${NAME} # that's the real magic incantation... echo "bootstraping vserver" if [ "${DIST}" = "skeleton" ] ; then vserver ${NAME} build -n ${NAME} --hostname ${HOSTNAME} --interface ${NET} -m skeleton else vserver ${NAME} build -n ${NAME} --hostname ${HOSTNAME} --interface ${NET} -m debootstrap -- -d ${DIST} -m ${MIRROR} -- ${DBOPTS} fi | while read do echo -n . done echo " done." # make sure the server starts on boot echo default > /etc/vservers/${NAME}/apps/init/mark echo ${NAME} > /etc/vservers/${NAME}/interfaces/0/name if [ "${DIST}" = "skeleton" ] ; then exit fi echo "starting vserver ${NAME}" vserver ${NAME} start > /dev/null echo "locking the root account" vserver ${NAME} exec passwd -l root # extra candy :) if [ -r $SOURCES ] then echo "security upgrade" cp $SOURCES ${VSERVER_ROOT}/${NAME}/etc/apt/sources.list vserver ${NAME} exec aptitude update vserver ${NAME} exec aptitude upgrade fi