Bootstrap with 'python' and check CIPD auth.

Bootstrap scripts now use '#!/usr/bin/env python' instead of
'#!/usr/bin/env python3' which should let them work on a wider variety
of systems. Tested again with python 2 and made a couple minor changes
for compatibility.

Added check_auth() function to update.py. If it fails, it prints a
useful error message and gets ABORT_PW_ENVSETUP=1 added to the
environment. This is a cue to env_setup/setup.sh to not continue so the
error is prominent on the terminal. (env_setup/setup.sh clears this
variable so it won't persist into the next time env_setup/setup.sh is
sourced.)

Change-Id: Ib4a694178f1dce8971302914651feea3c727ea15
diff --git a/env_setup/setup.sh b/env_setup/setup.sh
index cfd1b6b..99940a6 100644
--- a/env_setup/setup.sh
+++ b/env_setup/setup.sh
@@ -14,19 +14,23 @@
 
 # This script must be tested on bash, zsh, and dash.
 
+function _realpath () {
+  python -c "import os.path; print(os.path.realpath('$@'))"
+}
+
 # Shell: bash.
 if test -n "$BASH"; then
-  PW_SETUP_SCRIPT_PATH=$(realpath $BASH_SOURCE)
+  PW_SETUP_SCRIPT_PATH=$(_realpath $BASH_SOURCE)
 # Shell: zsh.
 elif test -n "$ZSH_NAME"; then
-  PW_SETUP_SCRIPT_PATH=$(realpath ${(%):-%N})
+  PW_SETUP_SCRIPT_PATH=$(_realpath ${(%):-%N})
 # Shell: dash.
 elif test ${0##*/} = dash; then
-  PW_SETUP_SCRIPT_PATH=$(realpath \
+  PW_SETUP_SCRIPT_PATH=$(_realpath \
     $(lsof -p $$ -Fn0 | tail -1 | sed 's#^[^/]*##;'))
 # If everything else fails, try $0. It could work.
 else
-  PW_SETUP_SCRIPT_PATH=$(realpath $0)
+  PW_SETUP_SCRIPT_PATH=$(_realpath $0)
 fi
 
 PW_ENVSETUP=$(dirname $PW_SETUP_SCRIPT_PATH)
@@ -35,5 +39,10 @@
 PW_ROOT=$(dirname "$PW_ENVSETUP")
 export PW_ROOT
 
+unset ABORT_PW_ENVSETUP
+
 . "$PW_ENVSETUP/cipd/init.sh"
-. "$PW_ENVSETUP/virtualenv/init.sh"
+
+if [[ -z "$ABORT_PW_ENVSETUP" ]]; then
+  . "$PW_ENVSETUP/virtualenv/init.sh"
+fi