Guest User

Untitled

a guest
Mar 6th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3.  
  4. PASSWORD_PATH = ".password"
  5. PASSWORD_ID_PATH = ".password_id"
  6.  
  7. # Make sure to have installed vagrant-triggers plugin
  8. # > vagrant plugin install vagrant-triggers
  9.  
  10. # After the first `vagrant up` stop the VM and execute the following steps
  11. # Take the identifier of the storage you want to encrypt
  12. # > HDD_UUID=`VBoxManage showvminfo <VM_NAME> | grep 'SATA.*UUID' | sed 's/^.*UUID: \(.*\))/\1/'`
  13. # Store your usernname (whitespaces are not allowed) in a variable
  14. # > USERNAME="<YOUR_USER_NAME_WITHOUT_WHITESPACES>"
  15. # Encrypt the storage, enter the password when asked
  16. # > VBoxManage encryptmedium $HDD_UUID --newpassword - --newpasswordid $USERNAME --cipher "AES-XTS256-PLAIN64"
  17. # Store the username in a file named .password_id
  18. # > echo $USERNAME > .password_id
  19. # Now, the next time you start the VM you'll be asked for the same password
  20.  
  21. Vagrant.configure("2") do |config|
  22. config.vm.box = "ubuntu/vivid64"
  23. config.vm.box_check_update = false
  24. config.vm.hostname = "secure"
  25.  
  26. config.trigger.before :up do
  27. if File.exists?(PASSWORD_ID_PATH)
  28. password_id = File.read(PASSWORD_ID_PATH).strip
  29. print "The VM is encrypted, please enter the password\n#{password_id}: "
  30. password = STDIN.noecho(&:gets).strip
  31. File.write(PASSWORD_PATH, password)
  32. puts ""
  33. end
  34. end
  35.  
  36. config.trigger.after :up do
  37. File.delete(PASSWORD_PATH) if File.exists?(PASSWORD_PATH)
  38. end
  39.  
  40. config.trigger.after :destroy do
  41. File.delete(PASSWORD_ID_PATH) if File.exists?(PASSWORD_ID_PATH)
  42. end
  43.  
  44. config.vm.provider :virtualbox do |vb|
  45. vb.name = "secure"
  46. vb.gui = false
  47.  
  48. if File.exists?(PASSWORD_ID_PATH)
  49. password_id = File.read(PASSWORD_ID_PATH).strip
  50. vb.customize "post-boot", [
  51. "controlvm", :id, "addencpassword", password_id, PASSWORD_PATH, "--removeonsuspend", "yes"
  52. ]
  53. end
  54. end
  55. end
Add Comment
Please, Sign In to add comment