Index: drbl-virt/sbin/drbl_PXE_PV-VM_deploy.sh
===================================================================
--- drbl-virt/sbin/drbl_PXE_PV-VM_deploy.sh	(revision 183)
+++ 	(revision )
@@ -1,63 +1,0 @@
-#!/bin/bash                                                                                                          
-# Program:
-#   Path DRBL evironment to support Xen/KVM
-# Author: 
-#   Jazz, Rock {jazz, rock}@nchc.org.tw
-# Version:
-#    1.0
-# History:                                                                                          
-#   2010/08/13  Rock    First release (1.0) 
- 
-# [Source]
-source /opt/drbl-virt/conf/drbl-virt.conf
-source $Work_Path/functions_drbl_virt
-source ./functions_drbl_virt
-# [Main]
-# = 0. Variables setup =
-# == Get DRBL eth ==
-eths=""
-declare -i eth_nu=""
-get_DRBL_eth
-
-if [ $eth_nu -gt "1" ]; then
-    echo ""
-    echo "DRBL environment has muiltpule netwrok card(NIC)."
-fi
-
-for eth in $eths
-do
-
-    # == Get Host IP range/number  ==
-    Host_first_IP=""
-    Host_last_IP=""
-    get_Host_IP_range
-
-    # == Get VM number, IP range & prefix name ==
-    declare -i VM_IP_range=""
-    declare -i Host_last_IP_4=""
-    declare -i VM_Host_totoal_nu=""
-    VM_first_IP=""
-    VM_last_IP=""
-    VM_prefix_name=""
-    get_VM_IP_range_and_prefix_name
-    create_VM_IP_table 
-
-    # == Generate MAC address  ==
-    # MAC address [00:16:3e:xx:xx:xx] is for Xen use
-    generate_Xen_MAC_address
-    
-
-
-done
-
-# = 1. Copy VM fs =
-# Kernel & initrd -> /home/domains
-
-
-# = 2. Add NFS config =
-
-# = 3. Add DHCP config =
-
-# = 4. Add hosts and cp it to all drbl client =
-
-# = 5. generate guest config file =
Index: drbl-virt/sbin/drbl_xen_patch.sh
===================================================================
--- drbl-virt/sbin/drbl_xen_patch.sh	(revision 183)
+++ drbl-virt/sbin/drbl_xen_patch.sh	(revision 184)
@@ -18,4 +18,5 @@
 # == Shutdown all drbl client ==
 echo "Please check all client are shutdown !!!"
+echo "you can use /opt/drbl/sbin/dcs to shutdown."
 read -p "Push 'Enter' to continue......"
 
@@ -33,7 +34,11 @@
 
 # == Modify PXE booting menu ==
+# if menu doesn't has drbl-virt, then add it
+cat /opt/drbl/sbin/generate-pxe-menu | grep drbl-virt
+if [  $? != 0 ]; then
 # backup generate-pxe-menu
 cp /tftpboot/nbi_img/pxelinux.cfg/default /tftpboot/nbi_img/pxelinux.cfg/default.drbl-virt_bak
 cp /opt/drbl/sbin/generate-pxe-menu /opt/drbl/sbin/generate-pxe-menu.drbl-virt_bak
+
 generate_PXE_menu="/opt/drbl/sbin/generate-pxe-menu"
 declare -i modify_line=$(cat -n $generate_PXE_menu | grep 'label drbl' | awk 'NR==1 {print $1}')
@@ -58,9 +63,11 @@
 modify_line=$modify_line+1
 sed -i "${modify_line}i\ " $generate_PXE_menu
-
+fi
 
 # = 2. Patch DRBL initrd to support bridge =
 # == Patch /usr/bin/mkpxeinitrd-net (1)Xen network scripts (2)command (3)modules ==
-# backup
+# backup mkpxeinitrd-net. if already has "drbl-virt add", dones't sed
+cat /usr/bin/mkpxeinitrd-net | grep "drbl-virt add"
+if [ $? != 0 ]; then
 cp /usr/bin/mkpxeinitrd-net /usr/bin/mkpxeinitrd-net.drbl-virt_bak
 # copy Xen network scripts
