Fix scoping issue ($target not available)

This is a follow on from 10a084ebc70417f48801c99610d1f9a60a16c793

because $target is out of scope this then checks to see if the host system is registered, not the chroot.  So use $dir instead