Add the following text above the Development Menu Tasks
entry:
; ------------------------------------------------------
; Clone Menu Tasks
; ------------------------------------------------------
label:clone
; Set Session option based on %_itemparams% variable
Set:Clone_Session,"%_itemparams%"
; to make sure all machines are the same hardware - use the drivers image name as the session name
Set:clone_session_name,%drivers_image%
Label:clone_computername
; Check for an AssetTag we can use for the DMI_NAME
Set:DMI_NAME,""
If:Var,dmi_board_asset,ne,""
Set:DMI_NAME,"%dmi_board_asset%"
ElseIf:Var,dmi_chassis_asset,ne,""
Set:DMI_NAME,"%dmi_chassis_asset%"
End:
Set:COMPUTERNAME,""
; Read the Computername in from ZISD (if it exists)
Zisd:Get,NetBiosName,ZISD_COMPUTERNAME
If:Var,ZISD_COMPUTERNAME,ne,""
Set:COMPUTERNAME,%ZISD_COMPUTERNAME%
Else:
Set:COMPUTERNAME,"%DMI_NAME%"
End:
; Configure clone image name
; Take the drivers image name and replace drivers- with clone-
Set:drivers_image_length,Len("%drivers_image%")
Set:image_length,%drivers_image_length%
Set:image_length,Math("-", 7)
Set:clone_image_name,Right("%drivers_image%", %image_length%)
Set:clone_image_name,clone%clone_image_name%
; Launch a Form to display detected hardware
Form:Start,"clone_Info","Hardware Detected","_OkCancel^_Ok",Blue
Form:Item,"Item1",Label,"Manufacturer"
Form:Item,"Item2",EditBox,": %lookup_section%",ReadOnly
Form:Item,"Item3",Label,"Model"
Form:Item,"Item4",EditBox,": %lookup_value%",ReadOnly
Form:Item,"Item5",Label,"Hardware Image"
Form:Item,"Item6",EditBox,": %drivers_image%",ReadOnly
Form:Item,"Item7",Label,"Hardware Type"
Form:Item,"Item8",EditBox,": %machine_type%",ReadOnly
Form:Item,"clone1",Label,"Clone Session"
Form:Item,"clone2",EditBox,": %Clone_Session%",ReadOnly
Form:Item,"Item9",Label,"Computer Name :"
Form:Item,"Item10",EditBox,"%COMPUTERNAME%"
Form:Item,"Item11",Label,"Auto Restart after imaging:"
Form:Item,"Item12",Radiobuttons,"Yes","Yes,No"
Form:Display,"clone_Info"
If:Var,_Form,Eq,"_Cancel"
Menu:Return
End:
Set:clone_autorestart,%_clone_Info_item12%
Set:mcast_computer_name,%_clone_Info_item10%
Goto:clone_%Clone_Session%
Label:Clone_Master
; Check to see if we are making an image to the server or multicasting it out to clients
Form:Start,"Clone_Master_check","Check Clone Master type","_BackNextCancel^_Next",Blue
Form:Item,"Item1",Label,"Clone Master type"
Form:Item,"Item2",RadioButtons,"Multicast","Multicast, Server"
; Display form
Form:Display,"Clone_Master_check"
If:Var,_Form,eq,"_Cancel"
Menu:Return
End:
If:Var,_Form,eq,"_Back"
Goto:clone
End:
Set:master_type,%_Clone_Master_check_Item2%
label:Clone_Master_check
If:Var,master_type,eq,"Server"
; We need to make an image of the machine and store it on the ZENworks server.
; This will be stored under the content-repo/images/clone folder by default
; the image will be named based on the driver information detected.
; Launch a Form to detail image information
Form:Start,"clone_master_server","Image information","_OkCancel^_Ok",Blue
Form:Item,"Item1",Label,"Image Path :"
Form:Item,"Item2",EditBox,"clone",readonly
Form:Item,"Item3",Label,"Image Name :"
Form:Item,"Item4",EditBox,"%clone_image_name%",readonly
Form:Display,"clone_master_server"
If:Var,_Form,Eq,"_Cancel"
Menu:Return
End:
Set:clone_image_name,%_clone_master_server_item4%
File:Run,"img %imgmakecmd%clone/%clone_image_name%",verbose
File:Run,"cat imglogr >> %_ZimDir%zim.log",verbose
If:Var,_error,eq,"57"
; file exists on server.
Dialog:Ask,"Warning! Image Creation Failed","Image file already exists on server\n Retry with different name?","_YesNo^_No",RED
If:Var,_ask,eq,"_Yes"
Set:clone_image_name,%clone_image_name%-1
Goto:Clone_Master_check
End:
End:
If:Var,_error,eq,"29"
; file path is invalid.
Dialog:Ask,"Warning! Image Creation Failed","File path does not exist on server\n path is: content-repo/images/clone \n Please check that this path exists.\n\n Retry","_YesNo^_No",RED
If:Var,_ask,eq,"_Yes"
Goto:Clone_Master_check
End:
End:
Goto:clone_update_zisd
End:
; Master machine will be multicasted out to machines.
Form:Start,"Clone_Master","Multicast Master","_BackNextCancel^_Next",Blue
Form:Item,"Item1",Label,"Clients to wait for (i.e. 30)"
Form:Item,"Item2",EditBox,"30"
Form:Item,"Item3",Label,"Time to wait for Clients to connect (i.e. 30min)"
Form:Item,"Item4",EditBox,"30"
; Display form
Form:Display,"Clone_Master"
If:Var,_Form,eq,"_Cancel"
Menu:Return
End:
If:Var,_Form,eq,"_Back"
Goto:clone
End:
Set:clone_master_clients,%_Clone_Master_Item2%
Set:clone_master_time,%_Clone_Master_Item4%
; Now run the Multicast Master clone session
File:Run,"img -session %clone_session_name% -master -clients=%clone_master_clients% -timeout=%clone_master_time%",verbose
File:Run,"cat imglogr >> /zimbin/zim.log",verbose
goto:clone_update_zisd
label:Clone_Client
Dialog:Ask,"", "Warning! All hard disk data on this machine will be erased.\n \nContinue?","_YesNo^_Yes",red
If:Var,_ask,eq,"_No"
Menu:Return
End:
; Session is a multicast client
File:Run,"img -session %clone_session_name% -client",verbose
File:Run,"cat imglogr >> /zimbin/zim.log",verbose
Goto:clone_update_zisd
Label:clone_server
If:Var,Clone_Session,eq,"Server"
; Session is a unicast restore from the ZENworks server
File:Run,"img %imgrestorecmd%clone/%clone_image_name%",verbose
File:Run,"cat imglogr >> /zimbin/zim.log",verbose
End:
Label:clone_update_zisd
; Update the information in ZISD
Zisd:Put,NetBiosName,%mcast_computer_name%
; Update VendorDataENGL
Set:VendorDataENGLSTRING,PutKeyPairStringValue("%VendorDataENGLSTRING%","Machine_Type","%machine_type%")
ZISD:Put,VendorDataENGL,"%VendorDataENGLSTRING%"
Set:zisd_update_count,"1"
Label:clone_update_zisd
ZISD:Write
; Trap ZISD:Write errors
If:Var,_ERROR,ne,"0"
If:Var,zisd_update_count,lt,"3"
Set:zisd_update_count,math(+, 1)
File:Run,"dd if=/dev/zero of=/dev/%HDTYPE% bs=512 seek=5 count=3",silent
goto:clone_update_zisd
Else:
Dialog:Ask,"Error!","An error occurred writing information to ZISD!","_Ok",red
End:
End:
If:Var,clone_autorestart,eq,"Yes"
Goto:reboot
End:
Menu:Return