Skip to content

Commit

Permalink
Merge pull request #1459 from p-l-/lint-shell
Browse files Browse the repository at this point in the history
lint: use shellcheck
  • Loading branch information
p-l- committed Dec 13, 2022
2 parents c0fdc5f + a1f766a commit 2644a89
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 40 deletions.
33 changes: 18 additions & 15 deletions .github/actions/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ sudo apt-get -q update
sudo apt-get -qy install tesseract-ocr tesseract-ocr-osd tesseract-ocr-eng phantomjs p0f
pip install .
mv ivre ivre_bak
cat .github/workflows/files/ivre.conf >> ~/.ivre.conf
echo "NMAP_SHARE_PATH = '`pwd`/usr/local/nmap/share/nmap'" >> ~/.ivre.conf
echo "WIRESHARK_SHARE_PATH = '`pwd`/usr/local/wireshark/share/wireshark'" >> ~/.ivre.conf
{
cat .github/workflows/files/ivre.conf
echo "NMAP_SHARE_PATH = '$(pwd)/usr/local/nmap/share/nmap'"
echo "WIRESHARK_SHARE_PATH = '$(pwd)/usr/local/wireshark/share/wireshark'"
} >> ~/.ivre.conf
mkdir -p usr/local/wireshark/share/wireshark
wget -q https://raw.githubusercontent.com/wireshark/wireshark/master/manuf -O usr/local/wireshark/share/wireshark/manuf
wget -q -O - https://github.com/ivre/ivre-test-samples/archive/c7f4f992e4f55c14f396efb6043adb617aa4ffc8.tar.gz | tar --transform='s#^ivre-test-samples-[^/]*/*#./#' -zxf -
Expand All @@ -33,29 +35,30 @@ if [ "${USE_PYOPENSSL}" = "0" ]; then
pip uninstall -y pyOpenSSL
fi

UBUNTU_VERSION="`awk -F = '/^DISTRIB_RELEASE=/ {print $2}' /etc/lsb-release`"
UBUNTU_VERSION="$(awk -F = '/^DISTRIB_RELEASE=/ {print $2}' /etc/lsb-release)"
echo "UBUNTU_VERSION: ${UBUNTU_VERSION}"

for archive in tools-travis-ivre nmap-7.91_ubuntu-${UBUNTU_VERSION} nfdump-1.6.17; do
wget -q --no-check-certificate https://ivre.rocks/data/tests/${archive}.tar.bz2 -O - | tar jxf -
for archive in tools-travis-ivre "nmap-7.91_ubuntu-${UBUNTU_VERSION}" nfdump-1.6.17; do
wget -q --no-check-certificate "https://ivre.rocks/data/tests/${archive}.tar.bz2" -O - | tar jxf -
done

mv tests/geoip/GeoLite2-{ASN,City,Country,RegisteredCountry}.dump-IPv4.csv.bz2 `python -c 'from ivre import config; print(config.GEOIP_PATH)'`; bunzip2 "/`python -c 'from ivre import config; print(config.GEOIP_PATH)'`/"GeoLite2-{ASN,City,Country,RegisteredCountry}.dump-IPv4.csv.bz2
mv tests/geoip/GeoLite2-{ASN,City,Country,RegisteredCountry}.dump-IPv4.csv.bz2 "$(python -c 'from ivre import config; print(config.GEOIP_PATH)')"; bunzip2 "/$(python -c 'from ivre import config; print(config.GEOIP_PATH)')/GeoLite2-"{ASN,City,Country,RegisteredCountry}.dump-IPv4.csv.bz2

for path_val in "`pwd`/usr/local/nmap/bin" "`pwd`/usr/local/nfdump/bin"; do
echo "$path_val" >> $GITHUB_PATH
for path_val in "$(pwd)/usr/local/nmap/bin" "$(pwd)/usr/local/nfdump/bin"; do
echo "$path_val" >> "$GITHUB_PATH"
export PATH="$path_val:$PATH"
done

