function init_disk {
  test "$(sfdisk -s /dev/hda)" -gt 20000000 || exec bash
  hdparm -c 1 -d 1 /dev/hda
  
  wget -O /hda.sfdisk ${srvaddr}/hda.sfdisk && \
    sfdisk /dev/hda < /hda.sfdisk           || \
    (
      echo "You may run fdisk (/part_hda) manually and then exit the shell to proceed"
      bash
    )
    mkfs.ext2   /dev/hda1
    mkswap      /dev/hda2
    mkfs.xfs -f /dev/hda3
}

   
function mount_newroot {
  mount -t xfs -o noatime /dev/hda3 /mnt/new 
}


function restore_system {
  init_disk || exec bash
  mount_newroot || exec bash
  curl ${srvaddr}/common/default.xfsdump | xfsrestore -J - /mnt/new
}


function post_restore {
  wget -O - ${srvaddr}/common/root.tar | tar -xf - -C /mnt/new
  wget -O - ${srvaddr}/root.tar | tar -xf - -C /mnt/new
}