@@ -81,5 +88,5 @@
 sed -i "${modify_line}icp -a --parents kernel/drivers/xen/netback/netloop.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file
 
-# == Run Xen network-bridge in booting (/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init) ==
+# == Add start_xen_bridge.sh to run Xen network-bridge (/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init) ==
 cat <<EOF >/usr/lib/mkpxeinitrd-net/initrd-skel/bin/start_xen_bridge.sh
 #!/bin/bash
@@ -104,12 +111,18 @@
 bash /bin/network-bridge start netdev=\$NIC
 EOF
-# backup
-cp /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init.drbl-virt_bak 
-declare -i modify_line=$(cat -n /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "# clean the tag file" | awk '{print $1}')
-modify_file="/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init"
+fi
+# == Run start_xen_bridge.sh when booting  ==
+cat linuxrc-or-init | grep "bash /bin/start_xen_bridge.sh"
+if [ $? !=0 ]; then
+    # backup linuxrc-or-init
+    cp /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init.drbl-virt_bak 
+    declare -i modify_line=$(cat -n /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "# clean the tag file" | awk '{print $1}')
+    modify_file="/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init"
 
-sed -i "${modify_line}i# drbl-virt add" $modify_file
-modify_line=$modify_line+1
-sed -i "${modify_line}ibash /bin/start_xen_bridge.sh" $modify_file
+    sed -i "${modify_line}i# drbl-virt add" $modify_file
+    modify_line=$modify_line+1
+    sed -i "${modify_line}ibash /bin/start_xen_bridge.sh" $modify_file
+fi
+
 
 # = 3. enable xend xendomains daemon in DRBL Client =
Index: drbl-virt/sbin/drbl_xen_repush.sh
===================================================================
--- drbl-virt/sbin/drbl_xen_repush.sh	(revision 184)
+++ drbl-virt/sbin/drbl_xen_repush.sh	(revision 184)
@@ -0,0 +1,79 @@
+#!/bin/bash
+# Program:
+#   Path DRBL evironment to support Xen/KVM
+# Author: 
+#   Jazz, Rock {jazz, rock}@nchc.org.tw
+# Version:
+#    1.0
+# History:                                                                                          
+#   2010/07/20  Rock    First release (1.0) 
+
+# [Source]
+source /opt/drbl-virt/conf/drbl-virt.conf
+source $Work_Path/functions_drbl_virt
+
+# [Main]
+
+# = 0. Variables setup =
+# == Get DRBL eth ==
+eths=""
+declare -i eth_nu=""
+get_DRBL_eth                                                                                                                                                                           
+     
+if [ $eth_nu -gt "1" ]; then
+    echo ""
+    echo "DRBL environment has muiltpule netwrok card(NIC)."
+fi   
+     
+for eth in $eths
+do   
+     
+    # == Get Host IP range/number  ==
+    Host_first_IP=""
+    Host_last_IP=""
+    # get eth network
+    eth_address=$(/opt/drbl/bin/drbl-get-ipadd $eth)
+    eth_netmask=$(/opt/drbl/bin/drbl-get-netmask $eth)
+    eth_network=$(/opt/drbl/bin/drbl-get-network $eth_address $eth_netmask)
+    get_Host_IP_range
+     
+    # == Get VM number, IP range & prefix name ==
+    declare -i VM_IP_range=""
+    declare -i Host_last_IP_4=""
+    declare -i VM_Host_totoal_nu=""
+    VM_first_IP=""
+    VM_last_IP=""
+    VM_prefix_name=""
+    get_VM_IP_range_and_prefix_name
+    create_VM_IP_table
+     
+    # == Generate MAC address  ==
+    # MAC address [00:16:3e:xx:xx:xx] is for Xen use
+    generate_Xen_MAC_address
+     
+    # == Add VM IP to dhcpd.conf  ==
+    VM_IPs=$(cat /opt/drbl-virt/etc/IP_VM_$eth | awk '{print $1}')
+    VM_hosts=$(cat /opt/drbl-virt/etc/IP_VM_$eth | awk '{print $2}')
+    VM_MACs=$(cat /opt/drbl-virt/etc/macadr-VM-$eth.txt)
+    add_VM_dhcpd_conf
+     
+    # == Add VM IP to exports  ==
+    #add_VM_nfs_exportd
+     
+    # == Add VM IP to ypserv.securenets  ==
+    #add_VM_ypserv_securenets
+     
+     
+done 
+     
+# = 1. Copy VM fs =
+# Kernel & initrd -> /home/domains
+     
+     
+# = 2. Add NFS config =
+     
+# = 3. Add DHCP config =
+     
+# = 4. Add hosts and cp it to all drbl client =
+     
+# = 5. generate guest config file =     
Index: drbl-virt/sbin/functions_drbl_virt
===================================================================
--- drbl-virt/sbin/functions_drbl_virt	(revision 183)
+++ drbl-virt/sbin/functions_drbl_virt	(revision 184)
@@ -174,8 +174,5 @@
 fi
 
