2019-11-26 02:44:14 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-01-19 05:16:07 -08:00
|
|
|
# Tells bash to exit if any command returns a non-zero return value
|
|
|
|
set -e
|
|
|
|
|
2019-11-26 02:44:14 -08:00
|
|
|
service="$1"
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "-=------------------------------------------------------"
|
|
|
|
echo " Starting installation for service '$service'..."
|
|
|
|
echo "-=------------------------------------------------------"
|
|
|
|
|
|
|
|
if [ "$DEBUG" = true ]
|
|
|
|
then
|
2019-12-03 18:26:59 -08:00
|
|
|
echo ""
|
|
|
|
echo "Command-line Args:"
|
|
|
|
echo " - service: $service"
|
2019-11-26 02:44:14 -08:00
|
|
|
echo ""
|
|
|
|
echo "Environment Variables:"
|
|
|
|
echo " - DEBIAN_FRONTEND: $DEBIAN_FRONTEND"
|
2019-12-03 18:26:59 -08:00
|
|
|
echo " - PATH: $PATH"
|
2019-11-26 02:44:14 -08:00
|
|
|
echo " - GRADLE_VERSION: $GRADLE_VERSION"
|
|
|
|
echo " - GRADLE_HOME: $GRADLE_HOME"
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
|
2019-12-03 18:26:59 -08:00
|
|
|
apt_pkgs=""
|
2019-11-26 02:44:14 -08:00
|
|
|
rm_pkgs=""
|
|
|
|
install_gradle=false
|
2019-12-03 18:26:59 -08:00
|
|
|
pip_common_pkgs="Fabric3 numpy requests"
|
|
|
|
master_pip_reqs_file=/requirements.txt
|
|
|
|
pip_reqs_file="/${service}-requirements.txt"
|
|
|
|
|
|
|
|
if [ "$service" = "base" ]
|
|
|
|
then
|
2019-12-11 09:43:20 -08:00
|
|
|
apt_pkgs="python3.6 python3-setuptools python3-pip libssl-dev vim dnsutils iputils-ping"
|
2019-11-26 02:44:14 -08:00
|
|
|
|
2019-12-03 18:26:59 -08:00
|
|
|
# Filter common pip packages
|
|
|
|
for pip_pkg in $pip_common_pkgs
|
|
|
|
do
|
|
|
|
grep "^$pip_pkg" "$master_pip_reqs_file" >> "$pip_reqs_file"
|
|
|
|
done
|
|
|
|
|
|
|
|
elif [ "$service" = "web" ]
|
2019-11-26 02:44:14 -08:00
|
|
|
then
|
2020-04-06 12:39:50 -07:00
|
|
|
apt_pkgs="python3-dev gcc g++ mysql-client libmysqlclient-dev python-mysqldb postgresql-client"
|
2019-11-26 02:44:14 -08:00
|
|
|
|
2020-04-06 12:39:50 -07:00
|
|
|
rm_pkgs="gcc g++"
|
2019-11-26 02:44:14 -08:00
|
|
|
|
2019-12-03 18:26:59 -08:00
|
|
|
pip_skip_pkgs="$pip_common_pkgs astroid autopep8 git-lint pycodestyle pylint"
|
|
|
|
cp "$master_pip_reqs_file" "$pip_reqs_file"
|
2019-11-26 02:44:14 -08:00
|
|
|
|
2019-12-03 18:26:59 -08:00
|
|
|
for pip_pkg in $pip_skip_pkgs
|
2019-11-26 02:44:14 -08:00
|
|
|
do
|
2019-12-03 18:26:59 -08:00
|
|
|
sed -i "/$pip_pkg/d" "$pip_reqs_file"
|
2019-11-26 02:44:14 -08:00
|
|
|
done
|
|
|
|
|
2019-12-03 18:26:59 -08:00
|
|
|
elif [ "$service" = "driver" ]
|
|
|
|
then
|
|
|
|
apt_pkgs="openssh-server openjdk-11-jdk unzip wget"
|
|
|
|
rm_pkgs="unzip wget"
|
2019-11-26 02:44:14 -08:00
|
|
|
install_gradle=true
|
2019-12-03 18:26:59 -08:00
|
|
|
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
echo "ERROR: Invalid value for service: '$service'"
|
|
|
|
echo ""
|
2020-02-27 12:16:10 -08:00
|
|
|
echo "Usage: $0 [base|web|driver]"
|
2019-12-03 18:26:59 -08:00
|
|
|
exit 1
|
2019-11-26 02:44:14 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo -e "\nUpdating package index..."
|
|
|
|
apt-get update
|
|
|
|
|
|
|
|
if [ -n "$apt_pkgs" ]
|
|
|
|
then
|
|
|
|
# Install required apt packages
|
|
|
|
echo -e "\nInstalling apt packages: $apt_pkgs"
|
|
|
|
apt-get install -y --no-install-recommends $apt_pkgs
|
|
|
|
fi
|
|
|
|
|
2019-12-03 18:26:59 -08:00
|
|
|
if [ -f "$pip_reqs_file" ] && [ -s "$pip_reqs_file" ]
|
2019-11-26 02:44:14 -08:00
|
|
|
then
|
|
|
|
# Install required pip packages
|
|
|
|
python3 --version
|
|
|
|
pip3 --version
|
2019-12-03 18:26:59 -08:00
|
|
|
echo -e "\nInstalling pip packages: `cat "$pip_reqs_file" | tr '\n' ' '`"
|
|
|
|
pip3 install --no-cache-dir --disable-pip-version-check -r "$pip_reqs_file"
|
2019-11-26 02:44:14 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$install_gradle" = true ]
|
|
|
|
then
|
|
|
|
javac --version
|
|
|
|
echo -e "\nInstalling gradle"
|
|
|
|
wget --no-verbose https://services.gradle.org/distributions/${GRADLE_VERSION}-bin.zip
|
|
|
|
unzip ${GRADLE_VERSION}-bin.zip -d /opt
|
|
|
|
rm ${GRADLE_VERSION}-bin.zip
|
|
|
|
gradle --version
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$rm_pkgs" ]
|
|
|
|
then
|
|
|
|
# Remove packages needed only for install
|
|
|
|
echo -e "\nRemoving packages only required for install: $rm_pkgs"
|
|
|
|
apt-get purge -y --autoremove $rm_pkgs
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "-=------------------------------------------------------"
|
|
|
|
echo " Installation complete for service '$service'!"
|
|
|
|
echo "-=------------------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
|