Debian Codegraph @

scripts/sbin/drbl-nfs-conf

raw symbols SCIP
1 #!/bin/bash
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: change the setting of NFS client
5 #
6
7 # Load DRBL setting and functions
8 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
9
10 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
11
12 #
13 check_if_root
14
15 #
16 run_cmd="`basename $0`"
17
18 #
19 usage() {
20 echo "Set the NFS parameters for DRBL client."
21 echo "Usage: $run_cmd [-s|--size] SIZE [--rsize] SIZE [--wsize] SIZE [-p|--protocol] PROTOCOL [-v|--verbose]"
22 echo "-s, --size SIZE: set the NFS blocksize (both rszie & wsize) to be SIZE bytes."
23 echo "-g, --no-gen-ssi do NOT generate DRBL SSI template tarball."
24 echo "--rsize SIZE: set the NFS rsize blocksize to be SIZE bytes."
25 echo "--wsize SIZE: set the NFS wsize blocksize to be SIZE bytes."
26 echo "-p, --protocol PROTOCOL: set the NFS to use the PROTOCOL (tcp, udp or auto)."
27 echo "-v, --verbose print out verbose information."
28 }
29
30 if [ $# -le 0 ]; then
31 usage
32 exit 1
33 fi
34 #
35 while [ $# -gt 0 ]; do
36 case "$1" in
37 -s|--size)
38 shift;
39 rsize="$1"
40 wsize="$1"
41 shift;;
42 --rsize)
43 shift; rsize="$1"
44 shift;;
45 --wsize)
46 shift; wsize="$1"
47 shift;;
48 -p|--protocol)
49 shift; protocol="$1"
50 shift;;
51 -g|--no-gen-ssi)
52 gen_ssi="no"
53 shift;;
54 -v|--verbose)
55 shift; VERBOSE="on"
56 ;;
57 -*) echo "${0}: ${1}: invalid option" >&2
58 usage >& 2
59 exit 2 ;;
60 *) break ;;
61 esac
62 done
63
64
65 # check parameter
66 [ -n "`echo $rsize | grep [^0-9]`" ] && echo "rsize is \"$rsize\", but rsize must be numbers!!! Program terminated!" && exit 1
67 [ -n "`echo $wsize | grep [^0-9]`" ] && echo "wsize is \"$wsize\", but wsize must be numbers!!! Program terminated!" && exit 1
68 # The specified protocol is higher priority, it will overwrite the protocol gton from kernel config
69 if [ -n "$protocol" ]; then
70 case "$protocol" in
71 [uU][dD][pP])
72 protocol="udp"
73 ;;
74 [tT][cC][pP])
75 protocol="tcp"
76 ;;
77 "auto")
78 check_kernel_nfsd_tcp_config
79 rtv=$?
80 case "$rtv" in
81 0)
82 protocol="udp"
83 ;;
84 1)
85 protocol="tcp"
86 ;;
87 esac
88 ;;
89 *)
90 echo "PROTOCOL must be \"tcp\" or \"udp\" only"
91 exit 1
92 esac
93 fi
94
95 run_mknic_nbi="0"
96
97 # for rsize
98 if [ -n "$rsize" ]; then
99 echo "The rsize you set for DRBL client is: $rsize"
100 echo -n "Modifying the NFS rsize parameter of clients... "
101 perl_str="s/,rsize=[[:digit:]]*,/,rsize=$rsize,/"
102 # change the fstab of clients
103 for itab in $drblroot/*; do
104 [ -f $itab/etc/fstab ] && perl -pi -e "$perl_str" $itab/etc/fstab
105 done
106 # change the drbl init in common root
107 perl -pi -e "$perl_str" $drblroot/../node_root/sbin/init
108
109 # change the mkinitrd mount
110 perl -pi -e "$perl_str" /usr/lib/mkpxeinitrd-net/initrd-skel/sbin/udhcpc-post
111 echo "done!"
112 # set the flag to run mknic_nbi
113 run_mknic_nbi="1"
114 fi
115
116 # for wsize
117 if [ -n "$wsize" ]; then
118 echo "The wsize you set for DRBL client is: $wsize"
119
120 echo -n "Modifying the NFS wsize parameter of clients... "
121 perl_str="s/,wsize=[[:digit:]]*,/,wsize=$wsize,/"
122 # change the fstab of clients
123 for itab in $drblroot/*; do
124 [ -f $itab/etc/fstab ] && perl -pi -e "$perl_str" $itab/etc/fstab
125 done
126 # change the drbl init in common root
127 perl -pi -e "$perl_str" $drblroot/../node_root/sbin/init
128
129 # change the mkinitrd mount
130 perl -pi -e "$perl_str" /usr/lib/mkpxeinitrd-net/initrd-skel/sbin/udhcpc-post
131 echo "done!"
132 # set the flag to run mknic_nbi
133 run_mknic_nbi="1"
134 fi
135
136 # for protocol
137 if [ -n "$protocol" ]; then
138 echo "The NFS protocol you set for DRBL client is: $protocol"
139
140 echo -n "Modifying the NFS protocol parameter of clients... "
141 perl_str="s/,tcp,|,udp,/,$protocol,/"
142 # change the fstab of clients
143 for itab in $drblroot/*; do
144 [ -f $itab/etc/fstab ] && perl -pi -e "$perl_str" $itab/etc/fstab
145 done
146 # change the drbl init in common root
147 perl -pi -e "$perl_str" $drblroot/../node_root/sbin/init
148
149 # change the mkinitrd mount
150 perl -pi -e "$perl_str" /usr/lib/mkpxeinitrd-net/initrd-skel/sbin/udhcpc-post
151 echo "done!"
152 # set the flag to run mknic_nbi
153 run_mknic_nbi="1"
154 fi
155
156 # make the initrd-net effect if necessary
157 if [ "$run_mknic_nbi" -eq "1" ]; then
158 echo "-------------------------------------------------------"
159 echo "Creating the network boot kernel image for DRBL clients..."
160 mknic-nbi -a
161 fi
162 #
163 if [ "$gen_ssi" != "no" ]; then
164 echo "-------------------------------------------------------"
165 echo "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
166 drbl-gen-ssi-files
167 fi
168
169 echo "Please reboot the CLIENTS to make the new setting of NFS effect!"