for env_val in "LD_LIBRARY_PATH=`pwd`/usr/local/zeek/lib:`pwd`/usr/local/nfdump/lib"; do
echo "$env_val" >> $GITHUB_ENV
export "$env_val"
# shellcheck disable=SC2066
for env_val in "LD_LIBRARY_PATH=$(pwd)/usr/local/zeek/lib:$(pwd)/usr/local/nfdump/lib"; do
echo "$env_val" >> "$GITHUB_ENV"
export "${env_val?}"
done

cp `python -c "import ivre.config; print(ivre.config.guess_prefix('patches'))"`/nmap/scripts/*.nse `pwd`/usr/local/nmap/share/nmap/scripts/
for patch in `python -c "import ivre.config; print(ivre.config.guess_prefix('patches'))"`/nmap/*; do (cd `pwd`/usr/local/nmap/share/nmap && patch -p0 < $patch); done
cp "$(python -c "import ivre.config; print(ivre.config.guess_prefix('patches'))")/nmap/scripts/"*.nse "$(pwd)/usr/local/nmap/share/nmap/scripts/"
for patch in "$(python -c "import ivre.config; print(ivre.config.guess_prefix('patches'))")/nmap/"*; do (cd "$(pwd)/usr/local/nmap/share/nmap" && patch -p0 < "$patch"); done
nmap --script-updatedb

sudo patch /etc/p0f/p0f.fp `python -c "import ivre.config; print(ivre.config.guess_prefix('patches'))"`/p0f/p0f.fp.patch
sudo patch /etc/p0f/p0f.fp "$(python -c "import ivre.config; print(ivre.config.guess_prefix('patches'))")/p0f/p0f.fp.patch"

ivre --version && nmap --version
22 changes: 12 additions & 10 deletions .github/actions/install/install_zeek.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash

# This file is part of IVRE.
# Copyright 2011 - 2021 Pierre LALET <pierre@droids-corp.org>
# Copyright 2011 - 2022 Pierre LALET <pierre@droids-corp.org>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand All @@ -28,21 +28,23 @@ if [ "${ZEEK_VERSION:0:2}" = "4." ]; then
cat tests/samples/results_zeek_v4 >> tests/samples/results
fi

UBUNTU_VERSION="`awk -F = '/^DISTRIB_RELEASE=/ {print $2}' /etc/lsb-release`"
UBUNTU_VERSION="$(awk -F = '/^DISTRIB_RELEASE=/ {print $2}' /etc/lsb-release)"
echo "UBUNTU_VERSION: ${UBUNTU_VERSION}"

for archive in zeek-${ZEEK_VERSION}_ubuntu-${UBUNTU_VERSION}; do
wget -q --no-check-certificate https://ivre.rocks/data/tests/${archive}.tar.bz2 -O - | tar jxf -
# shellcheck disable=SC2066
for archive in "zeek-${ZEEK_VERSION}_ubuntu-${UBUNTU_VERSION}"; do
wget -q --no-check-certificate "https://ivre.rocks/data/tests/${archive}.tar.bz2" -O - | tar jxf -
done

for path_val in "`pwd`/usr/local/zeek/bin"; do
echo "$path_val" >> $GITHUB_PATH
# shellcheck disable=SC2066
for path_val in "$(pwd)/usr/local/zeek/bin"; do
echo "$path_val" >> "$GITHUB_PATH"
export PATH="$path_val:$PATH"
done

for env_val in "ZEEKPATH=.:`pwd`/usr/local/zeek/share/zeek:`pwd`/usr/local/zeek/share/zeek/policy:`pwd`/usr/local/zeek/share/zeek/site" "ZEEKSAMPLES=`pwd`/usr/local/zeek/testing"; do
echo "$env_val" >> $GITHUB_ENV
export "$env_val"
for env_val in "ZEEKPATH=.:$(pwd)/usr/local/zeek/share/zeek:$(pwd)/usr/local/zeek/share/zeek/policy:$(pwd)/usr/local/zeek/share/zeek/site" "ZEEKSAMPLES=$(pwd)/usr/local/zeek/testing"; do
echo "$env_val" >> "$GITHUB_ENV"
export "${env_val?}"
done

LD_LIBRARY_PATH=`pwd`/usr/local/zeek/lib zeek --version
LD_LIBRARY_PATH="$(pwd)/usr/local/zeek/lib zeek --version"
6 changes: 5 additions & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- run: curl -L https://github.com/koalaman/shellcheck/releases/download/v0.9.0/shellcheck-v0.9.0.linux.x86_64.tar.xz | tar -Jxf - -C /usr/local/bin --strip-components 1 shellcheck-v0.9.0/shellcheck

- run: pip install -r requirements-linting.txt

- run: pip install .
Expand All @@ -46,7 +48,7 @@ jobs:

- run: bandit --severity-level high -r ./doc/conf.py ./setup.py ./bin/ivre ./tests/tests.py ./ivre_bak/ ./pkg/stubs/

- run: codespell --ignore-words=pkg/codespell_ignore `git ls-files | grep -vE '^web/static/(doc|an|bs|d3|jq|lk)/|^data/|\.(png|gif|svg)$'`
- run: git ls-files | grep -vE '^web/static/(doc|an|bs|d3|jq|lk)/|^data/|\.(png|gif|svg)$' | xargs -r codespell --ignore-words=pkg/codespell_ignore

- run: pylint -e all -d abstract-method,arguments-differ,attribute-defined-outside-init,broad-except,duplicate-code,fixme,function-redefined,global-statement,import-error,invalid-name,locally-disabled,missing-docstring,no-member,protected-access,super-init-not-called,suppressed-message,too-few-public-methods,too-many-ancestors,too-many-arguments,too-many-boolean-expressions,too-many-branches,too-many-instance-attributes,too-many-lines,too-many-locals,too-many-nested-blocks,too-many-public-methods,too-many-return-statements,too-many-statements,unsubscriptable-object,unused-argument,line-too-long,consider-using-f-string ivre ./doc/conf.py ./setup.py ./bin/ivre
- run: pylint -e all -d unused-argument,too-many-arguments,missing-function-docstring,missing-class-docstring,missing-module-docstring,multiple-statements,invalid-name,too-few-public-methods ./pkg/stubs/*.pyi
Expand All @@ -68,3 +70,5 @@ jobs:
- run: if ! find ./doc/ -type f -name '*.rst' -print0 | xargs -0 grep '[[:space:]]$'; then echo "trailing spaces OK"; else echo "!! trailing spaces !!"; false; fi

- run: sphinx-lint -e all -d line-too-long -d default-role ./doc/

- run: shellcheck .github/actions/install/install*.sh pkg/builddockers pkg/builddocs pkg/buildrpm pkg/runchecks
10 changes: 5 additions & 5 deletions pkg/builddockers
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash

# This file is part of IVRE.
# Copyright 2011 - 2021 Pierre LALET <pierre@droids-corp.org>
# Copyright 2011 - 2022 Pierre LALET <pierre@droids-corp.org>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand All @@ -20,17 +20,17 @@ docker pull debian:stable
docker pull debian:buster

# Create ivre/VERSION if needed
VERSION="`python3 setup.py --version 2>/dev/null`"
VERSION="$(python3 setup.py --version 2>/dev/null)"

case "$VERSION" in
*.dev*)
branch="`git rev-parse --abbrev-ref HEAD`"
branch="$(git rev-parse --abbrev-ref HEAD)"
case "$branch" in
master)
tag="latest"
;;
HEAD)
tag="commit-`git rev-parse HEAD | cut -c -8`"
tag="commit-$(git rev-parse HEAD | cut -c -8)"
echo "WARNING: version $VERSION / HEAD" >&2
;;
*)
Expand All @@ -50,7 +50,7 @@ esac
git archive --format=tar --prefix=ivre/ HEAD -o docker/base-local/ivre.tar
tar --owner=root:0 --group=root:0 --transform='s#^#ivre/#' -rf docker/base-local/ivre.tar ivre/VERSION

cd `dirname $0`/../docker
cd "$(dirname "$0")/../docker" || exit 255

docker build --no-cache -t "ivre/base:$tag" "base-local" || exit $?

Expand Down
4 changes: 2 additions & 2 deletions pkg/builddocs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/sh

# This file is part of IVRE.
# Copyright 2011 - 2019 Pierre LALET <pierre.lalet@cea.fr>
# Copyright 2011 - 2022 Pierre LALET <pierre@droids-corp.org>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand All @@ -16,6 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with IVRE. If not, see <http://www.gnu.org/licenses/>.

cd `dirname $0`/../doc
cd "$(dirname "$0")/../doc" || exit 255
make html && rm -rf ../web/static/doc && mv _build/html ../web/static/doc && rm -rf _build/

10 changes: 5 additions & 5 deletions pkg/buildrpm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/sh

# This file is part of IVRE.
# Copyright 2011 - 2020 Pierre LALET <pierre@droids-corp.org>
# Copyright 2011 - 2022 Pierre LALET <pierre@droids-corp.org>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand All @@ -17,8 +17,8 @@
# along with IVRE. If not, see <http://www.gnu.org/licenses/>.

RELEASE=1
DISTRIB="`rpmbuild --eval \"%{?dist}\"`"
VERSION="`python setup.py --version`"
DISTRIB="$(rpmbuild --eval \"%\{?dist\}\"$)"
VERSION="$(python setup.py --version)"

python setup.py bdist_rpm --release=$RELEASE --distribution-name=$DISTRIB --requires=pymongo,python-crypto --obsoletes=IVRE
mv dist/ivre-$VERSION-$RELEASE.noarch.rpm dist/ivre-$VERSION-${RELEASE}${DISTRIB}.noarch.rpm
python setup.py bdist_rpm --release="$RELEASE" --distribution-name="$DISTRIB" --requires=pymongo,python-crypto --obsoletes=IVRE
mv "dist/ivre-$VERSION-$RELEASE.noarch.rpm" "dist/ivre-$VERSION-${RELEASE}${DISTRIB}.noarch.rpm"
6 changes: 4 additions & 2 deletions pkg/runchecks
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/sh
#! /bin/bash

# This file is part of IVRE.
# Copyright 2011 - 2022 Pierre LALET <pierre@droids-corp.org>
Expand Down Expand Up @@ -29,7 +29,7 @@ MYPYPATH=./pkg/stubs/ mypy --follow-imports=skip --disallow-untyped-calls --disa
# partial sub-modules
MYPYPATH=./pkg/stubs/ mypy --follow-imports=skip --disallow-untyped-calls --disallow-untyped-decorators --disallow-incomplete-defs --no-implicit-optional --warn-redundant-casts --warn-unused-ignores --warn-return-any ./ivre/db/mongo.py && echo "mypy (partial) OK"

codespell --ignore-words=pkg/codespell_ignore `git ls-files | grep -vE '^web/static/(doc|an|bs|d3|jq|lk)/|^data/|\.(png|gif|svg)$'` && echo "codespell OK"
git ls-files | grep -vE '^web/static/(doc|an|bs|d3|jq|lk)/|^data/|\.(png|gif|svg)$' | xargs -r codespell --ignore-words=pkg/codespell_ignore && echo "codespell OK"

pylint -e all -d abstract-method,arguments-differ,attribute-defined-outside-init,broad-except,duplicate-code,fixme,function-redefined,global-statement,import-error,invalid-name,locally-disabled,missing-docstring,no-member,protected-access,super-init-not-called,suppressed-message,too-few-public-methods,too-many-ancestors,too-many-arguments,too-many-boolean-expressions,too-many-branches,too-many-instance-attributes,too-many-lines,too-many-locals,too-many-nested-blocks,too-many-public-methods,too-many-return-statements,too-many-statements,unsubscriptable-object,unused-argument,line-too-long,consider-using-f-string ivre ./doc/conf.py ./setup.py ./bin/ivre && echo "pylint OK"

Expand All @@ -41,3 +41,5 @@ rstcheck -r ./doc/ && echo "rstcheck OK"
if ! find ./doc/ -type f -name '*.rst' -print0 | xargs -0 grep '[[:space:]]$'; then echo "trailing spaces OK"; else echo "!! trailing spaces !!"; false; fi

sphinx-lint -e all -d line-too-long -d default-role ./doc/ && echo "sphinx-lint OK"

shellcheck .github/actions/install/install*.sh pkg/builddockers pkg/builddocs pkg/buildrpm pkg/runchecks && echo "shellcheck OK"

0 comments on commit 2644a89

Please sign in to comment.