#!/bin/sh # Bootstrap script for VESSL flare. set -e echo "Bootstrapping VESSL Flare..." echo URL_BASE="flare.vessl.ai" ######################## # HELPER FUNCTIONS START # Usage: _command_exists _command_exists() { type "$1" >/dev/null 2>&1 } # Usage: _download_to _download_to() { if _command_exists curl then curl -sSfL -o "$2" "$1" return fi if _command_exists wget then wget -nv -t 0 -O "$2" "$1" return fi echo "Error: no curl or wget found. Cannot download flare code; aborting." exit 1 } _find_python3() { for PY_CANDIDATE in \ "python3.11" \ "python3.10" \ "python3.9" \ "python3.8" \ "python3.7" \ "python3.6" \ "python3" do if _command_exists "${PY_CANDIDATE}" then PY_CMD="${PY_CANDIDATE}" unset PY_CANDIDATE return fi done unset PY_CANDIDATE if _command_exists python then if [ "$(python -c "import sys; print(sys.version_info[0])")" = "3" ] then PY_CMD="python" return fi fi echo "Error: no 'python3.X', 'python3', nor 'python' (that is Python 3) found." echo "Sorry, but VESSL Flare requires Python 3." exit 1 } _check_root() { _EUID=$(id -u) if [ "${_EUID}" != "0" ] then echo "===== USER NOT ROOT! =====" echo "You do not appear to be root (user id ${_EUID} != 0)." echo "Without root permission, Flare may not able to read" echo "certain system files or execute certain commands." echo echo "We recommend running Flare with root permission." if _command_exists sudo then echo "For example:" echo " \$ curl -L ${URL_BASE} | sudo sh" fi echo if [ -n "${FLARE_NOROOT}" ] then echo "Since FLARE_NOROOT environment variable is set," echo "Flare will run without root permission." echo return 0 fi echo "If you understand the message above and are still sure that you" echo "need to run Flare as non-root, please set environment variable" echo "FLARE_NOROOT to non-empty string and run Flare again." return 1 fi } # HELPER FUNCTIONS END ######################### _find_python3 _check_root TEMPDIR="$(mktemp -d)" PATH_TAR="${TEMPDIR}/flare.tar" PATH_PYROOT="${TEMPDIR}/code" mkdir -p "${PATH_PYROOT}" _download_to "${URL_BASE}/flare.tar" "${PATH_TAR}" tar -x -f "${PATH_TAR}" -C "${PATH_PYROOT}" "${PY_CMD}" "${PATH_PYROOT}/main.py" "$@"