Skip to content

Commit b55fb8b

Browse files
Mikhail Swiftcolek42
authored andcommitted
chore: add guards to scripts to check presence of required programs
Just adds some friendlier messages when running our test and example scripts. This came up when a developer tried to use the scripts and encountered errors. Signed-off-by: Mikhail Swift <[email protected]>
1 parent 97ca6e2 commit b55fb8b

7 files changed

Lines changed: 78 additions & 6 deletions

File tree

examples/log4shell/build.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/bin/sh
21
# Copyright 2022 The Witness Contributors
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +12,17 @@
1312
# See the License for the specific language governing permissions and
1413
# limitations under the License.
1514

16-
15+
#!/bin/sh
1716
set -e
1817

18+
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
19+
. "$DIR/../../test/common.sh"
20+
21+
if ! checkprograms make docker ; then
22+
exit 1
23+
fi
24+
25+
1926
printf "Building witness...\n"
2027
make -C ../../ clean build > /dev/null
2128
cp ../../bin/witness ./witness

examples/log4shell/find-affected-artifacts.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/bin/sh
21
# Copyright 2022 The Witness Contributors
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,8 +12,16 @@
1312
# See the License for the specific language governing permissions and
1413
# limitations under the License.
1514

15+
#!/bin/sh
1616
set -e
1717

18+
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
19+
. "$DIR/../../test/common.sh"
20+
21+
if ! checkprograms awk sha256sum docker tr jq ; then
22+
exit 1
23+
fi
24+
1825
printf "\nFinding artifacts with log4j 1.2.17...\n"
1926
LOG4JHASH=$(echo -n dependency:log4j/[email protected] | sha256sum | awk '{print $1}')
2027
entryuuid=$(docker run --rm -it --net host witness-log4shell-demo rekor-cli --rekor_server http://localhost:3000 search --sha "$LOG4JHASH" |\

examples/log4shell/verify.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/bin/sh
21
# Copyright 2022 The Witness Contributors
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,8 +12,17 @@
1312
# See the License for the specific language governing permissions and
1413
# limitations under the License.
1514

15+
#!/bin/sh
1616
set -e
1717

18+
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
19+
. "$DIR/../../test/common.sh"
20+
21+
if ! checkprograms docker ; then
22+
exit 1
23+
fi
24+
25+
1826
printf "\nVerifying policy on nonvulnerable package...\n"
1927
docker run --rm -it --net host -v "$(pwd):/src" -w /src/nonvuln witness-log4shell-demo witness verify -c ../witness.yaml --artifactfile target/my-app-1.0-SNAPSHOT.jar
2028

examples/solarwinds/demo.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/bin/sh
21
# Copyright 2021 The Witness Contributors
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,8 +12,16 @@
1312
# See the License for the specific language governing permissions and
1413
# limitations under the License.
1514

15+
#!/bin/sh
1616
set -e
1717

18+
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
19+
. "$DIR/../../test/common.sh"
20+
21+
if ! checkprograms make docker ; then
22+
exit 1
23+
fi
24+
1825
printf "Building witness...\n"
1926
make -C ../../ clean build > /dev/null
2027
cp ../../bin/witness ./witness

test/common.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2022 The Witness Contributors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#/bin/sh
16+
checkprograms() {
17+
local result=0
18+
for prog in "$@"
19+
do
20+
if ! command -v $prog > /dev/null; then
21+
printf "$prog is required to run this script. please ensure if is installed and in your PATH\n"
22+
result=1
23+
fi
24+
done
25+
26+
return $result
27+
}

test/test-oci.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
#!/bin/sh
1616
set -e
1717

18+
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
19+
. "$DIR/common.sh"
20+
21+
if ! checkprograms make ko ; then
22+
exit 1
23+
fi
24+
1825
make -C ../ build
1926
rm -f out.tar
2027
KO_DOCKER_REPO=null ../bin/witness run -c test.yaml -a oci --trace=false -- ko publish --push=false --tarball out.tar .

test/test.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#! /bin/bash
21
# Copyright 2021 The Witness Contributors
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,8 +12,18 @@
1312
# See the License for the specific language governing permissions and
1413
# limitations under the License.
1514

15+
#! /bin/sh
1616
set -e
1717

18+
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
19+
. "$DIR/common.sh"
20+
21+
if ! checkprograms make ; then
22+
exit 1
23+
fi
24+
25+
26+
1827
make -C ../ build
1928
rm -f ./test-attestation.demo ./testapp ./policy-signed.json
2029
../bin/witness -c test.yaml run -- go build -o=testapp .

0 commit comments

Comments
 (0)