WinRb/vagrant-windows — pull request #102 by rivy (2013-09-25 23:12:47+00:00)
Title: ADDED: XP/2003 guest OS support (includes :share_name option for config.vm.synced_folder)

I needed to do some testing on XP VMs, and wanted a repeatable environment. So, I took a couple of weekends, learned a little Ruby, learned a little about Vagrant and vagrant-windows, and then hacked together support for XP & 2003. Detailed information about the changes are included below in the commit message. Please excuse any "unusual" Ruby code, as I haven't had the opportunity to learn all the common idioms.

For some initial, rough notes on setting up an XP/2003 VM in VirtualBox for packaging, see https://gist.github.com/rivy/85f2bdf853af7bf267ef. Included within the notes are some pointers for building an XPMode installation, as well.

This is working well for me; I hope it's helpful to the general community.
\--
Roy Ivy III

## COMMIT

ADDED: XP/2003 guest OS support (includes :share_name option for config.vm.synced_folder, allowing provider share name customization)

### Detailed Changelog

ADDED: XP/2003 guest OS support
ADDED: option 'share_name:' for config.vm.synced_folder (eg, config.vm.synced_folder ".", "v:", share_name: "vagrant"), which allows replacement of the automatically generated provider share name
BUGFIX: corrected "\/\/" bug in win_friendly_share_id() [in helper.rb]
CHANGE: added full complement of windows path/file reserved characters to transform in win_friendly_share_id() [in helper.rb]
CHANGE: condensed command_alias.ps1 to leave more space to other scripts
CHANGE: condensed mount_volume.ps1.erb script
CHANGE: updated the mount script testing spec

### Summary

XP/2003 support was added by through the use of drive mapping to mount network shares, and using scheduled tasks for persistence across reboots. NOTE: this method also works for all other currently supported Windows versions, as well (tested on XP, 2003.x64, & Win7 [though only with a VirtualBox provider]).

win_friendly_share_id() [in helper.rb] was updated & expanded to transform any reserved windows character to an alternative usable in a windows path name (see [MSDN - Naming Files, Paths, and Namespaces]). This was needed to allow the use of a drive ('v:') as a mount point for config.vm.synced_folder.

Since the current WinRM module can't execute scripts longer than about 3000 characters on the guest (see [WinRb/WinRM - ISSUE: Problem with long powershell scripts]), it was necessary to condense both the command_alias.ps1 (prefixed to all scripts) and mount_volume.ps1.erb scripts. command_alias.ps1 was optimized
down to ~360 characters (from 508); it's a quite simple script, so removing most of the white space and shrinking variable names still leaves readable code. mount_volume.ps1.erb was also optimized to less than 2500 characters.

Additionally, an option 'share_name:' was added to config.vm.synced_folder to allow replacement of the automatically generated provider share name, so that the usual '\\PROVIDERSHARE\vagrant' could be generated even when using the new drive mapping technique to access the provider share.

An example Vagrantfile for an XP/2003 package is @ https://gist.github.com/rivy/c31c107e57a2bd36c2bf

### REFERENCES

URLref: [MSDN - Naming Files, Paths, and Namespaces] http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx @@ http://archive.is/v9UMV @@ http://webcitation.org/6Jtxa0vn3
URLref: [WinRb/WinRM - ISSUE: Problem with long powershell scripts] https://github.com/WinRb/WinRM/issues/41