[
  {
    "path": ".gitignore",
    "content": "VMs/**/*.*\nTools/*.exe\nTools/*.iso\nTools/*.msi\nTools/*.bat\nTools/hosts\n!Tools/jre-windows-i586.exe\nTools/selenium_conf/*.exe\nTools/selenium_conf/*.zip\nTools/selenium_conf/*.jar\n*log"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2014 Denis Witt\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."
  },
  {
    "path": "Makefile",
    "content": "all: fetch fetch_vms\n\nfetch: selenium-server deuac IEDriver\n\nfetch_vms: IE11-Win7 IE10-Win7 IE9-Win7 IE8-Win7\n\nIE11-Win7:\n\tcurl -O -L \"https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE11/Windows/IE11.Win7.For.Windows.VirtualBox.zip\"\n\tunzip IE11.Win7.For.Windows.VirtualBox.zip\n\tmkdir VMs || true\n\tmv IE11\\ -\\ Win7.ova VMs\n\trm IE11.Win7.For.Windows.VirtualBox.zip\n\n\nIE10-Win7:\n\tcurl -O -L \"https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE10/Windows/IE10.Win7.For.Windows.VirtualBox.zip\"\n\tunzip IE10.Win7.For.Windows.VirtualBox.zip\n\tmkdir VMs || true\n\tmv IE10\\ -\\ Win7.ova VMs\n\trm IE10.Win7.For.Windows.VirtualBox.zip\n\nIE9-Win7:\n\tcurl -O -L \"https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE9/Windows/IE9.Win7.For.Windows.VirtualBox.zip\"\n\tunzip IE9.Win7.For.Windows.VirtualBox.zip\n\tmkdir VMs || true\n\tmv IE9\\ -\\ Win7.ova VMs\n\trm IE9.Win7.For.Windows.VirtualBox.zip\n\nIE8-Win7:\n\tcurl -O -L \"https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE8/Windows/IE8.Win7.For.Windows.VirtualBox.zip\"\n\tunzip IE8.Win7.For.Windows.VirtualBox.zip\n\tmkdir VMs || true\n\tmv IE8\\ -\\ Win7.ova VMs\n\trm IE8.Win7.For.Windows.VirtualBox.zip\n\nselenium-server:\n\tcurl -o Tools/selenium_conf/selenium-server-standalone.jar -L http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar\n\ndeuac:\n\tcurl -o Tools/deuac.iso -L https://github.com/tka/SeleniumBox/blob/master/deuac.iso?raw=true\n\nIEDriver:\n\tcurl -o Tools/selenium_conf/IEDriverServer.zip -L http://selenium-release.storage.googleapis.com/2.44/IEDriverServer_Win32_2.44.0.zip\n\t#curl -o Tools/selenium_conf/IEDriverServer.zip -L http://selenium-release.storage.googleapis.com/2.44/IEDriverServer_x64_2.44.0.zip\n\tcd Tools/selenium_conf && unzip IEDriverServer.zip\n\n# Not using this as we are using vm only for IE\nchromedriver:\n\tcurl -o Tools/selenium_conf/chromedriver.zip -L http://chromedriver.storage.googleapis.com/2.15/chromedriver_win32.zip\n\tcd Tools/selenium_conf && unzip chromedriver.zip\n\n# Commenting command line jre download as this is broken, oracle has include some sort of hash in download url, need to fix this\n#Tools/jre-windows-i586.exe:\n#\tcurl -j -o Tools/jre-windows-i586.exe -L -O -H \"Cookie: oraclelicense=accept-securebackup-cookie\" http://download.oracle.com/otn-pub/java/jdk/8u151-b12/jre-8u151-windows-i586.exe\n\n# Not using this as we are using vm only for IE\nfirefox:\n\tcurl -o Tools/firefox.exe -L \"https://download.mozilla.org/?product=firefox-34.0.5-SSL&os=win&lang=en-GB\"\n\n# Not using this as we are using vm only for IE\nchrome:\n \tcurl -o Tools/chrome.exe -L \"https://dl.google.com/update2/installers/ChromeStandaloneSetup.exe\"\n"
  },
  {
    "path": "README.md",
    "content": "modernie_selenium\n=================\n\nManage modern.ie VirtualBox-Appliances with Selenium-Support\n\nThis script allows to delete and create virtual Windows-Machines using Images from http://www.modern.ie for automating Browser-Testing with Selenium.\n\nAs the modern.ie-Machines refuses to run more than 30-90 Days (at least for more than an hour) we remove the machines on a regular basis and recreate the original Appliance with all changes needed to run Selenium.\n\n\nPrerequisites\n=================\n\n  * VirtualBox (tested with 5.0.30)\n  * VirtualBox Extension Pack\n  * Selenium-Hub\n  \n\nWhat it does\n=================\n\n  * Import modern.ie VM images to VirtualBox\n  * Configure VM Network-Settings\n  * Configure VM RDP-Port-Setting (VRDE)\n  * Configure VM Clipboard behaviour\n  * Disable UAC\n  * Disable Windows-Firewall\n  * Rename the VM (Hostname)\n  * Update windows hosts file with hub ip\n  * Configures IE Protected-Mode to work with Selenium\n  * Disables IE Cache\n  * Install Java\n  * Install Selenium node and register to hub\n \n\nWhat it doesn't do\n==================\n\n  * Set up VirtualBox\n\nGetting started\n===============\n\n  * Run make all\n  * Run ```mkvm.sh /path/to/your/appliance/foobar.ova```.\n\nFetching the Appliances\n=======================\n\nGet all VM images using this command:\n\n```\nmake fetch_vms\n```\n\nConfigure\n=========\n\nAdjust ```config.sh``` to your needs. See below for details.\n\nIf you use the Makefile to get the binary files then you shouldn't have to alter the config script.\n\nBy default the Script assumes that your VirtualBox-Machines are placed in ```VMs/``` and that the script is run by the User the script is run as. All supplemental files should be placed in ```Tools/``` but you can configure different paths.\n\nTo do so simply edit ```config.sh```:\n\n```\njava_exe=\"jre-windows-i586.exe\"\n```\n\nFilename of your Java-Installer.\n\n```\nselenium_jar=\"selenium-server-standalone.jar\"\n```\n\nFilename of your Selenium-Server.\n\n```\nnic_bridge=\"eth0\"\n```\n\nName of your Network-Interface to use as bridge for your VM.\n\n```\nvm_path=\"VMs/\"\n```\n\nPath where to put your VMs.\n\n```\nvm_mem=\"768\"\n```\n\nAmount of memory (RAM) for Windows Vista, 7 and 8.x VMs in MB.\n\n```\nvm_mem_xp=\"512\"\n```\n\nAmount of memory (RAM) for Windows XP VMs in MB.\n\n```\ndeuac_iso=\"Tools/deuac.iso\"\n```\n\nPath and filename for deuac.iso (a bootable CD-Image to disable UAC so we can install Java without Problems).\n\n```\ntools_path=\"Tools/\"\n```\n\nPath to ```java_exe```, ```firefox_exe``` and ```chrome_exe``` (Location of Installers on VM-Host).\n\n```\nselenium_path=\"Tools/selenium_conf/\"\n```\n\nPath to your Selenium-Config-Files. It's important that you keep the folder structure below this point, otherwise the config will not be copied to the VMs (or the wrong Config goes to the wrong Machines).\n\n```\nie_cache_reg=\"Tools/ie_disablecache.reg\"\n```\n\nPath and filename to ```ie_disablecache.reg``` (Disables Internet Explorer Cache).\n\n```\nie_protectedmode_reg=\"Tools/ie_protectedmode.reg\"\n```\n\nPath and filename to ```ie_protectedmode.reg``` (Enables Protected Mode for all IE Security Zones).\n\n```\nlog_path=\"\"\n```\n\nPath to the (temporary) Logfile.\n\n```\nvbox_user=\"${USER}\"\n```\n\nUsername of VirtualBox-User.\n\n```\nmailto=\"root@example.com\"\n```\n\nE-Mail-Adress to send logfile to.\n\n```\ncreate_snapshot=False\n```\n\nIf ```True``` a snapshot will be created after all changes have been made.\n\nSelenium Config / Hub Hostname\n==============================\n\nHub should be running on host OS, as scripts fetch the ip of host os and put that into hosts file of windows vm. Need to change the script to fetch the ip of docker hub \n\nUsage\n=====\n\nRun below command:\n\n```\nmake fetch\n```\nGet specific VM image[Check options in make file]:\n\n```\nmake IE11-Win7\n```\n\nTo import the IE11-Win7 Appliance simply run:\n\n```\nmkvm.sh VMs/IE11\\ -\\ Win7.ova\n```\n\nIf you already have an IE11-Win7-Instance - and want to recreate it - run:\n\n```\nmkvm.sh VMs/IE11\\ -\\ Win7.ova --delete \"IE11 - Win7\"\n```\n\n\nTODO\n==============\n\n* Network Confguration\n* Jre installation link broken as Oracle has included has in the url[Fix: JRE exe is on Tools directory]\n* Windows silent activation\n* Need to change the script to fetch the ip of docker hub and update in windows hosts file\n\n"
  },
  {
    "path": "Tools/ie11_win32.reg",
    "content": "Windows Registry Editor Version 5.00\n\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BFCACHE]\n\"iexplore.exe\"=dword:00000000\n\n"
  },
  {
    "path": "Tools/ie_disablecache.reg",
    "content": "Windows Registry Editor Version 5.00\n\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main]\n“Start Page”=”about:blank”\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\CACHE]\n\"Persistent\"=dword:00000000\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Privacy]\n\"ClearBrowsingHistoryOnExit\"=dword:00000001\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings]\n\"SyncMode5\"=dword:00000003\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Url History]\n\"DaysToKeep\"=dword:00000000\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\5.0\\Cache\\Content]\n\"CacheLimit\"=dword:00002000\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache\\Content]\n\"CacheLimit\"=dword:00002000\n"
  },
  {
    "path": "Tools/ie_protectedmode.reg",
    "content": "Windows Registry Editor Version 5.00\n\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\0]\n\"2500\"=dword:00000000\n\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\1]\n\"2500\"=dword:00000000\n\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2]\n\"2500\"=dword:00000000\n\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3]\n\"2500\"=dword:00000000\n\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\4]\n\"2500\"=dword:00000000\n\n"
  },
  {
    "path": "Tools/selenium_conf/WIN7/IE10/config.json",
    "content": "{\n    \"configuration\": {\n        \"port\": 5555,\n        \"register\": true,\n        \"registerCycle\": 5000,\n        \"hubPort\": 4444,\n        \"hubHost\": \"hubhost\"\n    },\n    \"capabilities\": [\n        {\n            \"platform\": \"WINDOWS\",\n            \"browserName\": \"internet explorer\",\n            \"version\": 10,\n            \"maxInstances\": 1,\n            \"seleniumProtocol\": \"WebDriver\"\n        }\n    ]\n}\n"
  },
  {
    "path": "Tools/selenium_conf/WIN7/IE11/config.json",
    "content": "{\n    \"configuration\": {\n        \"port\": 5555,\n        \"register\": true,\n        \"registerCycle\": 5000,\n        \"hubPort\": 4444,\n        \"hubHost\": \"hubhost\"\n    },\n    \"capabilities\": [\n        {\n            \"platform\": \"WINDOWS\",\n            \"browserName\": \"internet explorer\",\n            \"version\": 11,\n            \"maxInstances\": 1,\n            \"seleniumProtocol\": \"WebDriver\"\n        }\n    ]\n}\n"
  },
  {
    "path": "Tools/selenium_conf/WIN7/IE8/config.json",
    "content": "{\n    \"configuration\": {\n        \"port\": 5555,\n        \"register\": true,\n        \"registerCycle\": 5000,\n        \"hubPort\": 4444,\n        \"hubHost\": \"hubhost\"\n    },\n    \"capabilities\": [\n        {\n            \"platform\": \"WINDOWS\",\n            \"browserName\": \"internet explorer\",\n            \"version\": 8,\n            \"maxInstances\": 1,\n            \"seleniumProtocol\": \"WebDriver\"\n        }\n    ]\n}\n"
  },
  {
    "path": "Tools/selenium_conf/WIN7/IE9/config.json",
    "content": "{\n    \"configuration\": {\n        \"port\": 5555,\n        \"register\": true,\n        \"registerCycle\": 5000,\n        \"hubPort\": 4444,\n        \"hubHost\": \"hubhost\"\n    },\n    \"capabilities\": [\n        {\n            \"platform\": \"WINDOWS\",\n            \"browserName\": \"internet explorer\",\n            \"version\": 9,\n            \"maxInstances\": 1,\n            \"seleniumProtocol\": \"WebDriver\"\n        }\n    ]\n}\n"
  },
  {
    "path": "Tools/selenium_conf/selenium.bat",
    "content": "\"C:\\Program Files\\Java\\jre1.8.0_151\\bin\\java.exe\" -jar c:\\selenium\\selenium-server-standalone.jar -role node -nodeConfig c:\\selenium\\config.json"
  },
  {
    "path": "config.sh",
    "content": "# Config; See readme for details.\njava_exe=\"jre-windows-i586.exe\"\nfirefox_exe=\"firefox.exe\"\nchrome_exe=\"chrome.exe\"\nselenium_jar=\"selenium-server-standalone.jar\"\n\nif [ $(uname) == \"Darwin\" ]\nthen\n  # This makes sense on a mac\n  nic_bridge=\"en0\"\nelse\n  # This works on Ubuntu\n  nic_bridge=\"eth0\"\nfi\n\nvm_path=\"VMs/\"\nvm_mem=\"768\"\nvm_mem_xp=\"512\"\ndeuac_iso=\"deuac.iso\"\ntools_path=\"$(pwd)/Tools/\"\nselenium_path=\"$(pwd)/Tools/selenium_conf/\"\nie_cache_reg=\"ie_disablecache.reg\"\nie_protectedmode_reg=\"ie_protectedmode.reg\"\nlog_path=\"\"\nvbox_user=\"${USER}\"\nmailto=\"root\"\ncreate_snapshot=False\n"
  },
  {
    "path": "mkvm.sh",
    "content": "#!/bin/bash\n\n# Debug\n#set -x\n#set -e\n\nsource config.sh\n\n# Basic-Checks.\nif [ \"${1}\" = \"--help\" ]; then\n  echo \"Usage: $0 path_to_ova [--delete VM-Name/UID]\"\n  exit 0\nfi\n\nif [ -z \"${1}\" ]; then\n  echo \"Appliance-Path is missing...\"\n  exit 1\nfi\n\nif [ ! -f \"${1}\" ]; then\n  echo \"Appliance ${1} not found...\"\n  exit 1\nfi\n\nif [ ! $(which VBoxManage) ]; then\n  echo \"VBoxManage not found...\"\n  exit 1\nfi\n\nif [ \"${USER}\" != \"${vbox_user}\" ]; then\n  echo \"This script must be run by user \\'${vbox_user}\\'...\"\n  exit 1\nfi\n\n# Init; Do not change.\nappliance=${1}\nremove_vm=${3}\nvm_name=False\nvm_pretty_name=False\nfatal=False\nerror=False\nwarning=False\n\n\ncopyto() {\n  # $1 = filename, $2 = source directory, $3 destination directory\n  if [ ! -f \"${2}${1}\" ]\n  then\n    echo \"Local file '${2}${1}' doesn't exist\"\n  fi\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto --target-directory \\\"${3}${1}\\\" \\\"${2}${1}\\\" --username 'IEUser' --password 'Passw0rd!'\"\n}\n\n# Loop VBoxManage guestcontrol commands as they are unreliable.\nexecute() {\n  counter=0\n  while [ $counter -lt 3 ]; do\n\n    echo \"Running $@\"\n    bash -c \"$@\"\n\n    if [ \"$?\" = \"0\" ]; then\n      guestcontrol_error=0\n      break\n    else\n      guestcontrol_error=1\n    fi\n    let counter=counter+1\n    sleep 10\n  done\n\n  if [ \"$guestcontrol_error\" = \"0\" ]; then\n    return 0\n  else\n    chk skip 1 \"Error running $@\"\n  fi\n}\n\n# Write Logfile and STDOUT.\nlog() {\n  echo ${1} | tee -a \"${log_path}${vm_pretty_name}.log\"\n}\n\n# Error-Handling.\nchk() {\n  if [ \"${2}\" != \"0\" ]; then\n    if [ \"${1}\" = \"fatal\" ]; then\n      log \"[FATAL] ${3}\"\n      fatal=True\n      sendmessage\n      exit ${2}\n    fi\n    if [ \"${1}\" = \"skip\" ]; then\n      log \"[WARNING] ${3}\"\n      warning=True\n    fi\n    if [ \"${1}\" = \"error\" ]; then\n      log \"[ERROR] ${3}\"\n      error=True\n    fi\n  else\n    log \"[OK]\"\n  fi\n}\n\n# Send Status-Mail.\nsendmessage() {\n  if [ ! -z ${mailto} ]; then\n    subject_prefix=\"SUCCESS\"\n    if [ \"${warning}\" = \"True\" ]; then\n      subject_prefix=\"WARNING\"\n    fi\n    if [ \"${error}\" = \"True\" ]; then\n      subject_prefix=\"ERROR\"\n    fi\n    if [ -f \"${log_path}False.log\" ]; then\n       cat \"${log_path}False.log\" \"${log_path}${vm_pretty_name}.log\" > /tmp/${vm_pretty_name}.log\n       cat \"/tmp/${vm_pretty_name}.log\" | mail -s \"${subject_prefix}: ${vm_name}\" ${mailto}\n       rm \"${log_path}${vm_pretty_name}.log\"\n       rm \"${log_path}False.log\"\n    else\n       cat \"${log_path}${vm_pretty_name}.log\" | mail -s \"${subject_prefix}: ${vm_name}\" ${mailto}\n       rm \"${log_path}${vm_pretty_name}.log\"\n    fi\n  fi\n}\n\n# Get VM OS-Type.\nexecute_os_specific() {\n  case \"${vm_os_type}\" in\n    WindowsXP)\n      ${1}_xp\n    ;;\n    WindowsVista)\n      ${1}_wv\n    ;;\n    Windows7)\n      ${1}_w7\n    ;;\n    Windows8*)\n      ${1}_w8\n    ;;\n    *)\n      chk skip 1 \"Unexpected OS-Type, skipping ${1}...\"\n    ;;\n  esac\n}\n\n# Check if the VM is still running.\ncheck_shutdown() {\n  counter=0\n  echo -n \"Waiting for shutdown\"\n  while $(VBoxManage showvminfo \"${vm_name}\" | grep -q 'running'); do\n    echo -n \".\"\n    sleep 1\n    let counter=counter+1\n    if [ ${counter} -ge 120 ]; then\n      chk skip 1 \"Unable to shutdown/restart...\"\n      break\n    fi\n  done\n  echo \"\"\n  waiting 5\n}\n\n# Print some dots.\nwaiting() {\n  counter=0\n  echo -n \"Waiting ${1} seconds\"\n  while [ ${counter} -lt ${1} ]; do\n    echo -n \".\"\n    let counter=counter+1\n    sleep 1\n  done\n  echo \"\"\n}\n\n# Get informations about the given Appliance (Name, OS-Type, IE-Version)\nget_vm_info() {\n  vm_info=$(VBoxManage import \"${appliance}\" -n)\n  chk fatal $? \"Error getting Appliance Info\"\n\n  vm_name=$(echo \"${vm_info}\" | grep \"Suggested VM name\" | awk -F'\"' '{print $2}')\n  vm_pretty_name=$(echo \"${vm_info}\" | grep \"Suggested VM name\" | awk -F'\"' '{print $2}' | sed 's/_/-/g' | sed 's/ //g' | sed 's/\\.//g')\n  vm_os_type=$(echo \"${vm_info}\" | grep 'Suggested OS type' | awk -F'\"' '{print $2}')\n  vm_ie=$(echo \"${vm_name}\" | awk -F' -' '{print $1}')\n}\n\n#Internal: Helper-Functions to install the Appliance (called by import_vm)\nex_import_vm_xp() {\n  VBoxManage import \"${appliance}\" --vsys 0 --memory ${vm_mem_xp}\n  chk fatal $? \"Could not import VM\"\n}\n\nex_import_vm_w7() {\n  VBoxManage import \"${appliance}\" --vsys 0 --memory ${vm_mem}\n  chk fatal $? \"Could not import VM\"\n}\n\nex_import_vm_wv() {\n  ex_import_vm_w7\n}\n\nex_import_vm_w8() {\n  ex_import_vm_w7\n}\n\n# Import the given Appliance-File; OS-Specific\nimport_vm() {\n  log \"Importing ${appliance} as ${vm_name}...\"\n  execute_os_specific ex_import_vm\n}\n\n# Set VM Network-Config.\nset_network_config() {\n  log \"Setting network bridge ${nic_bridge}...\"\n  execute \"VBoxManage modifyvm \\\"${vm_name}\\\" --nic1 bridged --bridgeadapter1 \\\"${nic_bridge}\\\"\"\n  chk error $? \"Could not set Bridge\"\n}\n\n# Find and set free Port for RDP-Connection.\nset_rdp_config() {\n  log \"Setting VRDE-Port ${vrdeport}...\"\n  vrdeports=$(find \"${vm_path}\" -name *.vbox -print0 | xargs -0 grep \"TCP/Ports\" | awk -F'\"' '{print $4}' | sort)\n  for ((i=9000;i<=10000;i++)); do\n    echo ${vrdeports} | grep -q ${i}\n    if [[ $? -ne 0 ]]; then\n      vrdeport=$i\n      break\n    fi\n  done\n\n  if [ -z \"${vrdeport}\" ]; then\n    vrdeport=\"9000\"\n  fi\n  if [[ ${vrdeport} < 9000 ]]; then\n    vrdeport=\"9000\"\n  fi\n  if [ \"${vrdeport}\" = \"10000\" ]; then\n    chk skip $? \"Could not find free VRDE-Port\"\n  else\n    execute \"VBoxManage modifyvm \\\"${vm_name}\\\" --vrde on --vrdeport \\\"${vrdeport}\\\"\"\n    chk error $? \"Could not set VRDE-Port\"\n  fi\n}\n\n# Internal: Helper-Functions to disable UAC (called by disable_uac)\nex_disable_uac_w7() {\n  log \"Mounting Disk...\"\n  VBoxManage storageattach \"${vm_name}\" --storagectl \"IDE\" --port 1 --device 0 --type dvddrive --medium \"${tools_path}${deuac_iso}\"\n  chk fatal $? \"Could not mount ${tools_path}${deuac_iso}\"\n  log \"Disabling UAC...\"\n  VBoxManage startvm \"${vm_name}\" --type headless\n  chk fatal $? \"Could not start VM to disable UAC\"\n  waiting 60\n  check_shutdown\n  log \"Removing Disk...\"\n  VBoxManage storageattach \"${vm_name}\" --storagectl \"IDE\" --port 1 --device 0 --type dvddrive --medium none\n  chk fatal $? \"Could not unmount ${deuac_iso}\"\n}\n\nex_disable_uac_wv() {\n  ex_disable_uac_w7\n}\n\nex_disable_uac_w8() {\n  ex_disable_uac_w7\n}\n\nex_disable_uac_xp() {\n  return 1\n}\n\n# Disable UAC; Required to install Java successfully later; OS-Specific\ndisable_uac() {\n  execute_os_specific ex_disable_uac\n}\n\n# Start the VM; Wait some seconds afterwards to give the VM time to start up completely.\nstart_vm() {\n  log \"Starting VM ${vm_name}...\"\n  VBoxManage startvm \"${vm_name}\" --type headless\n  chk fatal $? \"Could not start VM\"\n  waiting 60\n}\n\n# Internal: Helper-Functions to disable the Windows Firewall (called by disable_firewall)\nex_disable_firewall_xp() {\n  log \"Disabling Windows XP Firewall...\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe 'C:/windows/system32/netsh.exe' --username 'IEUser' --password 'Passw0rd!' -- netsh/arg0 firewall set opmode mode=DISABLE\"\n  chk error $? \"Could not disable Firewall\"\n}\n\nex_disable_firewall_w7() {\n  log \"Disabling Windows Firewall...\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe 'C:/windows/system32/netsh.exe' --username 'IEUser' --password 'Passw0rd!' -- netsh/arg0 advfirewall set allprofiles state off\"\n  chk error $? \"Could not disable Firewall\"\n}\n\nex_disable_firewall_wv() {\n  ex_disable_firewall_w7\n}\n\nex_disable_firewall_w8() {\n  ex_disable_firewall_w7\n}\n\n# Disable the Windows Firewall; OS-Specific\ndisable_firewall() {\n  execute_os_specific ex_disable_firewall\n}\n\n# Create C:\\Temp\\; Most Functions who copy files to the VM are relying on this folder and will fail is he doesn't exists.\ncreate_temp_path() {\n  vm_temp=\"C:/Temp/\"\n  log \"Creating ${vm_temp}...\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" createdirectory \\\"${vm_temp}\\\" --username 'IEUser' --password 'Passw0rd!'\"\n  chk fatal $? \"Could not create ${vm_temp}\"\n}\n\n# Apply registry changes to configure Internet Explorer settings (Protected-Mode, Cache)\nset_ie_config() {\n  log \"Apply IE Protected-Mode Settings...\"\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${ie_protectedmode_reg}\\\" \"${vm_temp}\" --username 'IEUser' --password 'Passw0rd!'\"\n  copyto \"${ie_protectedmode_reg}\" \"$tools_path\" \"$vm_temp\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe 'C:\\\\Windows\\\\Regedit.exe' --username 'IEUser' --password 'Passw0rd!' -- Regedit/arg0 /s '${vm_temp}ie_protectedmode.reg'\"\n  chk error $? \"Could not apply IE Protected-Mode-Settings\"\n  log \"Disabling IE-Cache...\"\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${ie_cache_reg}\\\" \"${vm_temp}\" --username 'IEUser' --password 'Passw0rd!'\"\n  copyto ie_disablecache.reg \"${tools_path}\" \"${vm_temp}\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe 'C:\\\\Windows\\\\Regedit.exe' --username 'IEUser' --password 'Passw0rd!' -- Regedit/arg0 /s '${vm_temp}ie_disablecache.reg'\"\n  chk error $? \"Could not disable IE-Cache\"\n}\n\n# Install Java (required by Selenium); We don't use --wait-exit as it may cause trouble with XP-VMs, instead we just wait some time to ensure the Java-Installer can finish.\ninstall_java() {\n  log \"Installing Java...\"\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${tools_path}${java_exe}\\\" \"${vm_temp}\" --username 'IEUser' --password 'Passw0rd!'\"\n  copyto \"${java_exe}\" \"${tools_path}\" \"${vm_temp}\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe \\\"${vm_temp}${java_exe}\\\" --username 'IEUser' --password 'Passw0rd!' -- ${java_exe}/args0 /s\"\n  chk error $? \"Could not install Java\"\n  waiting 120\n}\n\n# Install Firefox.\ninstall_firefox() {\n  log \"Installing Firefox...\"\n  copyto \"${firefox_exe}\" \"${tools_path}\" \"${vm_temp}\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe \\\"${vm_temp}${firefox_exe}\\\" --username 'IEUser' --password 'Passw0rd!' -- ${firefox_exe}/args0 /S\"\n  chk error $? \"Could not install Firefox\"\n  waiting 120\n}\n\n# Install Chrome-Driver for Selenium\ninstall_chrome_driver() {\n  log \"Installing Chrome Driver...\"\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${selenium_path}chromedriver.exe\\\" C:/Windows/system32/ --username 'IEUser' --password 'Passw0rd!'\"\n  copyto chromedriver.exe \"${selenium_path}\" \"C:/Windows/system32/\"\n  chk error $? \"Could not install Chrome Driver\"\n  waiting 5\n}\n\n# Install Chrome.\ninstall_chrome() {\n  log \"Installing Chrome...\"\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${tools_path}${chrome_exe}\\\" \"${vm_temp}\" --username 'IEUser' --password 'Passw0rd!'\"\n  copyto \"${chrome_exe}\" \"${tools_path}\" \"${vm_temp}\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe 'C:/Windows/System32/msiexec.exe' --username 'IEUser' --password 'Passw0rd!' -- msiexec/args0 /qn /i \\\"${vm_temp}${chrome_exe}\\\"\"\n  chk error $? \"Could not install Chrome\"\n  waiting 120\n  install_chrome_driver\n}\n\n# Internal: Helper-Functions to Install Selenium (called by install_selenium)\nstart_selenium_xp() {\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${selenium_path}selenium.bat\\\" 'C:/Documents and Settings/All Users/Start Menu/Programs/Startup/' --username 'IEUser' --password 'Passw0rd!'\"\n  copyto \"selenium.bat\" \"${selenium_path}\" 'C:/Documents and Settings/All Users/Start Menu/Programs/Startup/'\n  chk error $? \"Could not copy Selenium-Startup-File\"\n}\n\nstart_selenium_w7() {\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${selenium_path}selenium.bat\\\" 'C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Startup/' --username 'IEUser' --password 'Passw0rd!'\"\n  copyto \"selenium.bat\" \"${selenium_path}\" 'C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Startup/'\n  chk error $? \"Could not copy Selenium-Startup-File\"\n}\n\nstart_selenium_wv() {\n  start_selenium_w7\n}\n\nstart_selenium_w8() {\n  start_selenium_w7\n}\n\nconfig_selenium_xp() {\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${selenium_path}XP/${vm_ie}/config.json\\\" C:/selenium/ --username 'IEUser' --password 'Passw0rd!'\"\n  copyto config.json \"${selenium_path}XP/${vm_ie}/\" \"C:/selenium/\"\n  chk error $? \"Could not copy Selenium-Config\"\n}\n\nconfig_selenium_w7() {\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${selenium_path}WIN7/${vm_ie}/config.json\\\" C:/selenium/ --username 'IEUser' --password 'Passw0rd!'\"\n  copyto config.json \"${selenium_path}WIN7/${vm_ie}/\" \"C:/selenium/\"\n  chk error $? \"Could not copy Selenium-Config\"\n}\n\nconfig_selenium_wv() {\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${selenium_path}VISTA/${vm_ie}/config.json\\\" C:/selenium/ --username 'IEUser' --password 'Passw0rd!'\"\n  copyto config.json \"${selenium_path}VISTA/${vm_ie}/\" \"C:/selenium/\"\n  chk error $? \"Could not copy Selenium-Config\"\n}\n\nconfig_selenium_w8() {\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${selenium_path}WIN8/${vm_ie}/config.json\\\" C:/selenium/ --username 'IEUser' --password 'Passw0rd!'\"\n  copyto config.json \"${selenium_path}WIN8/${vm_ie}/\" \"C:/selenium/\"\n  chk error $? \"Could not copy Selenium-Config\"\n}\n\nie11_driver_reg() {\n  if [ \"${vm_ie}\" = \"IE11\" ]; then\n    log \"Copy ie11_win32.reg...\"\n    #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${tools_path}ie11_win32.reg\\\" \"${vm_temp}\" --username 'IEUser' --password 'Passw0rd!'\"\n    copyto ie11_win32.reg \"${tools_path}\" \"${vm_temp}\"\n    chk skip $? \"Could not copy ie11_win32.reg\"\n    log \"Setting ie11_win32.reg...\"\n    execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe 'C:\\\\Windows\\\\Regedit.exe' --username 'IEUser' --password 'Passw0rd!' -- Regedit/arg0 /s '${vm_temp}ie11_win32.reg'\"\n    chk skip $? \"Could not set ie11_win32.reg\"\n  fi\n}\n\n# Install Selenium\ninstall_selenium() {\n  log \"Creating C:/selenium/...\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" createdirectory C:/selenium/ --username 'IEUser' --password 'Passw0rd!'\"\n  chk fatal $? \"Could not create C:/Selenium/\"\n  log \"Installing Selenium...\"\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${selenium_path}${selenium_jar}\\\" C:/selenium/ --username 'IEUser' --password 'Passw0rd!'\"\n  copyto \"${selenium_jar}\" \"${selenium_path}\" \"C:/selenium/\"\n  chk error $? \"Could not install Selenium\"\n  log \"Installing IEDriverServer...\"\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto \\\"${selenium_path}IEDriverServer.exe\\\" C:/Windows/system32/ --username 'IEUser' --password 'Passw0rd!'\"\n  copyto \"IEDriverServer.exe\" \"${selenium_path}\" \"C:/Windows/system32/\"\n  chk error $? \"Could not install IEDriverServer.exe\"\n  log \"Configure Selenium...\"\n  execute_os_specific config_selenium\n  log \"Prepare Selenium-Autostart...\"\n  execute_os_specific start_selenium\n  ie11_driver_reg\n}\n\n# Create a Snapshot; Disabled by default.\nsnapshot_vm() {\n  log \"Creating Snapshot ${1}...\"\n  VBoxManage snapshot \"${vm_name}\" take \"${1}\"\n  chk skip $? \"Could not create Snapshot ${1}\"\n}\n\n# Reboot the VM; Ensure to wait some time after sending the reboot-Command so that the machine can start up before other actions will applied.\n# shutdown.exe is used because VBox ACPI-Functions are sometimes unreliable with XP-VMs.\nreboot_vm() {\n  log \"Rebooting...\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe C:/Windows/system32/shutdown.exe --username 'IEUser' --password 'Passw0rd!' -- shutdown/args0 /t 5 /r /f\"\n  chk skip $? \"Could not reboot\"\n  waiting 90\n}\n\n# Shutdown the VM and control the success via showvminfo; shutdown.exe is used because VBox ACPI-Functions are sometimes unreliable with XP-VMs.\nshutdown_vm() {\n  log \"Shutting down...\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe C:/Windows/system32/shutdown.exe --username 'IEUser' --password 'Passw0rd!' -- shutdown/args0 /t 5 /s /f\"\n  chk skip $? \"Could not shut down\"\n  check_shutdown\n}\n\nshutdown_vm_for_removal() {\n  log \"Shutting down for removal...\"\n  execute \"VBoxManage guestcontrol \\\"${remove_vm}\\\" run --exe C:/Windows/system32/shutdown.exe --username 'IEUser' --password 'Passw0rd!' -- shutdown/args0 /t 5 /s /f\"\n  chk skip $? \"Could not shut down for removal\"\n}\n\n# Remove the given Machine from VBox and delete all associated files. Shut down the VM beforehand, if needed.\ndelete_vm() {\n  log \"Removing ${remove_vm}...\"\n  if [ ! $(VBoxManage showvminfo \"${remove_vm}\" | grep -q 'running') ]; then\n    shutdown_vm_for_removal\n    waiting 30\n  fi\n  execute \"VBoxManage unregistervm \\\"${remove_vm}\\\" --delete\"\n  chk skip $? \"Could not remove VM ${remove_vm}\"\n  waiting 10\n}\n\n# Change the Hostname of the VM; Avoids duplicate Names on the Network in case you set up several instances of the same Appliance.\n# We copy the rename.bat because the VBox exec doesn't provide the needed Parameters in a way wmic.exe is able to apply correctly.\n# Also WinXP usually fails to set the name, you can use C:\\Temp\\rename.bat to set it manually on the VM. Make sure to restart afterwards.\nrename_vm() {\n  case ${vm_name} in\n    IE6*WinXP*)\n      vm_orig_name=\"ie6winxp\"\n    ;;\n    IE8*WinXP*)\n      vm_orig_name=\"ie8winxp\"\n    ;;\n    IE7*Vista*)\n      vm_orig_name=\"IE7Vista\"\n    ;;\n    IE8*Win7*)\n      vm_orig_name=\"IE8Win7\"\n    ;;\n    IE9*Win7*)\n      vm_orig_name=\"IE9Win7\"\n    ;;\n    IE10*Win7*)\n      vm_orig_name=\"IE10Win7\"\n    ;;\n    IE11*Win7*)\n      vm_orig_name=\"IE11Win7\"\n    ;;\n    IE10*Win8*)\n      vm_orig_name=\"IE10Win8\"\n    ;;\n    IE11*Win8*)\n      vm_orig_name=\"IE11Win8_1\"\n    ;;\n    *)\n      chk skip 1 \"Could not find hostname, skip renaming...\"\n      return 1\n    ;;\n  esac\n  log \"Preparing to change Hostname ${vm_orig_name} to ${vm_pretty_name}...\"\n  echo 'c:\\windows\\system32\\wbem\\wmic.exe computersystem where caption=\"'${vm_orig_name}'\" call rename \"'${vm_pretty_name}'\"' > ${tools_path}/rename.bat\n  chk skip $? \"Could not create rename.bat\"\n  log \"Copy rename.bat...\"\n  #execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" copyto '/tmp/rename.bat' \"${vm_temp}\" --username 'IEUser' --password 'Passw0rd!'\"\n  copyto rename.bat \"${tools_path}\" \"${vm_temp}\"\n  chk skip $? \"Could not copy rename.bat\"\n  log \"Launch rename.bat...\"\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe '${vm_temp}rename.bat' --username 'IEUser' --password 'Passw0rd!'\"\n  chk skip $? \"Could not change Hostname\"\n  waiting 5\n}\n\nconfigure_clipboard() {\n  log \"Changing Clipboard-Mode to bidirectional...\"\n  VBoxManage controlvm \"${vm_name}\" clipboard bidirectional\n  chk skip $? \"Could not set Clipboard-Mode\"\n  waiting 5\n}\n\nupdate_hub_ip() {\n   # Create a hosts file\n   log \"Updating hub ip in guest VM hosts file...\"\nif [ $(uname) == \"Darwin\" ]\nthen\n  # This makes sense on a mac\n  ifconfig ${nic_bridge} | grep \"inet \" | awk '{print $2 \" hubhost\"}' > ${tools_path}/hosts\nelse\n  # This works on Ubuntu\n  ifconfig ${nic_bridge} | grep \"inet \" | awk '{print $2 \" hubhost\"}' | sed 's/addr://' > ${tools_path}/hosts\nfi\n# Send it to the VM\ncopyto hosts ${tools_path} \"C:/Windows/System32/drivers/etc/\"\nchk skip $? \"Could not update hub ip in guest VM hosts file\"\n  waiting 5\n}\n\n# Check if --delete was given as second parameter to this script. The VM-Name is expected to be the third parameter.\n# If no VM-Name is given --delete will be ignored.\nif [ \"${2}\" = \"--delete\" ]; then\n  if [ ! -z \"${3}\" ]; then\n    delete_vm\n  else\n    log \"Delete VM\"\n    chk skip \"--delete was given, but no VM, skipping...\"\n  fi\nfi\n\nex_activate_vm_xp() {\n  chk skip 0 \"Nothing to do...\"\n}\n\nex_activate_vm_w7() {\n  execute \"VBoxManage guestcontrol \\\"${vm_name}\\\" run --exe cmd.exe --username 'IEUser' --password 'Passw0rd!' -- cmd/args0 /C slmgr /ipk 33PXH-7Y6KF-2VJC9-XBBR8-HVTHH\"\n  chk skip $? \"Could not activate Windows\"\n}\n\nex_activate_vm_wv() {\n  ex_activate_vm_w7\n}\n\nex_activate_vm_w8() {\n  ex_activate_vm_w7\n}\n\nactivate_vm() {\n  execute_os_specific ex_activate_vm\n}\n\nget_vm_info\nimport_vm\nset_network_config\nset_rdp_config\ndisable_uac\nstart_vm\ndisable_firewall\ncreate_temp_path\nrename_vm\nset_ie_config\ninstall_java\n#install_firefox\n#install_chrome\ninstall_selenium\nconfigure_clipboard\nupdate_hub_ip\n#activate_vm\n\nif [ \"${create_snapshot}\" = \"True\" ]; then\n  shutdown_vm \"${vm_name}\"\n  snapshot_vm \"Selenium\"\n  start_vm\nelse\n  reboot_vm\nfi\n\nsendmessage\n"
  },
  {
    "path": "mkvm_cron.sh",
    "content": "#!/bin/bash\n\n# Do not remove \"sleep 30\" as Virtualbox tend to act strange if you run to many commands in a short time.\n\nsu vbox --shell=/bin/bash -c \"/opt/mkvm.sh /opt/Appliances/xp/ie6/IE6\\ -\\ WinXP.ova --delete 'IE6 - WinXP'\"\nsleep 30\nsu vbox --shell=/bin/bash -c \"/opt/mkvm.sh /opt/Appliances/xp/ie8/IE8\\ -\\ WinXP.ova --delete 'IE8 - WinXP'\"\nsleep 30\n\nsu vbox --shell=/bin/bash -c \"/opt/mkvm.sh /opt/Appliances/win7/ie8/IE8\\ -\\ Win7.ova --delete 'IE8 - Win7'\"\nsleep 30\nsu vbox --shell=/bin/bash -c \"/opt/mkvm.sh /opt/Appliances/win7/ie9/IE9\\ -\\ Win7.ova --delete 'IE9 - Win7'\"\nsleep 30\nsu vbox --shell=/bin/bash -c \"/opt/mkvm.sh /opt/Appliances/win7/ie10/IE10\\ -\\ Win7.ova --delete 'IE10 - Win7'\"\nsleep 30\nsu vbox --shell=/bin/bash -c \"/opt/mkvm.sh /opt/Appliances/win7/ie11/IE11\\ -\\ Win7.ova --delete 'IE11 - Win7'\"\nsleep 30\n\nsu vbox --shell=/bin/bash -c \"/opt/mkvm.sh /opt/Appliances/vista/ie7/IE7\\ -\\ Vista.ova --delete 'IE7 - Vista Clone'\"\nsleep 30\n\nsu vbox --shell=/bin/bash -c \"/opt/mkvm.sh /opt/Appliances/win8/ie10/IE10\\ -\\ Win8.ova --delete 'IE10 - Win8'\"\nsleep 30\nsu vbox --shell=/bin/bash -c \"/opt/mkvm.sh /opt/Appliances/win8/ie11/IE11\\ -\\ Win8.1.ova --delete 'IE11 - Win8.1'\"\nsleep 30\n"
  },
  {
    "path": "mkvm_cronjob",
    "content": "# /etc/cron.d/mkvm\n# cron entry for recreate modern.ie VMs\n\n# m h  dom mon dow  user  command\n0 3 1 * * root /opt/mkvm_cron.sh\n"
  }
]