Whamcloud - gitweb
file export-do_kern_mount.patch was initially added on branch b1_5.
[fs/lustre-release.git] / build / sles8-update_rcfile_setting.sh
1 # Update the variable $var in $rcfile: The function update_$VAR must
2 # exist. It is called with the old value of $var, and must return the
3 # new value.
4
5 update_rcfile_setting() {
6     local rcfile=$1 var=$2
7
8     # The characters $, `, ", and \ have special meaning inside double
9     # quoted shell variables. The characters " and \ have special meaning
10     # inside awk double-quoted variables.
11
12     local old=$(source "$rcfile" ;
13                 eval echo \$$var \
14                 | sed -e 's/\([$`"\\]\)/\\\1/g')
15     local new=$(eval update_$var "$old" \
16                 | sed -e 's/\([$`"\\]\)/\\\1/g' \
17                       -e 's/\(["\\]\)/\\\1/g')
18     local tmp=$(mktemp /tmp/${rcfile##/*}.XXXXXX)
19     
20     # This script breaks for multi-line varables -- I don't think
21     # we need to handle this special case.
22     awk '
23         function replace() {
24             if (!done)
25                 print "'"$var"'=\"'"$new"'\""
26             done=1
27         }
28         
29         /^'"$var"'=/    { replace() ; next }
30                         { print }
31     ' < $rcfile > $tmp &&
32     cat $tmp > $rcfile
33
34     rm -f $tmp
35 }