We have a single script that sets the root. We import that into any script that we run from cron.
The first thing that happens in the script is to set the variables. If you run it from the command line as hci, it just sets the root again. No harm done. This allows us to migrate scripts from our test site to our production site with no changes.