[Libguestfs] [PATCH V2] virt-sysprep:add ipconfig for preparation
Richard W.M. Jones
rjones at redhat.com
Fri Mar 9 15:48:12 UTC 2012
On Fri, Mar 09, 2012 at 02:50:17PM +0800, Wanlong Gao wrote:
> +#FIXME: This may not work OK for IPv6 ?
:-)
Does it work or not? Anyone??
> +if [ "$ipconfig" = "yes" ]; then
> + case "$type/$distro" in
> + linux/fedora|linux/rhel)
> + if [ -d $mnt/etc/sysconfig/network-scripts ]; then
> + if [ -z $ipconfig_param ]; then
Apparently you don't need to quote parameters in bash, but while this
is technically correct, I think it is safer to quote it. There are a
few other similar ones later in the code.
> + for (( i=1; i<8 ; i+=2 )); do
> + __device=$(echo "$ipconfig_param" | awk -v j=$i -F: '{print $j}')
> + if [ -z $__device ]; then
> + break
> + fi
> + __ipconfig=$(echo "$ipconfig_param" | awk -v j=$((i+1)) -F: '{print $j}')
> + __config_file=$(echo "$mnt/etc/sysconfig/network-scripts/ifcfg-$__device")
> + if [ -e $__config_file ]; then
> + __ip=$(echo "$__ipconfig" | awk -F, '{print $1}')
> + __mask=$(echo "$__ipconfig" | awk -F, '{print $2}')
> + __gw=$(echo "$__ipconfig" | awk -F, '{print $3}')
> + sed '/^IPADDR=/d;/^BOOTPROTO=/d;/^NETMASK=/d;/^GATEWAY=/d;/^DNS/d' \
> + < "$__config_file" > "$__config_file.new"
> + echo "IPADDR=$__ip" >> "$__config_file.new"
> + echo "BOOTPROTO=static" >> "$__config_file.new"
> + echo "NETMASK=$__mask" >> "$__config_file.new"
> + echo "GATEWAY=$__gw" >> "$__config_file.new"
> + mv -f "$__config_file.new" "$__config_file"
> + fi
> + done
> + fi
> + fi
I can't see any fault in this code. I wonder if there's an easier
way, but maybe not, this is shell script after all ...
Seems OK in general.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
More information about the Libguestfs
mailing list