Whamcloud - gitweb
LU-1187 tests: Fixes in test-framework for DNE
[fs/lustre-release.git] / lustre / scripts / lc_modprobe.in
1 #!/bin/bash
2 #
3 # lc_modprobe - add lustre module options into modprobe.conf or 
4 #               modules.conf
5 #
6 #################################################################################
7
8 # Get the library of functions
9 . @scriptlibdir@/lc_common
10
11 # Check the kernel version
12 KERNEL_VERSION=`uname -r`
13 KERNEL_VERSION=${KERNEL_VERSION:0:3}
14
15 if [ "${KERNEL_VERSION}" = "2.4" ]; then
16         MODULE_CONF=/etc/modules.conf
17 else
18         MODULE_CONF=/etc/modprobe.conf
19 fi
20
21 read -r NETWORKS
22 MODLINES_FILE=/tmp/modlines$$.txt
23 START_MARKER=$"# start lustre config"
24 END_MARKER=$"# end lustre config"
25
26 # Generate a temp file contains lnet options lines 
27 generate_lnet_lines() {
28         local LNET_LINE TMP_LINE
29
30         TMP_LINE="${NETWORKS}"
31
32         echo ${START_MARKER} > ${MODLINES_FILE}
33         echo "# Lustre module options added automatically by `basename $0`" >> ${MODLINES_FILE}
34         while true; do
35                 LNET_LINE=${TMP_LINE%%\\n*}
36                 echo ${LNET_LINE} >> ${MODLINES_FILE}
37
38                 TMP_LINE=${TMP_LINE#*\\n}
39
40                 if [ "${TMP_LINE}" == "${LNET_LINE}" ]; then
41                         break
42                 fi
43         done
44         echo ${END_MARKER} >> ${MODLINES_FILE}
45
46         #echo "--------------${MODLINES_FILE}--------------"
47         #cat ${MODLINES_FILE}
48         #echo -e "------------------------------------------\n"
49
50         return 0
51 }
52
53 if ! generate_lnet_lines; then
54         exit 1  
55 fi
56
57 MODULE_CONF=$(fcanon ${MODULE_CONF})
58 # Add lnet options lines to the module configuration file
59 if [ -e ${MODULE_CONF} ]; then
60         # Delete the old options
61         sed -i "/${START_MARKER}/,/${END_MARKER}/d" ${MODULE_CONF}
62 fi
63
64 cat ${MODLINES_FILE} >> ${MODULE_CONF}
65 rm -f ${MODLINES_FILE}
66 exit 0