public
Last active

mlnx_en-1.5.9 install script

  • Download Gist
install.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.