Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Autoinstall latest driver for Intel 10/40 GbE network cards from official site under CentOS 7.
#!/bin/sh -e
# Autoinstall latest driver for Intel 10/40 GbE network cards from official site under CentOS 7
# Written by ilya.evseev@gmail.com
# Distributed as public domain
# Last updated on 09-March-2019
INSTALL_ME_SO='
yum install -y wget make gcc "$(rpm -qf --qf '%{NAME}' /boot/vmlinuz-$(uname -r))-devel" &&
cd /etc/kernel/postinst.d/ &&
wget https://gist.githubusercontent.com/ilyaevseev/defbb0846b18aa9500a650f9ac2dcff1/raw//00-autoinstall-i40e-driver.sh &&
chmod +x 00-autoinstall-i40e-driver.sh &&
ln -s 00-autoinstall-i40e-driver.sh 00-autoinstall-ixgbe-driver.sh
'
KERNEL_VERSION="${1:-$(uname -r)}"
DRIVER_VERSION="$2"
DRIVER_SITE="https://downloadcenter.intel.com"
case "$0" in
*-i40e-* ) DRIVER="i40e" ; DRIVER_PAGE="/download/24411/Intel-Network-Adapter-Driver-for-PCIe-Intel-40-Gigabit-Ethernet-Network-Connections-Under-Linux-" ;;
*-ixgbe-* ) DRIVER="ixgbe"; DRIVER_PAGE="/download/14687/Intel-Network-Adapter-Driver-for-PCIe-Intel-10-Gigabit-Ethernet-Network-Connections-Under-Linux-" ;;
* ) echo "Filename $0 should contain driver name: i40e or ixgbe"; exit 1;;
esac
Skip() { echo "Skip $0: $@"; exit 0; }
# Check hardware..
ip -oneline link list | awk -F ': ' '{ print "ethtool -i",$2 }' | sh - 2>/dev/null | grep -q "^driver: $DRIVER\$" || Skip "no hardware for $DRIVER"
# Check kernel-devel package..
rpm -qa | egrep -q "^kernel.*-devel-${KERNEL_VERSION}$" || Skip "kernel-devel not installed"
Detect() {
local result="$1"; shift;
local a="$(wget -qO- "$DRIVER_SITE/$DRIVER_PAGE" | gawk "$@")";
test -z "$a" && { echo "UPDATE i40e: Cannot fetch $result from $DRIVER_PAGE" 1>&2; exit 1; }
eval "$result=\"$a\""
}
DownloadDriver() {
test -s "$DESTPKG" && return
Detect DRIVER_URL 'match($0,/data-direct-path="(https:.+.tar.gz)">/,m) { print m[1]; exit }'
# Workaround 2.1.6 => 2.1.26 at here:
# https://downloadcenter.intel.com/download/27189/Intel-Network-Adapter-Driver-for-PCIe-40-Gigabit-Ethernet-Network-Connections-Under-Linux-
local fname="$(basename "$DRIVER_URL")"
if ! test "$fname" = "$DESTPKG"; then
echo "UPDATE i40e: FIX DRIVER VERSION FROM $DESTPKG TO $fname"
DESTPKG="${fname}"
DESTDIR="${fname%.tar.gz}"
fi
echo "UPDATE i40e: DOWNLOAD $DRIVER_URL"
wget -qN "$DRIVER_URL"
}
if test -n "$DRIVER_VERSION"
then Detect DRIVER_PAGE -v VER="$DRIVER_VERSION" 'match($0, /href="(\/download\/.+)">(.+)<\/a>/, m) && m[2] == VER { print m[1] }'
else Detect DRIVER_VERSION 'match($0, /meta name="DownloadVersion" content="(.+)"/, m) { print m[1]; exit }'
fi
echo "UPDATE i40e: KERNEL = $KERNEL_VERSION, DRIVER = $DRIVER_VERSION"
DESTPKG="i40e-$DRIVER_VERSION.tar.gz"
DESTDIR="i40e-$DRIVER_VERSION"
cd /usr/src
test -s "$DESTDIR/SUMS" || { DownloadDriver; tar xzf "$DESTPKG"; }
make -C "$DESTDIR/src" "BUILD_KERNEL=$KERNEL_VERSION" clean install
depmod "$KERNEL_VERSION"
lsinitrd -k "$KERNEL_VERSION" | grep -q '/i40e.ko$' && dracut -f --kver "$KERNEL_VERSION"
## END ##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment