sc3dev/install-development-tools.sh

155 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
#########################################################################
# This script attempts to install the appopriate build dependencies #
# for the host system. #
# #
# This is primarily developed on the latest Ubuntu LTS release and #
# MacOS; other platforms are not supported. #
# #
# The primary packages required: #
# #
# - clang #
# - clang-tidy #
# - cmake #
# - cppcheck #
# - doxygen #
# - git #
# - graphviz #
# - make #
# - scdoc #
# #
# Furthermore, certain CI systems require additional packages, and some #
# base system packages are also useful. #
# #
# - bash #
# - ca-certificates #
# - gzip #
# - ssh #
# - tar #
#########################################################################
set -eu
AUTOMATED_MODE=${AUTOMATED_MODE:-}
install_debianesque () {
APTARGS=""
SUDO="sudo"
if [ "$(whoami)" == "root" ]
then
SUDO=
fi
if [ ! -z "${AUTOMATED_MODE}" ]
then
APTARGS="-y"
fi
echo "[+] distribution is ${DISTRIB_ID}, choosing Debianesque install."
if [ -z "$(command -v cmake)" ]
then
install-cmake-debian.sh
fi
echo "[+] installing tools"
sudo $SUDO apt-get $APTARGS install git clang scdoc \
python3-pip doxygen graphviz valgrind
}
install_alpine () {
APK_ADD="apk add --update-cache"
echo "[+] distribution is ${DISTRIB_ID}, choosing Alpine install."
$APK_ADD alpine-sdk
echo "[+] setting up base system"
$APK_ADD bash ca-certificates gzip openssh tar
echo "[+] installing development tooling"
$APK_ADD clang clang-extra-tools cmake cppcheck doxygen g++ git \
graphviz make scdoc valgrind
}
install_redhat () {
DNF_INSTALL="dnf install -y"
SUDO="sudo"
if [ "$(whoami)" == "root" ]
then
SUDO=
fi
echo "[+] setting up base system"
# dnf is probably the slowest package manager I've used, so
# install everything in one shot.
$DNF_INSTALL ca-certificates gzip openssh tar \
clang clang-tools-extra cmake cppcheck doxygen \
gcc-c++ git graphviz libstdc++-devel make scdoc \
valgrind rpmdevtools
}
install_unsupported () {
echo "[+] distribution is ${DISTRIB_ID}, choosing Redhat install."
echo "[!] This distribution is unsupported." > /dev/stderr
exit 1;
}
install_macos () {
# TODO: consider supporting macports?
echo "[+] host system is MacOS"
echo "[+] installing tools"
brew install git cmake scdoc
echo "[+] installing libraries and development headers"
# TODO: look up proper package names in homebrew
}
install_linux () {
DISTRIB_ID="${DISTRIB_ID:-}"
echo "[+] host system is Linux"
if [[ -f "/etc/lsb-release" ]]
then
source /etc/lsb-release
elif [[ -d "/etc/apt" ]]
then
DISTRIB_ID="apt-based"
elif [[ -f "/etc/rpi-issue" ]]
then
DISTRIB_ID=apt-based
elif [[ -d "/etc/apk" ]]
then
DISTRIB_ID=alpine
elif [[ -d "/etc/dnf" ]]
then
DISTRIB_ID="redhat"
else
DISTRIB_ID="unsupported/unknown"
fi
case ${DISTRIB_ID} in
Ubuntu) install_debianesque ;;
Debian) install_debianesque ;;
apt-based) install_debianesque ;;
alpine) install_alpine ;;
redhat) install_redhat ;;
*)
echo "[!] distribution ${DISTRIB_ID} isn't supported in this script." > /dev/null
exit 1
;;
esac
}
case "$(uname -s)" in
Linux) install_linux ;;
Darwin) install_macos ;;
*)
echo "[!] platform $(uname -s) isn't supported in this script." > /dev/null
;;
esac