Files
bind9/bin/tests/system/get_ports.sh
T
Tom Krizek b8b9b4ac2c Reformat shell scripts with shfmt
All changes in this commit were automated using the command:

shfmt -w -i 2 -ci -bn . $(find . -name "*.sh.in")

By default, only *.sh and files without extension are checked, so
*.sh.in files have to be added additionally. (See mvdan/sh#944)

(manually replayed commit 4cb8b13987)
2023-10-26 13:05:00 +02:00

76 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
# This script is a 'port' broker. It keeps track of ports given to the
# individual system subtests, so every test is given a unique port range.
get_sorted_test_names() {
find . -maxdepth 2 -mindepth 2 -type f \( -name "tests.sh" -o -name "tests*.py" \) | cut -d/ -f2 | sort -u
}
total_tests=$(get_sorted_test_names | wc -l)
ports_per_test=20
port_min=5001
port_max=$((32767 - (total_tests * ports_per_test)))
baseport=0
test_index=0
while getopts "p:t:-:" OPT; do
if [ "$OPT" = "-" ] && [ -n "$OPTARG" ]; then
OPT="${OPTARG%%=*}"
OPTARG="${OPTARG#$OPT}"
OPTARG="${OPTARG#=}"
fi
# shellcheck disable=SC2214
case "$OPT" in
p | port) baseport=$OPTARG ;;
t | test)
test_index=$(get_sorted_test_names | awk "/^${OPTARG}\$/ { print NR }")
if [ -z "${test_index}" ]; then
echo "Test '${OPTARG}' not found" >&2
exit 1
fi
;;
-) break ;;
*)
echo "invalid option" >&2
exit 1
;;
esac
done
port_pool_size=$((port_max - port_min))
if [ "${baseport}" -eq 0 ]; then
baseport="$((($(date +%s) / 3600 % port_pool_size) + port_min + (test_index * ports_per_test)))"
fi
echo "export PORT=$((baseport))"
echo "export TLSPORT=$((baseport + 1))"
echo "export HTTPPORT=$((baseport + 2))"
echo "export HTTPSPORT=$((baseport + 3))"
echo "export EXTRAPORT1=$((baseport + 4))"
echo "export EXTRAPORT2=$((baseport + 5))"
echo "export EXTRAPORT3=$((baseport + 6))"
echo "export EXTRAPORT4=$((baseport + 7))"
echo "export EXTRAPORT5=$((baseport + 8))"
echo "export EXTRAPORT6=$((baseport + 9))"
echo "export EXTRAPORT7=$((baseport + 10))"
echo "export EXTRAPORT8=$((baseport + 11))"
echo "export CONTROLPORT=$((baseport + 12))"
# Local Variables:
# sh-basic-offset: 4
# End: