1.1 --- a/OpenSecurity/install/initial_vm.bat Tue Feb 18 12:57:28 2014 +0100
1.2 +++ b/OpenSecurity/install/initial_vm.bat Tue Feb 18 14:00:16 2014 +0100
1.3 @@ -1,58 +1,107 @@
1.4 -@echo off
1.5 -
1.6 -rem ensure environment is ready
1.7 -
1.8 -rem This gets up VirtualBox VBoxSVC.exe COM Server right
1.9 -rem and thus helps us not to run in any timing problems
1.10 -rem due to a lazy VBox COM Server ... o.O
1.11 -VBoxManage list vms > %TEMP%\VMS.txt
1.12 -del %TEMP%\VMS.txt
1.13 -
1.14 -rem Now, VBox should feel good within the Windows OS space
1.15 -rem switch into the User's VBox setup folders
1.16 -C:
1.17 -cd "C:\Users\%USERNAME%
1.18 -mkdir "VirtualBox VMs"
1.19 -cd "VirtualBox VMs"
1.20 -
1.21 -rem get recent initial VM and create disk image
1.22 -echo "download initial OpenSecurity VM"
1.23 -rem wget http://service.x-net.at/opensecurity/OsecVM_initialized.ova
1.24 -
1.25 -rem I've already downloaded ... this is for convenience --> delete this line
1.26 -rem This is just for testing. Enbale the real "wget http://service...." line above
1.27 -rem to get the real VM image from X-Net
1.28 -copy C:\Users\dyle\Documents\OpenSecurity\setup\OsecVM_initialized.ova .
1.29 -
1.30 -rem import the VM
1.31 -VBoxManage.exe import OsecVM_initialized.ova --vsys 0 --vmname SecurityDVM --unit 12 --disk SecurityDVM\SecurityDVM.vmdk
1.32 -
1.33 -rem launch the SecurityVM the first time to let the user do initial updates
1.34 -VBoxManage.exe startvm SecurityDVM
1.35 -
1.36 -echo # Start VirtualBox and update the machine
1.37 -echo #
1.38 -echo # login with
1.39 -echo # user: root
1.40 -echo # pass: osecvm
1.41 -echo #
1.42 -echo # issue these commands as root
1.43 -echo #
1.44 -echo # # apt-get update
1.45 -echo # # apt-get upgrade
1.46 -echo # # apt-get dist-upgrade
1.47 -echo #
1.48 -echo # then shutdown the machine with
1.49 -echo #
1.50 -echo # # shutdown -h now
1.51 -echo #
1.52 -echo # press a key when done to proceed
1.53 -pause
1.54 -
1.55 -rem Turn the VM disk image immutable and attach it
1.56 -echo sealing disk image ...
1.57 -VBoxManage.exe storageattach SecurityDVM --storagectl SATA --port 0 --medium none
1.58 -VBoxManage.exe modifyhd SecurityDVM\SecurityDVM.vmdk --type immutable
1.59 -VBoxManage.exe storageattach SecurityDVM --storagectl SATA --port 0 --device 0 --type hdd --mtype normal --medium SecurityDVM\SecurityDVM.vmdk
1.60 -echo done. OpenSecurity is ready to serve
1.61 -
1.62 +@echo off
1.63 +
1.64 +cd "%0%\.."
1.65 +SET WGET="%0%\..\..\cygwin64\bin\wget.exe"
1.66 +SET BASH="%0%\..\..\cygwin64\bin\bash.exe"
1.67 +SET OS_ADMIN_PORT=8080
1.68 +
1.69 +rem ------------------------------------------------------------
1.70 +rem install initial OpenSecuity VM image
1.71 +rem ------------------------------------------------------------
1.72 +
1.73 +SET OVA_TEMPLATE_URL="http://service.x-net.at/opensecurity/OsecVM_latest.ova"
1.74 +
1.75 +
1.76 +:ENSURE_VBOX_READY
1.77 +rem ensure environment is ready
1.78 +rem This gets up VirtualBox VBoxSVC.exe COM Server right
1.79 +rem and thus helps us not to run in any timing problems
1.80 +rem due to a lazy VBox COM Server ... o.O
1.81 +rem
1.82 +rem 1. locate the VBoxManage.exe
1.83 +rem 2. check version (ability to call)
1.84 +rem 3. enumerate vms (ensure VBoxSVC.exe feels good)
1.85 +
1.86 +CSCRIPT //NoLogo vbox_lookup.vbs >%TEMP%\vbox_lookup
1.87 +SET /P VBM_DIR=<%TEMP%\vbox_lookup
1.88 +SET VBM="%VBM_DIR%VBoxManage.exe"
1.89 +IF NOT EXIST %VBM% GOTO VBM_MISSING
1.90 +%VBM% -version >%TEMP%\vbox_version
1.91 +IF NOT ERRORLEVEL 0 GOTO VBM_ERROR
1.92 +%VBM% list vms > %TEMP%\VMS.txt
1.93 +del %TEMP%\VMS.txt
1.94 +
1.95 +
1.96 +:PREPARE_VBOX_FOLDER
1.97 +rem Now, VBox should feel good within the Windows OS space
1.98 +rem switch into the User's VBox setup folders
1.99 +rem
1.100 +rem 1. create Virtual box folder (if not already existing)
1.101 +rem 2. download OVA template
1.102 +rem 3. import OVS template in VBox
1.103 +
1.104 +SET VBP=%HOMEDRIVE%%HOMEPATH%\VirtualBox VMs
1.105 +IF NOT EXIST "%VBP%" MKDIR "%VBP%"
1.106 +
1.107 +
1.108 +:DOWNLOAD_TEMPLATE_VM
1.109 +rem Download the OSec.ova template from the X-Net servers
1.110 +
1.111 +IF EXIST OsecVM.ova GOTO COPY_TEMPLATE_VM
1.112 +echo "download initial OpenSecurity VM"
1.113 +"%WGET%" %OVA_TEMPLATE_URL%
1.114 +IF NOT ERRORLEVEL 0 GOTO OVA_DOWNLOAD_ERROR
1.115 +RENAME OsecVM_latest.ova OsecVM.ova
1.116 +
1.117 +:COPY_TEMPLATE_VM
1.118 +echo "copying template VM into Virtual Box's realm"
1.119 +%HOMEDRIVE%
1.120 +cd "%VBP%"
1.121 +COPY "%0%\..\OSecVM.ova" .
1.122 +
1.123 +
1.124 +:IMPORT_TEMPLATE_VM
1.125 +%VBM% import OsecVM.ova --vsys 0 --vmname SecurityDVM --unit 12 --disk SecurityDVM\SecurityDVM.vmdk
1.126 +IF NOT ERRORLEVEL 0 GOTO VBM_IMPORT_ERROR
1.127 +echo "turn template into immutable image"
1.128 +%VBM% storageattach SecurityDVM --storagectl SATA --port 0 --medium none
1.129 +%VBM% storageattach SecurityDVM --storagectl SATA --port 0 --device 0 --type hdd --mtype writethrough --medium SecurityDVM\SecurityDVM.vmdk
1.130 +%VBM% storageattach SecurityDVM --storagectl SATA --port 0 --medium none
1.131 +%VBM% storageattach SecurityDVM --storagectl SATA --port 0 --device 0 --type hdd --mtype immutable --medium SecurityDVM\SecurityDVM.vmdk
1.132 +echo "OpenSecurity VM Image ready."
1.133 +
1.134 +:UPDATE_TEMPLATE
1.135 +rem we have imported the Template
1.136 +rem now, we need to update the template before first use
1.137 +
1.138 +cd "%0%\..\.."
1.139 +SET PATH=%CD%\python27;%PATH%
1.140 +START python27\pythonw bin\opensecurityd.pyw
1.141 +echo Waiting for OpenSecurity Amdin Daemon to start
1.142 +%BASH% -c -l "for i in $(seq 0 4); do echo -n '.'; sleep 1; done; echo"
1.143 +rem trigger update
1.144 +%WGET% http://localhost:%OS_ADMIN_PORT%/update_template
1.145 +GOTO END
1.146 +
1.147 +
1.148 +:OVA_DOWNLOAD_ERROR
1.149 +echo "Failed to download OVA initial image."
1.150 +GOTO END
1.151 +
1.152 +
1.153 +:VBM_ERROR
1.154 +echo "Error calling VBoxManage.exe"
1.155 +GOTO END
1.156 +
1.157 +
1.158 +:VBM_MISSING
1.159 +echo "Could not locate VBoxManage.exe --> Is VirtualBox installed?"
1.160 +GOTO END
1.161 +
1.162 +
1.163 +:VBM_IMPORT_ERROR
1.164 +echo "Failed to import OVA template into VBox."
1.165 +GOTO END
1.166 +
1.167 +
1.168 +:END