summaryrefslogtreecommitdiffstats
path: root/jjb/kuberef/kuberef-run-linting.sh
diff options
context:
space:
mode:
authorVictor Morales <v.morales@samsung.com>2020-08-28 16:35:12 -0400
committerVictor Morales <v.morales@samsung.com>2020-08-28 17:17:01 -0400
commit6fb97028e93a7844000204be53ed937a47d9082f (patch)
tree4f6c8936d7205a1ea512f350bd79c6a57cee4487 /jjb/kuberef/kuberef-run-linting.sh
parent857de0535fcac0b353cc7f3c555060aa5807cfc7 (diff)
Improve kuberef lint script
The OPNFV security audit releng's job prevent to retrieve binaries from external sources which results on depending to the binaries provided by the OS package managers. This change pretends to cover different scenarios where the Jenkins builder is unknown. Signed-off-by: Victor Morales <v.morales@samsung.com> Change-Id: I37d9b15d3ac9de0b06a96e07eed90f7cc717f444
Diffstat (limited to 'jjb/kuberef/kuberef-run-linting.sh')
-rwxr-xr-xjjb/kuberef/kuberef-run-linting.sh78
1 files changed, 72 insertions, 6 deletions
diff --git a/jjb/kuberef/kuberef-run-linting.sh b/jjb/kuberef/kuberef-run-linting.sh
index 810f93321..084eac91c 100755
--- a/jjb/kuberef/kuberef-run-linting.sh
+++ b/jjb/kuberef/kuberef-run-linting.sh
@@ -12,10 +12,51 @@ set -o nounset
set -o pipefail
set -o xtrace
+# _vercmp() - Function that compares two versions
+function _vercmp {
+ local v1=$1
+ local op=$2
+ local v2=$3
+ local result
+
+ # sort the two numbers with sort's "-V" argument. Based on if v2
+ # swapped places with v1, we can determine ordering.
+ result=$(echo -e "$v1\n$v2" | sort -V | head -1)
+
+ case $op in
+ "==")
+ [ "$v1" = "$v2" ]
+ return
+ ;;
+ ">")
+ [ "$v1" != "$v2" ] && [ "$result" = "$v2" ]
+ return
+ ;;
+ "<")
+ [ "$v1" != "$v2" ] && [ "$result" = "$v1" ]
+ return
+ ;;
+ ">=")
+ [ "$result" = "$v2" ]
+ return
+ ;;
+ "<=")
+ [ "$result" = "$v1" ]
+ return
+ ;;
+ *)
+ die $LINENO "unrecognised op: $op"
+ ;;
+ esac
+}
+
echo "Requirements validation"
# shellcheck disable=SC1091
source /etc/os-release || source /usr/lib/os-release
+min_shellcheck_version=0.4.0
+min_tox_version=3.5
+
pkgs=""
if ! command -v shellcheck; then
case ${ID,,} in
@@ -27,9 +68,19 @@ if ! command -v shellcheck; then
;;
esac
fi
-
if ! command -v pip; then
- pkgs+=" python-pip"
+ case ${ID,,} in
+ *suse*|rhel|centos|fedora)
+ pkgs+=" python3-pip python3-setuptools"
+ ;;
+ ubuntu|debian)
+ if _vercmp "${VERSION_ID}" '<=' "18.04"; then
+ pkgs+=" python-pip python-setuptools"
+ else
+ pkgs+=" python3-pip python3-setuptools"
+ fi
+ ;;
+ esac
fi
if [ -n "$pkgs" ]; then
@@ -37,11 +88,13 @@ if [ -n "$pkgs" ]; then
case ${ID,,} in
*suse*)
sudo zypper install --gpg-auto-import-keys refresh
- sudo -H -E zypper install -y --no-recommends "$pkgs"
+ # shellcheck disable=SC2086
+ sudo -H -E zypper install -y --no-recommends $pkgs
;;
ubuntu|debian)
sudo apt-get update
- sudo -H -E apt-get -y --no-install-recommends install "$pkgs"
+ # shellcheck disable=SC2086
+ sudo -H -E apt-get -y --no-install-recommends install $pkgs
;;
rhel|centos|fedora)
PKG_MANAGER=$(command -v dnf || command -v yum)
@@ -49,9 +102,18 @@ if [ -n "$pkgs" ]; then
sudo -H -E "$PKG_MANAGER" -q -y install epel-release
fi
sudo "$PKG_MANAGER" updateinfo --assumeyes
- sudo -H -E "${PKG_MANAGER}" -y install "$pkgs"
+ # shellcheck disable=SC2086
+ sudo -H -E "$PKG_MANAGER" -y install $pkgs
;;
esac
+ if ! command -v pip && command -v pip3 ; then
+ sudo ln -s "$(command -v pip3)" /usr/bin/pip
+ fi
+ sudo "$(command -v pip)" install --upgrade pip
+fi
+
+if ! command -v tox || _vercmp "$(tox --version | awk '{print $1}')" '<' "$min_tox_version"; then
+ sudo "$(command -v pip)" install tox==$min_tox_version
fi
echo "Server tools information:"
@@ -61,4 +123,8 @@ shellcheck -V
echo "Linting process execution"
tox -e lint
-bash -c 'shopt -s globstar; shellcheck -x **/*.sh'
+if _vercmp "$(shellcheck --version | awk 'FNR==2{print $2}')" '<' "$min_shellcheck_version"; then
+ bash -c 'shopt -s globstar; shellcheck **/*.sh'
+else
+ bash -c 'shopt -s globstar; shellcheck -x **/*.sh'
+fi