download to GERRIT_CACHE_HOME when set

When building a plugin as user `nobody`, download_file is unable to
write the artifacts to the cache since the user does not have a home
directory.  For a CI build I also need to be set the cache directory to
a predetermined value.

Introduce the optional `GERRIT_CACHE_HOME` environment variable to
support relocating downloaded artifacts.  When the environment variable
is not set, behavior is unchanged.

Update documentation to mention support for `GERRIT_CACHE_HOME`. While at
it, explain how to override the bazel repository and disk cache, would
have same a bit of time the first time I had to tweak them.

This was done in Gerrit with Ie4fac83928527e0e71b159b9500983234c2261ac

Change-Id: I0c4b3992d36cf40196f64251900f07e527d8a3c4
diff --git a/tools/download_file.py b/tools/download_file.py
index 092a81f..1900b20 100755
--- a/tools/download_file.py
+++ b/tools/download_file.py
@@ -17,7 +17,7 @@
 
 from hashlib import sha1
 from optparse import OptionParser
-from os import link, makedirs, path, remove
+from os import environ, link, makedirs, path, remove
 import shutil
 from subprocess import check_call, CalledProcessError
 from sys import stderr
@@ -25,7 +25,10 @@
 from zipfile import ZipFile, BadZipfile, LargeZipFile
 
 GERRIT_HOME = path.expanduser('~/.gerritcodereview')
-CACHE_DIR = path.join(GERRIT_HOME, 'bazel-cache', 'downloaded-artifacts')
+CACHE_DIR = environ.get(
+    'GERRIT_CACHE_HOME',
+    path.join(GERRIT_HOME, 'bazel-cache', 'downloaded-artifacts'))
+
 LOCAL_PROPERTIES = 'local.properties'