I am now writing a small bash script that updates an Intel NIC driver to the latest version from the official website. Is there any way to improve\simplify the script? I want to avoid a lot of "if...else" stuff. Helpful tips will be appreciated!
#! /bin/bash
DRV_PKG_NAME="e1000e-3.0.4.tar.gz"
DRV_PKG_URL="http://downloadmirror.intel.com/15817/eng/e1000e-3.0.4.tar.gz"
# Downloading driver and extracting it to current directory
echo "Downloading and extracting driver package..."
if wget -q ${DRV_PKG_URL} && tar zxvf ${DRV_PKG_NAME} >/dev/null ; then
echo "Done!"
else
exit 1
fi
# Installing required build dependencies if necessary
echo "Installing build dependencies..."
if apt-get install -y build-essential linux-headers-$(uname -r) >/dev/null ; then
echo "Done!"
else
exit 1
fi
# Going into the driver source directory
cd e1000e-3.0.4/src/
# Building driver and updating initramfs
echo "Building module and updating initramfs..."
if { make install && update-initramfs -k all -u; } >/dev/null ; then
echo "Done!"
else
exit 1
fi
echo "Purging unnecessary build dependencies..."
if apt-get -y purge build-essential >/dev/null ; then
echo "Done!"
else
exit 1
fi
# Restarting iface
echo "Restarting iface!"
{ ifdown eth0 && ifup eth0; } &>/dev/null
# Checking installed driver version
if [[ $(modinfo -F version e1000e) == "3.0.4-NAPI" ]] ; then
echo "Driver succesfully installed!"
exit 0
else
echo "Something Wrong...Try to re-install!"
exit 1
fi