#!/bin/sh
#
# Bash Script used to move a physical host to a virtual on
# This script must be run as root from host node that the container
# will be on.
#
# Version 2.0 
# 6/10/2008 Andrew Niemantsverdriet
#

echo -n "Enter the host to move: "
read host

echo -n "Enter the OpenVZ container ID: "
read ctid
echo

echo "Rsyncing $host to CTID: $ctid"

rsync -arvpz --numeric-ids --exclude-from '/root/.excludes' $host:/ /var/lib/vz/private/$ctid/

#Clean Ups
echo "Cleaning Up..."
sed -i -e '/getty/d' /var/lib/vz/private/$ctid/etc/inittab

rm -f /var/lib/vz/private/$ctid/etc/mtab
ln -s /proc/mounts /var/lib/vz/private/$ctid/etc/mtab

cp /var/lib/vz/private/$ctid/etc/fstab /var/lib/vz/private/$ctid/etc/fstab.old
grep devpts /var/lib/vz/private/$ctid/etc/fstab.old > /var/lib/vz/private/$ctid/etc/fstab

echo -n "Do you want to start CTID: $ctid now? (y/n): "
read ok

if [ "$ok" = "n" ]; then
  echo
  echo "Process Complete"
  exit 1
else
  vzctl start $ctid
  echo "You can now enter container and disable un-needed services"
fi
