Whamcloud - gitweb
A shell script to add lnet options line to modprobe.conf or modules.conf
authoryujian <yujian>
Thu, 15 Dec 2005 12:16:40 +0000 (12:16 +0000)
committeryujian <yujian>
Thu, 15 Dec 2005 12:16:40 +0000 (12:16 +0000)
lustre/utils/add_lnet_options.sh [new file with mode: 0755]

diff --git a/lustre/utils/add_lnet_options.sh b/lustre/utils/add_lnet_options.sh
new file mode 100755 (executable)
index 0000000..9f845ba
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/bash
+#
+# add_lnet_options.sh - add lnet options lines into modprobe.conf or modules.conf
+#
+#################################################################################
+
+# Check the kernel version
+KERNEL_VERSION=`uname -r`
+KERNEL_VERSION=${KERNEL_VERSION:0:3}
+
+if [ "${KERNEL_VERSION}" = "2.4" ]; then
+       MODULE_CONF=/etc/modules.conf
+else
+       MODULE_CONF=/etc/modprobe.conf
+fi
+
+read -r NETWORKS
+MODLINES_FILE=$"/tmp/modlines.txt"
+START_MARKER=$"# start lustre config"
+END_MARKER=$"# end lustre config"
+
+# Generate a temp file contains lnet options lines 
+generate_lnet_lines() {
+       local LNET_LINE TMP_LINE
+
+       TMP_LINE="${NETWORKS}"
+
+       echo ${START_MARKER} > ${MODLINES_FILE}
+       while true; do
+               LNET_LINE=${TMP_LINE%%\\n*}
+               echo ${LNET_LINE} >> ${MODLINES_FILE}
+
+               TMP_LINE=${TMP_LINE#*\\n}
+
+               if [ "${TMP_LINE}" == "${LNET_LINE}" ]; then
+                       break
+               fi
+       done
+       echo ${END_MARKER} >> ${MODLINES_FILE}
+
+       #echo "--------------${MODLINES_FILE}--------------"
+       #cat ${MODLINES_FILE}
+       #echo -e "------------------------------------------\n"
+
+       return 0
+}
+
+if ! generate_lnet_lines; then
+       exit 1  
+fi
+
+# Add lnet options lines to the module configuration file
+if [ -e ${MODULE_CONF} ]; then
+       # Delete the old options
+       sed -i "/${START_MARKER}/,/${END_MARKER}/d" ${MODULE_CONF}
+fi
+
+cat ${MODLINES_FILE} >> ${MODULE_CONF}
+rm -f ${MODLINES_FILE}
+exit 0