zulip/tools/provision
Greg Price e469578a55 py3: Fix up (almost) all script invocations to rely on shebangs.
This follows up on 207cf6302 from last year to clean up cases that
have apparently popped up since then.  Invoking the scripts directly
makes a cleaner command line in any case, and moreover is essential
to how we control running a Zulip install as either Python 2 or 3
(soon, how we always ensure it runs as Python 3.)

One exception: we're currently forcing `provision` in dev to run
Python 3, while still running both Python 2 and Python 3 jobs in CI.
We use a non-shebang invocation to do the forcing of Python 3.
2017-08-15 17:30:31 -07:00

58 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# Use this script to provision dependencies for your Zulip installation.
# This script is idempotent, so it can be restarted at any time, and it
# will usually run fairly quickly when your dependencies are up to date.
set -e
if [ "$EUID" -eq 0 ]; then
echo "Error: The provision script must not be run as root" >&2
exit 1
fi
#Make the script independent of the location from where it is
#executed
PARENT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
cd "$PARENT_PATH"
mkdir -p ../var/log
LOG_PATH="../var/log/provision.log"
echo "PROVISIONING STARTING." >> $LOG_PATH
PROVISION_PATH="./lib/provision.py"
if [ -n "$TRAVIS" ]; then
# In CI, we let PATH provide the Python version.
PROVISION_CMD=("$PROVISION_PATH")
else
# In dev, we force Python 3.
PROVISION_CMD=(python3 "$PROVISION_PATH")
fi
# PYTHONUNBUFFERED is important to ensure that tracebacks don't get
# lost far above where they should be in the output.
export PYTHONUNBUFFERED=1
"${PROVISION_CMD[@]}" "$@" 2>&1 | tee -a "$LOG_PATH"
failed=${PIPESTATUS[0]}
if [ $failed = 1 ]; then
echo -e "\033[0;31m"
echo "Provisioning failed!"
echo
echo "* Look at the traceback(s) above to find more about the errors."
echo "* Resolve the errors or get help on chat."
echo "* If you can fix this yourself, you can re-run tools/provision at any time."
echo "* Logs are here: zulip/var/log/provision.log"
echo -e "\033[0m"
exit 1
elif [ "$VIRTUAL_ENV" != "/srv/zulip-py3-venv" ] && [ -z "$TRAVIS" ]; then
echo -e "\033[0;31m"
echo "WARNING: This shell does not have the Python 3 virtualenv activated."
echo "Zulip commands will fail."
echo
echo "To update the shell, run:"
echo " source /srv/zulip-py3-venv/bin/activate"
echo "or just close this shell and start a new one."
echo -en "\033[0m"
fi
exit 0