Skip to content

Instantly share code, notes, and snippets.

@igable
Created October 17, 2012 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igable/3908289 to your computer and use it in GitHub Desktop.
Save igable/3908289 to your computer and use it in GitHub Desktop.
mlnx_en-1.5.9 install script
#!/bin/bash
# install.sh - installation script for mlnx_en driver
# Initial sanity checks
if [ $UID -ne 0 ]; then
echo Must be root to run this script.
exit 1
fi
# Initial value
batch="no"
with_sysctl="1"
with_memtrack="0"
disable_kmp=0
err=0
usage()
{
cat << EOF
Usage: `basename $0` [--help]: Prints this message
[--batch]: Remove all installed components without promt
[--disable-kmp]: Disable kernel module package (KMP) support
EOF
}
###############################################################################
# Parsing command line #
###############################################################################
while [ ! -z "$1" ]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-b|--batch)
batch="yes"
;;
--without-sysctl)
with_sysctl="0"
;;
--disable-kmp)
disable_kmp=1
;;
--with-memtrack)
with_memtrack="1"
;;
*)
echo "Bad input parameter: $1"
usage
exit 1
;;
esac
shift
done
name=`basename $0`
cd `dirname $0`
package_dir=`pwd`
LOGFILE=/tmp/install-mlx4_en.log.$$
### Local functions
incr_err() {
let err=$err+1
}
ex() {
echo "EXEC: $@" >> $LOGFILE
eval $@ >> $LOGFILE 2>&1
if [ "$?" != "0" ]; then
echo "$@ FAILED"
echo "Please review $LOGFILE"
exit 1
fi
}
check_input() {
if [ "x$1" == "xy" ] \
|| [ "x$1" == "xyes" ] \
|| [ "x$1" == "xY" ] \
|| [ "x$1" == "xYES" ] \
|| [ "x$1" == "x" ] ; then
return 1
else
return 0
fi
}
check_prev_install() {
# Uninstall ofed
INFO=/etc/infiniband/info
if [ -x ${INFO} ]; then
info_prefix=$(${INFO} | grep -w prefix | cut -d '=' -f 2)
if [ -x ${info_prefix}/sbin/ofed_uninstall.sh ]; then
if [ "$batch" == "no" ]; then
echo -n "Remove currently installed ofed components (${info_prefix}/sbin/ofed_uninstall.sh) (y/n) [y] ? "
read force
else
force="yes"
fi
check_input $force
RC=$?
if [ $RC == 1 ]; then
echo "Cleaning an old distribution at ${info_prefix}"
echo "Running: yes | ${info_prefix}/uninstall.sh" >> $LOGFILE
yes | ${info_prefix}/sbin/ofed_uninstall.sh --unload-modules --force > /dev/null 2>&1
if [ $? -ne 0 ]; then
yes | ${info_prefix}/sbin/ofed_uninstall.sh > /dev/null 2>&1
fi
if ( ls ${info_prefix}/uninstall*.sh > /dev/null 2>&1 ); then
yes | ${info_prefix}/uninstall*.sh > /dev/null 2>&1
fi
else
echo "Cannot continue without removing ofed first."
exit 1
fi
fi
fi
# Uninstall ofed rpm
if (rpm -q ofed-kmp-default > /dev/null); then
if [ "$batch" == "no" ]; then
echo "Remove currently OFED RPM?"
echo -n "This operation is ireversable (y/n) [y] ? "
read force
else
force="yes"
fi
check_input $force
RC=$?
if [ $RC == 1 ]; then
echo "Uninstalling OFED rpm"
echo "Removing OFED" >> $LOGFILE 2>&1
rpm -e ofed-kmp-default > /dev/null 2>&1
else
echo "Cannot continue without uninstalling OFED first."
exit 1
fi
fi
# Uninstall mtnic driver
if [ -d /lib/modules/${KER_UNAME_R}/kernel/drivers/net/mtnic ]; then
echo Removing mtnic driver ...
rmmod mtnic > /dev/null 2>&1
rm -rf /lib/modules/${KER_UNAME_R}/kernel/drivers/net/mtnic
fi
# Uninstall mlnx_en
if [ -d /tmp/mlnx_en ] ; then
if [ "$batch" == "no" ]; then
echo -n "Remove currently installed mlnx_en (y/n) [y] ? "
read force
else
force="yes"
fi
check_input $force
RC=$?
if [ $RC == 1 ]; then
echo "Cleaning an old distribution at /tmp/mlnx_en"
echo "Removing $src_path" >> $LOGFILE 2>&1
/sbin/mlnx_en_uninstall.sh >> $LOGFILE 2>&1
/bin/rm -rf $src_path > /dev/null 2>&1
/bin/rm -rf $include_path > /dev_null 2>&1
else
echo "Cannot continue without removing $target_path first."
exit 1
fi
fi
if (rpm -q mlnx_en > /dev/null || rpm -q mlnx-en-devel > /dev/null || rpm -q mlnx-ofc > /dev/null); then
if [ "$batch" == "no" ]; then
echo -n "Remove currently installed mlnx_en (y/n) [y] ? "
read force
else
force="yes"
fi
check_input $force
RC=$?
if [ $RC == 1 ]; then
echo "Removing previous installation"
cp mlnx_en_uninstall.sh /sbin/
/sbin/mlnx_en_uninstall.sh
else
echo "Cannot continue without removing previous installation."
exit 1
fi
fi
if (rpm -qa | grep -q "mlnx-en"); then
if [ "$batch" == "no" ]; then
echo -n "Remove currently installed mlnx-en package (y/n) [y] ? "
read force
else
force="yes"
fi
check_input $force
RC=$?
if [ $RC == 1 ]; then
echo "Removing mlnx-en package"
rpm -e `rpm -qa | grep "mlnx-en"` > /dev/null 2>&1
else
echo "Cannot continue without removing mlnx-en package."
exit 1
fi
fi
}
is_installed()
{
/bin/rpm -q $1 > /dev/null 2>&1
}
#Gives a warning if Network Manager is set
check_network_manager() {
local R="\[\033[0;31m\]" # red
local manager=""
if [ -f "/etc/sysconfig/network/config" ]; then
manager=`cat /etc/sysconfig/network/config | grep "^NETWORKMANAGER=yes"`
if [ "$manager" != "" ]; then
echo
echo "WARNING: Please set NETWORKMANAGER=no in the /etc/sysconfig/network/config"
echo
fi
fi
}
# Check that a previous version is loaded
check_loaded_modules() {
if ( `/sbin/lsmod | grep mlx4 > /dev/null 2>&1`); then
if [ "$batch" == "no" ]; then
echo; echo " In order for newly installed mlx4 modules to load, "
echo " previous modules must first be unloaded."
echo -n " Do you wish to unload now? (y/n) [y] "
read force
else
force="yes"
fi
check_input $force
RC=$?
if [ $RC == 1 ]; then
echo "Unloading mlx4 modules"
if [ "$with_memtrack" == "1" ]; then
/sbin/rmmod memtrack > /dev/null 2>&1
fi
/sbin/rmmod mlx4_fc > /dev/null 2>&1
/sbin/rmmod mlx4_en > /dev/null 2>&1
/sbin/rmmod mlx4_ib > /dev/null 2>&1
/sbin/rmmod mlx4_core > /dev/null 2>&1
else
echo "WARNING: Loading the new installed modules could cause symbol confilcts"
echo " Please unload all prevoius versions of mlx4 modules"
echo
fi
fi
}
set_ifcfg() {
local conf=$1
local dev=$2
local hwaddr=$3
cat << EOF > $conf
# Mellanox Technologies [ConnectX EN 10GigE]
DEVICE=$dev
ONBOOT=yes
BOOTPROTO=none
HWADDR=$hwaddr
EOF
}
TOPDIR=/tmp/MLNX_EN
ARCH=`rpm --eval %{_target_cpu}`
KER_UNAME_R=`uname -r`
KER_PATH=/lib/modules/${KER_UNAME_R}/build
if [ ! -d "${KER_PATH}/" ]; then
echo
echo "ERROR: No kernel sources/headers found for $KER_UNAME_R kernel."
echo "Cannot continue..."
exit 1
fi
cd ${package_dir}
echo "Installing mlnx_en for Linux"
echo "Starting installation at `date`..." | tee -a $LOGFILE
# Clean old source code
check_prev_install
# Add th uninstall script
cp mlnx_en_uninstall.sh /sbin/
# Create installation dir
if [ -d $TOPDIR ]; then
ex /bin/rm -rf $TOPDIR
fi
ex /bin/mkdir $TOPDIR
ex /bin/mkdir ${TOPDIR}/BUILD
ex /bin/mkdir ${TOPDIR}/SRPMS
ex /bin/mkdir ${TOPDIR}/RPMS
ex /bin/mkdir ${TOPDIR}/SOURCES
case "$(rpm -qf /etc/issue)" in
openSUSE-release-11.1*)
distro=openSUSE11sp1
dist_rpm=openSUSE11sp1
;;
openSUSE-release-12.1*)
distro=openSUSE12sp1
dist_rpm=openSUSE12sp1
;;
sles-release-11.1*)
distro=sles11sp1
dist_rpm=sles11sp1
;;
sles-release-11.2*)
distro=sles11sp2
dist_rpm=sles11sp2
;;
sles-release-10-15.45.8)
distro=sles10sp3
dist_rpm=sles10sp3
;;
sles-release-10-15.57.1)
distro=sles10sp4
dist_rpm=sles10sp4
;;
sles-release-11-72.13)
distro=sles11
dist_rpm=sles11
;;
redhat-release-server-6Server-6.0*|centos-release-6-0*|sl-release-6.0*)
distro=rhel6.0
dist_rpm=rhel6u0
;;
redhat-release-server-6Server-6.1*|centos-release-6-1*|sl-release-6.1*)
distro=rhel6.1
dist_rpm=rhel6u1
;;
redhat-release-server-6Server-6.2*|centos-release-6-2*|sl-release-6.2*)
distro=rhel6.2
dist_rpm=rhel6u2
;;
redhat-release-server-6Server-6.3*|centos-release-6-3*|sl-release-6.3*)
distro=rhel6.3
dist_rpm=rhel6u3
;;
redhat-release-5Server-5.8*|centos-release-5-8*)
distro=rhel5.8
dist_rpm=rhel5u8
;;
redhat-release-5Server-5.7*|centos-release-5-7*)
distro=rhel5.7
dist_rpm=rhel5u7
;;
redhat-release-5Server-5.6*|centos-release-5-6*)
distro=rhel5.6
dist_rpm=rhel5u6
;;
redhat-release-5Server-5.5*|centos-release-5-5*)
distro=rhel5.5
dist_rpm=rhel5u5
;;
redhat-release-5Server-5.4*|centos-release-5-4*)
distro=rhel5.4
dist_rpm=rhel5u4
;;
redhat-release-5Server-5.3*|centos-release-5-3*)
distro=rhel5.3
dist_rpm=rhel5u3
;;
redhat-release-5Server-5.2*|centos-release-5-2*)
distro=rhel5.2
dist_rpm=rhel5u2
;;
oraclelinux-release-6.*-1.0.2)
distro=oel6.1
dist_rpm=oel6u1
;;
oraclelinux-release-6.*-2.0.2)
distro=oel6.2
dist_rpm=oel6u2
;;
*)
distro=unsupported
dist_rpm=unsupported
;;
esac
build_requires_common="gcc make patch"
build_requires_redhat="$build_requires_common redhat-rpm-config"
build_requires_suse="$build_requires_common kernel-syms"
missing_rpms=""
echo "Verifying dependencies"
case "$distro" in
rhel*)
for package in $build_requires_redhat; do
if ! is_installed "$package"; then
missing_rpms="$missing_rpms $package"
fi
done
;;
sles*)
for package in $build_requires_suse; do
if ! is_installed "$package"; then
missing_rpms="$missing_rpms $package"
fi
done
;;
esac
if [ ! -z "$missing_rpms" ]; then
echo "mlnx_en requires the following RPM(s) to be installed: $missing_rpms"
exit 1
fi
echo "Building mlnx_en binary RPMs"
target_cpu=`rpm --eval %_target_cpu`
case "$dist_rpm" in
rhel5*)
if [ "$target_cpu" == "i386" ]; then
target_cpu=i686
fi
;;
esac
kmp=1
if ! ( /bin/rpm -qf /lib/modules/$KER_UNAME_R/build/ > /dev/null 2>&1 ); then
kmp=0
fi
if [ $kmp -eq 1 ]; then
case $distro in
rhel5.2 | oel*)
kmp=0
;;
sles*)
if [ "$ARCH" == "ppc64" ]; then
kmp=0
fi
;;
esac
case $KER_UNAME_R in
*fbk*)
kmp=0
;;
esac
fi
if [ $disable_kmp -eq 1 ]; then
kmp=0
fi
cmd="rpmbuild --rebuild \
--define '_dist .${dist_rpm}' --define '_target_cpu $target_cpu' \
--define '_topdir $TOPDIR' --define 'sysctl_update $with_sysctl' --define 'MEMTRACK $with_memtrack'"
if [ $kmp -eq 1 ]; then
SRPM=`ls -1 ${package_dir}/SRPMS/*mlnx-en*`
else
SRPM=`ls -1 ${package_dir}/SRPMS/*mlnx_en*`
cmd="$cmd --define '_release ${KER_UNAME_R//-/_}'"
fi
case $distro in
rhel6.3)
cmd="$cmd --define '__find_provides %{nil}'"
;;
esac
cmd="$cmd $SRPM"
ex $cmd
echo "Installing RPMs"
if ( grep "Ubuntu" /etc/issue > /dev/null 2>&1); then
ex "rpm -ivh --force-debian --nodeps ${TOPDIR}/RPMS/${target_cpu}/*mlnx*"
else
ex "rpm -ivh --nodeps ${TOPDIR}/RPMS/${target_cpu}/*mlnx*"
fi
/sbin/depmod
mkdir -p $package_dir/RPMS/$dist_rpm/$target_cpu/ > /dev/null 2>&1
cp -a ${TOPDIR}/RPMS/${target_cpu}/*mlnx* $package_dir/RPMS/$dist_rpm/$target_cpu/ > /dev/null 2>&1
# Install mstflint
if (rpm -q zlib-devel > /dev/null); then
echo "Installing mstflint"
rpm -e mstflint > /dev/null 2>&1
rpm -e mstflint-debuginfo > /dev/null 2>&1
cmd="rpmbuild --rebuild --define '_topdir $TOPDIR' ${package_dir}/SRPMS/mstflint*"
ex $cmd
ex "rpm -ivh ${TOPDIR}/RPMS/${ARCH}/mstflint*"
else
echo "no zlib on the machine, skipping mstflint installation"
fi
cp -a ${TOPDIR}/RPMS/${ARCH}/mstflint* $package_dir/RPMS/$dist_rpm/$target_cpu/ > /dev/null 2>&1
# Check Network Manager
check_network_manager
# Check that a previous version is loaded
check_loaded_modules
# W/A for mlnx_en devices configuration on RedHat5*
if ( grep "Red Hat Enterprise Linux Server release 5" /etc/issue > /dev/null 2>&1 || grep "CentOS release 5" /etc/issue > /dev/null 2>&1); then
if ( `/sbin/lsmod | grep mlx4 > /dev/null 2>&1`); then
unload=0
else
ex /sbin/modprobe mlx4_en
unload=1
fi
sleep 1
for dev_t in /sys/class/net/eth*
do
dev=${dev_t##*/}
vendor=`cat /sys/class/net/${dev}/device/vendor 2> /dev/null`
if [ "$vendor" == "0x15b3" ]; then
hwaddr=`cat /sys/class/net/${dev}/address`
conf=/etc/sysconfig/network-scripts/ifcfg-$dev
if [ ! -f $conf ]; then
set_ifcfg $conf $dev $hwaddr
else
if ! ( grep $hwaddr $conf > /dev/null 2>&1 ); then
# The existing configuration used by another interface
# Preserve the existing one and create the new configuration
mv $conf ${conf}.bak
set_ifcfg $conf $dev $hwaddr
fi
fi
fi
done
if [ "$unload" == "1" ]; then
ex /sbin/modprobe -r mlx4_en
fi
fi
if [ $err -eq 0 ]; then
echo "Installation finished successfully."
/bin/rm $LOGFILE
/bin/rm -rf $TOPDIR
else
echo "Installation finished with errors."
echo "See $LOGFILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment