Use a chroot() function

Fixes a warning:
-bash: local: can only be used in a function

A local variable can only be used inside a function.
The function is also unset after use.