+# Path's to the vserver references images and stubs
+vrefdir=$PWD/vservers/.vref
+vstubdir=$PWD/vservers/.vstub
+
+# XXX: The vserver reference name should be passed in as an argument
+# rather than being hardcoded.
+vrefname=default
+
+# Make /vservers and default vserver reference image
+vref=${vrefdir}/${vrefname}
+install -d -m 755 ${vref}
+
+# "Parse" out the packages and groups for mkfedora
+vrefpackages=$(grep "^package:.*" vserver-reference.lst | awk '{print $2}')
+vrefgroups=$(grep "^group:.*" vserver-reference.lst | awk '{print $2}')
+options=""
+for package in ${vrefpackages} ; do options="$options -p $package"; done
+for group in ${vrefgroups} ; do options="$options -g $group"; done
+
+# Populate a minimal /dev in the reference image
+pl_makedevs ${vref}
+
+# Populate image with vserver-reference packages
+pl_setup_chroot ${vref} ${options}
+
+for systemvserver in reference-vservers/*.lst ; do
+ NAME=$(basename $systemvserver .lst)
+
+ # "Parse" out the packages and groups for yum
+ systempackages=$(grep "^package:.*" $systemvserver | awk '{print $2}')
+ systemgroups=$(grep "^group:.*" $systemvserver | awk '{print $2}')
+
+ vdir=${vstubdir}/${NAME}
+ install -d -m 755 ${vdir}
+
+ # Clone the base vserver reference to the system vserver reference
+ # OPTIMIZATION: Consider using "cp -al" in the future
+ rsync -a ${vref}/ ${vdir}/
+ rm -f ${vdir}/var/lib/rpm/__db*
+
+ # Communicate to the initialization script from which vref this stub was cloned
+ echo ${vrefname} > ${vdir}.cloned
+
+ # Construct the excludes & includes patterns for rsync
+ (cd ${vdir} && find *) > ${vdir}.excludes
+ echo "var/lib/rpm/*" > ${vdir}.includes
+
+ # Install the system vserver specific packages
+ [ -n "$systempackages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y install $systempackages
+ [ -n "$systemgroups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $systemgroups