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