Skip to content

Instantly share code, notes, and snippets.

@dotysan
Created December 12, 2024 22:58
Show Gist options
  • Save dotysan/495a3de27fc343a6685e69bb47f19b3e to your computer and use it in GitHub Desktop.
Save dotysan/495a3de27fc343a6685e69bb47f19b3e to your computer and use it in GitHub Desktop.
Standardized install of iperf
#! /usr/bin/env bash
#
# Standardized install of iperf.
#
set -o errexit
set -o nounset
set -o pipefail
PS4func() {
local lineno="$1"
local i f=''
local c="\033[0;36m" y="\033[0;33m" n="\033[0m"
local d=$((${#FUNCNAME[@]}-2))
if [[ $lineno == 1 ]]
then lineno=0
fi
for ((i=d; i>0; i--))
do printf -v f "%s%s()" "$f" "${FUNCNAME[i]}"
done
printf "$y%s:%04d$c%s$n " "${BASH_SOURCE[1]##*/}" "$lineno" "$f"
}
PS4='\r$(PS4func $LINENO)'
set -o xtrace
#
IPERF_VER=3.17.1
main() {
local where vers
where=$(which iperf3)
if [[ "$where" != "/usr/local/bin/iperf3" ]]
then do_install
fi
vers=$(iperf3 --version)
if ! grep -q "^iperf ${IPERF_VER//.\\.} " <<<"$vers"
then do_install
fi
if ! grep -q "^Optional features available: CPU affinity setting, IPv6 flow label, SCTP, TCP congestion algorithm setting, sendfile / zerocopy, socket pacing, authentication, bind to device, support IPv4 don't fragment, POSIX threads\$" <<<"$vers"
then do_install
fi
echo "You are running iperf $IPERF_VER no installation needed."
}
do_install() {
sudo apt purge iperf iperf3 libiperf0
mkdir --parents "$HOME/src"
cd "$HOME/src"
if [[ ! -d iperf ]]
then git clone [email protected]:esnet/iperf.git
fi
cd iperf
git checkout "tags/$IPERF_VER"
"$HOME/src/sh/lt.sh" ||:
if [[ ! -s /usr/include/netinet/sctp.h ]]
then sudo apt install libsctp-dev
fi
if [[ ! -s /usr/bin/checksctp ]]
then sudo apt install lksctp-tools
fi
if [[ ! -s /usr/include/openssl/ssl.h ]]
then sudo apt install libssl-dev
fi
./configure
make -j
sudo make install
sudo ldconfig
echo "You now have iperf $IPERF_VER installed."
iperf3 --version
exit 0
}
main
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment