Files
OpenUxAS-bootstrap/install/bootstrap
2020-08-12 15:50:00 -04:00

137 lines
3.4 KiB
Bash
Executable File

#! /usr/bin/env bash
# Supported options are given with environment variables. All arguments are
# passed through to install/install
#
# Options
#
# BOOTSTRAP_ROOT : specify the directory in which the bootstrap should be
# placed. Defaults to: ${HOME}/bootstrap
#
# BOOTSTRAP_FORK : specify the fork of OpenUxAS-bootstrap to use. Defaults
# to: afrl-rq/OpenUxAS-bootstrap
#
# BOOTSTRAP_REF : specify the ref-spec that should be checked out. Defaults
# to HEAD of the repo's default branch.
#
# USE_GIT_URI : if set (to anything other than the empty string), do not
# perform the checkout using https.
#
# ADA : if set (to anything other than the empty string), install
# GNAT Community Edition, to enable Ada development.
#
# DEVEL : if set (to anything other than the empty string),
# configure uxas, lmcp and amase for development.
ARGS=$@
if [ -z "$BOOTSTRAP_ROOT" ]; then
BOOTSTRAP_ROOT="${HOME}/bootstrap"
fi
if [ -z "$BOOTSTRAP_FORK" ]; then
BOOTSTRAP_FORK="afrl-rq/OpenUxAS-bootstrap.git"
fi
colorize() {
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
else echo -n "$2"
fi
}
# Checks for bootstrap, and suggests to remove it for installing
if [ -d "${BOOTSTRAP_ROOT}" ]; then
{ echo
colorize 1 "CRITICAL"
echo ": Can not proceed with installation. Kindly remove the '${BOOTSTRAP_ROOT}' directory first."
echo
} >&2
exit 1
fi
if ! command -v git 1>/dev/null 2>&1; then
{ echo
colorize 1 "CRITICAL"
echo ": Git is not installed, can't continue."
echo
} >&2
exit 1
fi
if ! command -v python3 1>/dev/null 2>&1; then
{ echo
colorize 1 "CRITICAL"
echo ": python3 is not installed, can't continue."
echo
} >&2
exit 1
fi
PYTHON_MAJOR_VERSION=$( python3 -c 'import sys; print(sys.version_info[0])' )
PYTHON_MINOR_VERSION=$( python3 -c 'import sys; print(sys.version_info[1])' )
if ((10#${PYTHON_MAJOR_VERSION} < 3)); then
{ echo
colorize 1 "CRITICAL"
echo ": python >= 3.7 is required, can't continue."
echo
} >&2
exit 1
else
if ((10#${PYTHON_MINOR_VERSION} < 7)); then
{ echo
colorize 1 "CRITICAL"
echo ": python >= 3.7 is required, can't continue."
echo
}
exit 1
fi
fi
failed_clone() {
colorize 1 "CRITICAL"
echo ": Failed to git clone $1"
exit -1
}
clone() {
[ -d "$2" ] || git clone --depth 1 "$1" "$2" || failed_clone "$1"
}
failed_checkout() {
colorize 1 "CRITICAL"
echo ": Failed to check out $1"
exit -2
}
checkout() {
(git fetch --unshallow --update-head-ok origin '+refs/heads/*:refs/heads/*' \
&& git checkout "$1") || failed_checkout "$1"
}
if [ -n "${USE_GIT_URI}" ]; then
GITHUB="git://github.com"
else
GITHUB="https://github.com"
fi
clone "${GITHUB}/${BOOTSTRAP_FORK}" "${BOOTSTRAP_ROOT}"
if [ -n "${BOOTSTRAP_REF}" ]; then
(cd "${BOOTSTRAP_ROOT}" && checkout "${BOOTSTRAP_REF}") || exit $?
fi
if [ -n "${ADA}" ]; then
(cd "${BOOTSTRAP_ROOT}" && \
python3 install/install --automatic -v --log-file bootstrap.log ${ARGS})
else
(cd "${BOOTSTRAP_ROOT}" && \
python3 install/install --automatic -v --log-file bootstrap.log --no-gnat ${ARGS})
fi
if [ -n "${DEVEL}" ]; then
(cd "${BOOTSTRAP_ROOT}" && \
eval "$( python3 install/install-anod-venv --printenv )" && \
python3 anod devel-setup uxas lmcp amase --log-file devel-setup.log)
fi