working on setup: inital VM setup
authorOliver Maurhart <oliver.maurhart@ait.ac.at>
Mon, 17 Feb 2014 15:19:32 +0100
changeset 62eab1e343a004
parent 59 0b194a55eb68
child 70 e1db93adbebf
working on setup: inital VM setup
OpenSecurity/install/initial_vm.bat
OpenSecurity/install/vbox_lookup.vbs
     1.1 --- a/OpenSecurity/install/initial_vm.bat	Tue Feb 04 13:44:21 2014 +0100
     1.2 +++ b/OpenSecurity/install/initial_vm.bat	Mon Feb 17 15:19:32 2014 +0100
     1.3 @@ -1,58 +1,104 @@
     1.4  @echo off
     1.5  
     1.6 -rem ensure environment is ready
     1.7 +
     1.8 +
     1.9 +cd %0%\..
    1.10 +
    1.11 +rem ----------
    1.12 +----------
    1.13 +----------
    1.14 +----------
    1.15 +----------
    1.16 +----------
    1.17 +
    1.18 +rem install initial OpenSecuity VM image
    1.19 +rem
    1.20 +rem ----------
    1.21 +----------
    1.22 +----------
    1.23 +----------
    1.24 +----------
    1.25 +----------
    1.26 +
    1.27 +
    1.28 +SET OVA_TEMPLATE_URL="http://service.x-net.at/opensecurity/OsecVM_shrinked_29.01.2014.ova"
    1.29 +
    1.30 +:ENSURE_VBOX_READY
    1.31 +rem ensure environment is ready
    1.32 +
    1.33  
    1.34  rem This gets up VirtualBox VBoxSVC.exe COM Server right
    1.35 +
    1.36  rem and thus helps us not to run in any timing problems
    1.37 -rem due to a lazy VBox COM Server ... o.O
    1.38 -VBoxManage list vms > %TEMP%\VMS.txt
    1.39 -del %TEMP%\VMS.txt
    1.40 +
    1.41 +rem due to a lazy VBox COM Server ... o.O
    1.42 +rem
    1.43 +rem 1. locate the VBoxManage.exe
    1.44 +rem 2. check version (ability to call)
    1.45 +rem 3. enumerate vms (ensure VBoxSVC.exe feels good)
    1.46 +
    1.47 
    1.48 +CSCRIPT //NoLogo vbox_lookup.vbs >%TEMP%\vbox_lookup
    1.49 +SET /P VBM_DIR=<%TEMP%\vbox_lookup
    1.50 +SET VBM="%VBM_DIR%VBoxManage.exe"
    1.51 +IF NOT EXIST %VBM% GOTO VBM_MISSING
    1.52 +%VBM% -version >%TEMP%\vbox_version
    1.53 +IF NOT ERRORLEVEL 0 GOTO VBM_ERROR
    1.54 +%VBM% list vms > %TEMP%\VMS.txt
    1.55  
    1.56 -rem Now, VBox should feel good within the Windows OS space
    1.57 -rem switch into the User's VBox setup folders
    1.58 -C:
    1.59 -cd "C:\Users\%USERNAME%
    1.60 -mkdir "VirtualBox VMs"
    1.61 -cd "VirtualBox VMs"
    1.62 +del %TEMP%\VMS.txt
    1.63 +
    1.64 
    1.65 +:PREPARE_VBOX_FOLDER
    1.66 
    1.67 +rem Now, VBox should feel good within the Windows OS space
    1.68  
    1.69 -rem get recent initial VM and create disk image
    1.70 +rem switch into the User's VBox setup folders 
    1.71 +
    1.72 +rem
    1.73 +rem 1. create Virtual box folder (if not already existing)
    1.74 +rem 2. download OVA template
    1.75 +rem 3. import OVS template in VBox
    1.76 +
    1.77 +SET VBP=%HOMEDRIVE%%HOMEPATH%\VirtualBox VMs
    1.78 +IF NOT EXIST "%VBP%" MKDIR "%VBP%"
    1.79 +
    1.80 +%HOMEDRIVE%
    1.81 +cd "%VBP%"
    1.82 +
    1.83 +
    1.84 +GOTO :UPDATE_TEMPLATE
    1.85 +
    1.86 +:DOWNLOAD
    1.87  echo "download initial OpenSecurity VM"
    1.88 -rem wget http://service.x-net.at/opensecurity/OsecVM_initialized.ova
    1.89 -
    1.90 -rem I've already downloaded ... this is for convenience --> delete this line
    1.91 -rem This is just for testing. Enbale the real "wget http://service...." line above
    1.92 -rem to get the real VM image from X-Net
    1.93 -copy C:\Users\dyle\Documents\OpenSecurity\setup\OsecVM_initialized.ova .
    1.94 -
    1.95 -rem import the VM
    1.96 -VBoxManage.exe import OsecVM_initialized.ova --vsys 0 --vmname SecurityDVM --unit 12 --disk SecurityDVM\SecurityDVM.vmdk
    1.97 -
    1.98 -rem launch the SecurityVM the first time to let the user do initial updates
    1.99 -VBoxManage.exe startvm SecurityDVM
   1.100 -
   1.101 -echo # Start VirtualBox and update the machine	
   1.102 -echo #                                         
   1.103 -echo # login with                              
   1.104 -echo #   user: root                            
   1.105 -echo #   pass: osecvm                          
   1.106 -echo #                                         
   1.107 -echo # issue these commands as root            
   1.108 -echo #                                         
   1.109 -echo #       # apt-get update                  
   1.110 -echo #       # apt-get upgrade                 
   1.111 -echo #       # apt-get dist-upgrade            
   1.112 -echo #                                         
   1.113 -echo # then shutdown the machine with          
   1.114 -echo #                                         
   1.115 -echo #       # shutdown -h now                 
   1.116 -echo #                                         
   1.117 -echo # press a key when done to proceed        
   1.118 -pause
   1.119 -
   1.120 -rem Turn the VM disk image immutable and attach it
   1.121 -echo sealing disk image ...
   1.122 -VBoxManage.exe storageattach SecurityDVM --storagectl SATA --port 0 --medium none
   1.123 -VBoxManage.exe modifyhd SecurityDVM\SecurityDVM.vmdk --type immutable
   1.124 -VBoxManage.exe storageattach SecurityDVM --storagectl SATA --port 0 --device 0 --type hdd --mtype normal --medium SecurityDVM\SecurityDVM.vmdk
   1.125 -echo done. OpenSecurity is ready to serve
   1.126 -
   1.127 +
   1.128 +SET WGET="%0%\..\..\cygwin64\bin\wget.exe"
   1.129 +"%WGET%" %OVA_TEMPLATE_URL%
   1.130 +
   1.131 IF NOT ERRORLEVEL 0 GOTO OVA_DOWNLOAD_ERROR
   1.132 +RENAME OsecVM_shrinked_29.01.2014.ova OsecVM.ova
   1.133 +
   1.134 +:IMPORT
   1.135 +%VBM% import OsecVM.ova --vsys 0 --vmname SecurityDVM --unit 12 --disk SecurityDVM\SecurityDVM.vmdk
   1.136 +IF NOT ERRORLEVEL 0 GOTO VBM_IMPORT_ERROR
   1.137 +
   1.138 +:UPDATE_TEMPLATE
   1.139 +rem we have imported the Template
   1.140 +rem we need to update the template at first run
   1.141 +
   1.142 +
   1.143 +GOTO END
   1.144 +
   1.145 +:OVA_DOWNLOAD_ERROR
   1.146 +echo "Failed to download OVA initial image."
   1.147 +GOTO END
   1.148 +
   1.149 +:VBM_ERROR
   1.150 +echo "Error calling VBoxManage.exe"
   1.151 +GOTO END
   1.152 +
   1.153 +:VBM_MISSING
   1.154 +echo "Could not locate VBoxManage.exe --> Is VirtualBox installed?"
   1.155 +GOTO END
   1.156 +
   1.157 +:VBM_IMPORT_ERROR
   1.158 +echo "Failed to import OVA template into VBox."
   1.159 +GOTO END
   1.160 +
   1.161 +:END
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/OpenSecurity/install/vbox_lookup.vbs	Mon Feb 17 15:19:32 2014 +0100
     2.3 @@ -0,0 +1,3 @@
     2.4 +Set cShell = CreateObject("WScript.Shell")
     2.5 +WScript.Echo cShell.RegRead("HKLM\SOFTWARE\Oracle\VirtualBox\InstallDir")
     2.6 +