install_requirements.sh 2.97 KB
Newer Older
#!/bin/bash
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
# If not already set, set the list of components you want to install dependencies for.
# By default, dependencies for all components are installed.
# Components still not supported by this script:
#   ztp & policy : implemented in Java
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
#   dlt                 : under design
#   pathcomp            : under design
ALL_COMPONENTS="context device service nbi monitoring webui interdomain slice"
ALL_COMPONENTS="${ALL_COMPONENTS} dbscanserving opticalattackmitigator opticalattackdetector"
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
ALL_COMPONENTS="${ALL_COMPONENTS} l3_attackmitigator l3_centralizedattackdetector l3_distributedattackdetector"
TFS_COMPONENTS=${TFS_COMPONENTS:-$ALL_COMPONENTS}

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
# Some components require libyang built from source code
# - Ref: https://github.com/CESNET/libyang
# - Ref: https://github.com/CESNET/libyang-python/
echo "Installing libyang..."
sudo apt-get --yes --quiet --quiet update
sudo apt-get --yes --quiet --quiet install build-essential cmake libpcre2-dev python3-dev python3-cffi
mkdir libyang
git clone https://github.com/CESNET/libyang.git libyang
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
git fetch
git checkout v2.1.148
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
mkdir libyang/build
cd libyang/build
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
echo "*" > .gitignore
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
cmake -D CMAKE_BUILD_TYPE:String="Release" ..
make
sudo make install
sudo ldconfig
cd ../..

echo "Updating PIP, SetupTools and Wheel..."
pip install --upgrade pip               # ensure next packages get the latest versions
pip install --upgrade setuptools wheel  # bring basic tooling for other requirements
pip install --upgrade pip-tools pylint  # bring tooling for package compilation and code linting
printf "\n"

echo "Creating integrated requirements file..."
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
touch requirements.in
diff requirements.in common_requirements.in | grep '^>' | sed 's/^>\ //' >> requirements.in
printf "\n"

echo "Collecting requirements from components..."
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
for COMPONENT in $TFS_COMPONENTS
    if [ "$COMPONENT" == "ztp" ] || [ "$COMPONENT" == "policy" ]; then continue; fi
    diff requirements.in src/$COMPONENT/requirements.in | grep '^>' | sed 's/^>\ //' >> requirements.in
done
printf "\n"

echo "Compiling requirements..."
# Done in a single step to prevent breaking dependencies between components
pip-compile --quiet --output-file=requirements.txt requirements.in
printf "\n"

echo "Installing requirements..."
python -m pip install -r requirements.txt
printf "\n"

#echo "Removing the temporary files..."
rm requirements.in
rm requirements.txt
printf "\n"