-# get eth network
-eth_address=$(/opt/drbl/bin/drbl-get-ipadd $eth)
-eth_netmask=$(/opt/drbl/bin/drbl-get-netmask $eth)
-eth_network=$(/opt/drbl/bin/drbl-get-network $eth_address $eth_netmask)
+# get eth network X.X.X
 eth_network_f3=$(echo $eth_network | cut -d "." -f 1-3)
 
@@ -214,5 +211,6 @@
     done
 
-    read -p "Input Prefix name for VM for $eth (ex. drblvm): " VM_prefix_name
+    #read -p "Input Prefix name for VM for $eth (ex. drblvm): " VM_prefix_name
+    VM_prefix_name=$(cat /etc/drbl/drblpush.conf  | grep hostname= | sed 's/hostname=//')
     read -p "Is it correct? (yes/no): " jude
 done
@@ -238,5 +236,5 @@
 VM_Host_totoal_nu=$((${Host_last_IP_4}-1+${VM_IP_range}))
 if [ -e /opt/drbl-virt/etc/IP_VM_$eth ]; then
-    mv /opt/drbl-virt/etc/IP_VM_$eth /opt/drbl-virt/etc/IP_VM_${eth}.$(date +%Y-%m-%d-%H-%M-%S).drbl-virt_bak
+    mv -f /opt/drbl-virt/etc/IP_VM_$eth /opt/drbl-virt/etc/IP_VM_${eth}.$(date +%Y-%m-%d-%H-%M-%S).drbl-virt_bak
 fi
 declare -i VM_IP_0=$VM_prefix_eth
@@ -275,5 +273,4 @@
             echo "${eth_network_f3}.${VM_IP_1} ${VM_prefix_name}${VM_IP_0}${VM_IP_1}" >> /opt/drbl-virt/etc/IP_VM_$eth
         fi
-
     done
 
@@ -297,5 +294,5 @@
 
 # backup
-mv /opt/drbl-virt/etc/macadr-VM-$eth.txt /opt/drbl-virt/etc/macadr-VM-$eth.txt.$(date +%Y-%m-%d-%H-%M-%S).drbl-virt_bak
+mv -f /opt/drbl-virt/etc/macadr-VM-$eth.txt /opt/drbl-virt/etc/macadr-VM-$eth.txt.$(date +%Y-%m-%d-%H-%M-%S).drbl-virt_bak
 
 # generate MAC
@@ -318,7 +315,20 @@
     fi
 done
-
-
-}
-
-
+}
+
+function add_VM_dhcpd_conf(){
+# backup dhcpd.conf
+if [ -e /etc/dhcp3/dhcpd.conf ]; then
+cp -f /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.drbl-virt_bak
+fi
+
+subnet_lines=$(cat -n /etc/dhcp3/dhcpd.conf | grep $eth_network | awk '{print $1}')
+host_lines=$(cat -n /etc/dhcp3/dhcpd.conf | grep 'host ' | grep '{' | awk '{print $1}')
+
+for subnet_line in $subnet_lines
+do
+    host_lines cat -n /etc/dhcp3/dhcpd.conf | sed -n "$subnet_line,\$p" | grep 'host .* {' | awk '{print $1}'
+
+done
+
+}
