2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2020 Samsung Electronics
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
15 # _vercmp() - Function that compares two versions
22 # sort the two numbers with sort's "-V" argument. Based on if v2
23 # swapped places with v1, we can determine ordering.
24 result=$(echo -e "$v1\n$v2" | sort -V | head -1)
32 [ "$v1" != "$v2" ] && [ "$result" = "$v2" ]
36 [ "$v1" != "$v2" ] && [ "$result" = "$v1" ]
48 die $LINENO "unrecognised op: $op"
53 echo "Requirements validation"
54 # shellcheck disable=SC1091
55 source /etc/os-release || source /usr/lib/os-release
57 min_shellcheck_version=0.4.0
61 if ! command -v shellcheck; then
63 *suse*|rhel|centos|fedora)
71 if ! command -v pip; then
73 *suse*|rhel|centos|fedora)
74 pkgs+=" python3-pip python3-setuptools"
77 if _vercmp "${VERSION_ID}" '<=' "18.04"; then
78 pkgs+=" python-pip python-setuptools"
80 pkgs+=" python3-pip python3-setuptools"
86 if [ -n "$pkgs" ]; then
87 echo "Requirements installation"
90 sudo zypper install --gpg-auto-import-keys refresh
91 # shellcheck disable=SC2086
92 sudo -H -E zypper install -y --no-recommends $pkgs
96 # shellcheck disable=SC2086
97 sudo -H -E apt-get -y --no-install-recommends install $pkgs
100 PKG_MANAGER=$(command -v dnf || command -v yum)
101 if ! sudo "$PKG_MANAGER" repolist | grep "epel/"; then
102 sudo -H -E "$PKG_MANAGER" -q -y install epel-release
104 sudo "$PKG_MANAGER" updateinfo --assumeyes
105 # shellcheck disable=SC2086
106 sudo -H -E "$PKG_MANAGER" -y install $pkgs
109 if ! command -v pip && command -v pip3 ; then
110 sudo ln -s "$(command -v pip3)" /usr/bin/pip
112 sudo "$(command -v pip)" install --upgrade pip
115 if ! command -v tox || _vercmp "$(tox --version | awk '{print $1}')" '<' "$min_tox_version"; then
116 sudo "$(command -v pip)" install tox==$min_tox_version
119 echo "Server tools information:"
124 echo "Linting process execution"
126 if _vercmp "$(shellcheck --version | awk 'FNR==2{print $2}')" '<' "$min_shellcheck_version"; then
127 bash -c 'shopt -s globstar; shellcheck **/*.sh'
129 bash -c 'shopt -s globstar; shellcheck -x **/*.sh'