Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit: recovered some code, not working though

  • Loading branch information...
commit b18ac613f9fdfef5cb8ca9484e32c47944f2b2fd 0 parents
@jedi4ever authored
3  .gitignore
@@ -0,0 +1,3 @@
+gems/*
+iso/*
+tmp/*
13 README
@@ -0,0 +1,13 @@
+Before we can actually build the boxes, we need to take care of the minimal things to install
+
+0)Have ruby and rubygems working
+
+1)To avoid messing up your installed gems, it's to start from an empty gem list
+$ . veewee.ENV
+
+2)The minimal thing you need is the rake gem
+$ gem install rake
+
+#To avoid needing Root access =>
+3)You would also want to have Virtualbox installed
+curl http://download.virtualbox.org/virtualbox/3.2.10/VirtualBox-3.2.10-66523-OSX.dmg
44 Rakefile
@@ -0,0 +1,44 @@
+base_dir= File.dirname(__FILE__)
+box_definition_dir= File.dirname(__FILE__)+"/"+"definitions"
+
+desc 'Default: list option'
+task :default => [:test]
+
+desc 'Build box'
+task :build, [:box] do |t,args|
+ box=args.box
+ if File.directory?("#{box_definition_dir}/#{box}")
+ if run_box.length!=0
+ puts "Executing #{run_box}"
+ require("#{run_box}")
+ end
+ end
+
+end
+
+desc 'Test box'
+task :test, [:box] do |t,args|
+ system("puppet apply -v --debug --modulepath=#{base_dir}/modules recipe/site.pp")
+end
+
+desc 'List Boxes'
+task :list do
+
+ subdirs=Dir.glob("#{box_definition_dir}/*")
+ subdirs.each do |sub|
+ if File.directory?("#{sub}")
+ run_box=Dir.glob("#{sub}/run.rb")
+ clean_box=Dir.glob("#{sub}/clean.rb")
+ if run_box.length!=0
+ name=sub.sub(/#{box_dir}\//,'')
+ puts "rake run['#{name}']"
+ end
+ if clean_box.length!=0
+ name=sub.sub(/#{box_dir}\//,'')
+ puts "rake clean['#{name}']"
+ end
+ end
+ end
+
+end
+
1  TODO
@@ -0,0 +1 @@
+Maybe use Bittorrent to download iso - http://rubytorrent.rubyforge.org/
0  boxes/.gitignore
No changes.
2  gems/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
2  iso/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
79 lib/sendkeystrokes.rb
@@ -0,0 +1,79 @@
+def send_sequence(vboxcmd,vname,sequence)
+ cmd="";
+ sequence.each { |s|
+ keycodes=string_to_keycode(s)
+ puts keycodes
+ # VBox seems to have issues with sending the scancodes as one big
+ # .join()-ed string. It seems to get them out or order or ignore some.
+ # A workaround is to send the scancodes one-by-one.
+ codes=""
+ for keycode in keycodes.split(' ') do
+ codes=codes+send_keycode(vboxcmd,vname,keycode)
+ end
+ cmd=cmd+codes+" sleep 1;"
+ }
+ return cmd;
+end
+
+def send_keycode(vboxcmd,vname,keycode)
+
+ return "#{vboxcmd} controlvm '#{vname}' keyboardputscancode #{keycode} ;"
+end
+
+def string_to_keycode(thestring)
+
+ #http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
+
+ k=Hash.new
+ k['1'] = '02' ; k['2'] = '03' ; k['3'] = '04'; k['4']= '05' ;k['5']='06'; k['6'] = '07' ; k['7'] = '08'; k['8'] = '09'; k['9']= '0a'; k['0']='0b'; k['-'] = '0c'; k['='] = '0d' ;
+ k['Tab'] = '0f'; k['q'] = '10' ; k['w'] = '11' ; k['e'] = '12'; k['r'] = '13' ; k['t'] = '14' ; k['y'] = '15'; k['u']= '16' ; k['i']='17'; k['o'] = '18' ; k['p'] = '19' ; k['[']='1a'; k[']']='1b'
+ k['Q'] = '2a 10 aa' ; k['W'] = '2a 11 aa' ; k['E'] = '2a 12 aa'; k['R'] = '2a 13 aa' ; k['t'] = '14' ; k['y'] = '15'; k['U']= '2a 16 aa' ; k['i']='17'; k['o'] = '18' ; k['p'] = '19' ;
+
+ k['a'] = '1e'; k['s'] = '1f' ; k['d'] = '20' ; k['f'] = '21'; k['g'] = '22' ; k['h'] = '23' ; k['j'] = '24'; k['k']= '25' ; k['l']='26'; k[';'] = '27' ;k['"']='28';
+ k['a'] = '1e'; k['S'] = '2a 1f aa' ; k['d'] = '20' ; k['f'] = '21'; k['g'] = '22' ; k['h'] = '23' ; k['j'] = '24'; k['k']= '25' ; k['l']='26'; k[';'] = '27' ;k['"']='28';
+
+ k['z'] = '2c'; k['x'] = '2d' ; k['c'] = '2e' ; k['v'] = '2f'; k['b'] = '30' ; k['n'] = '31' ; k['m'] = '32'; k[',']= '33' ; k['.']='34'; k['/'] = '35' ;k[':'] = '2a 27 aa'
+ k['_'] = '2a 0c aa';
+
+ special=Hash.new;
+ special['<Enter>'] = '1c';
+ special['<Backspace>'] = '0e';
+ special['<Spacebar>'] = '39';
+ special['<Return>'] = '1c'
+ special['<Esc>'] = '01';
+
+ keycodes=''
+ thestring.gsub!(/ /,"<Spacebar>")
+
+ until thestring.length == 0
+ nospecial=true;
+ special.keys.each { |key|
+ if thestring.start_with?(key)
+ #take thestring
+ #check if it starts with a special key + pop special string
+ keycodes=keycodes+special[key]+' ';
+ thestring=thestring.slice(key.length,thestring.length-key.length)
+ nospecial=false;
+ break;
+ end
+ }
+ if nospecial
+ keycodes=keycodes+k[thestring.slice(0,1)]+' ';
+ thestring=thestring.slice(1,thestring.length-1)
+ end
+ #else take the character + pop 1 character
+ end
+
+ return keycodes
+end
+
+
+module Puppet::Parser::Functions
+ newfunction(:sendkeystrokes, :type => :rvalue) do |args|
+ vboxcmd= args[0]
+ vname = args[1]
+ keystrokes = args[2]
+ cmd=send_sequence(vboxcmd,vname,keystrokes)
+ return cmd
+ end
+end
140 lib/veewee.rb
@@ -0,0 +1,140 @@
+ENV['GEM_PATH']=File.dirname(__FILE__)
+ENV['GEM_HOME']=File.dirname(__FILE__)
+ENV['VBOX_USER_HOME']=File.dirname(__FILE__)+"/tmp"
+#PATH=$GEM_HOME/bin:$PATH
+
+require 'webrick'
+include WEBrick
+
+exit
+
+class Veewee
+
+ #:vostype -> this is the virtualbox type
+ #
+ def self.contract(options={:vcpu => '1', :vmemory=> '348', :vdisksize => '10140', :isodst => "", :isosrc => "", :isomd5 => "", :bootwait => "30",
+ :vostype => "Ubuntu", :bootcmd => "", :kickport => "", :kickip => "", :vmname => "ubuntu", :hostsshport => "2222", :guestsshport => "22"})
+ puts "it works"
+
+ #Download iso file is not existing
+
+ #Verify the md5
+ if [ options[:isomd5] != ""]
+ puts "we go an isomd5"
+ verify_md5(options[:isodst],options[:isomd5])
+ end
+
+ #Check if exists (remove if wanted)
+ #Create VM unless exits
+ #Add IDE unless exists
+ #Add SATA unless exists
+ #Create Disk unless exists
+ #Add Disk to SATA unless already linked
+ #Add ISO to IDE unless already mounted
+ #Boot VM unless already booted
+ #Wait some time
+ #Send some keystrokes unless ssh exists
+ #Wait for SSH to become alive
+ #Login to the box with username, password
+ #sudo install a minimal chef thing (rvm?)
+ #or example a script as root to care of the minimal fixing
+ #If installed and checks are running
+ #export the box
+
+ end
+
+ def self.verify_md5(filename,checksum)
+ puts "verifying md5 sum"
+ end
+
+ def self.checkiso_exists(filename)
+ puts "verifying if iso exists"
+ puts "potentional ask it to download iso, if ask"
+ end
+
+ def self.install_gems
+ #install vagrant gem
+ #install md5sum? gem
+ #install virtualbox gem
+ end
+
+ def self.find_vbox_cmd
+ #vboxheadless="VBoxHeadless"
+ return "VBoxManage"
+ end
+
+ def self.create_vm(options)
+ #command => "${vboxcmd} createvm --name ${vmname} --ostype ${vostype} --register",
+ #unless => "${vboxcmd} list vms|grep ${vname}"
+ end
+
+ def self.create_disk(options)
+ #command => "${vboxcmd} createhd --filename '${vname}.vdi' --size ${vdisksize}",
+ #unless => "${vboxcmd} showhdinfo '${vname}.vdi'"
+ end
+
+ def self.create_ide(vmname)
+ #command => "${vboxcmd} storagectl '${vname}' --name 'IDE Controller' --add ide",
+ #unless => "${vboxcmd} showvminfo '${vname}' | grep 'IDE Controller' "
+ end
+
+ def self.attach_disk(vmname)
+ #command => "${vboxcmd} storageattach '${vname}' --storagectl 'SATA Controller' --port 0 --device 0 --type hdd --medium '${vname}.vdi'",
+ end
+
+ def self.mount_iso(vmname,isofile)
+ #command => "${vboxcmd} storageattach '${vname}' --storagectl 'IDE Controller' --type dvddrive --port 1 --device 0 --medium '${isodst}' ";
+ end
+
+ def self.create_sata
+ #command => "${vboxcmd} storagectl '${vname}' --name 'SATA Controller' --add sata",
+ #unless => "${vboxcmd} showvminfo '${vname}' | grep 'SATA Controller' ";
+ end
+
+ def self.suppress
+ # command => "${vboxcmd} setextradata global 'GUI/RegistrationData' 'triesLeft=0';
+ # ${vboxcmd} setextradata global 'GUI/UpdateDate' '1 d, 2009-09-20';
+ # ${vboxcmd} setextradata global 'GUI/SuppressMessages' 'confirmInputCapture,remindAboutAutoCapture,remindAboutMouseIntegrationOff';
+
+ end
+
+ def self.set_ssh_port
+ # exec {
+ # "set ssh port":
+ # command => "${vboxcmd} modifyvm '${vname}' --natpf1 'guestssh,tcp,,${hostsshport},,${guestsshport}'",
+ # unless => "${vboxcmd} showvminfo '${vname}'|grep State|grep running"
+ # }
+ end
+
+ def self.wait_for_http(filename,options => {:port => 7777})
+ end
+
+ def self.wait_for_ssh
+ end
+
+end
+
+Veewee.contract
+
+exit
+
+
+
+class FileServlet < WEBrick::HTTPServlet::AbstractServlet
+ def do_GET(request,response)
+ response['Content-Type']='text/plain'
+ response.status = 200
+ displayfile=File.open("/Users/patrick/vagrantbox/files/preseed.cfg",'r')
+ content=displayfile.read()
+ response.body=content
+ sleep 4
+ @@s.shutdown
+ end
+end
+
+@@s= HTTPServer.new(:Port => 7125)
+@@s.mount("/preseed.cfg", FileServlet)
+trap("INT"){@@s.shutdown}
+@@s.start
+
+
14 templates/ubuntu-10-10-64bit/installer.rb
@@ -0,0 +1,14 @@
+Veewee.build( { vmemory => "384", vcpu => "1",
+# isosrc => "http://releases.ubuntu.com/10.10/ubuntu-10.10-server-i386.iso",
+ isosrc => "file:///Users/patrick/vagrantbox/dists/ubuntu-10.10-server-i386.iso",
+ isodst => "/Users/patrick/vagrantbox/downloads/ubuntu-10.10-server-i386.iso",
+ isomd5 => "ce1cee108de737d7492e37069eed538e",
+ vostype => "Ubuntu",
+ bootcmd => [ '<Esc><Esc><Enter>',
+ '/install/vmlinuz noapic preseed/url=http://192.168.2.30:7125/preseed.cfg debian-installer=en_US auto locale=en_US kbd-chooser/method=us ',
+ 'hostname=ubuntu ',
+ 'fb=false debconf/frontend=noninteractive ',
+ 'console-setup/ask_detect=false console-setup/modelcode=pc105 console-setup/layoutcode=us ',
+ 'initrd=/install/initrd.gz -- <Enter>' ],
+ bootwait => "30",
+})
41 templates/ubuntu-10-10-64bit/postinstall.sh
@@ -0,0 +1,41 @@
+#Updating the box
+echo vagrant | sudo -S apt-get -y update
+echo vagrant | sudo -S apt-get -y upgrade"
+
+#Shellutil.comment("installing ruby enterprise")
+echo vagrant|sudo -S apt-get -y install linux-headers-$(uname -r) build-essential
+echo vagrant | sudo -S apt-get -y install zlib1g-dev libssl-dev libreadline5-dev
+echo vagrant | sudo -S wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz
+echo vagrant | sudo -S tar xzvf ruby-enterprise-1.8.7-2010.02.tar.gz
+echo vagrant | sudo -S ./ruby-enterprise-1.8.7-2010.02/installer -a /opt/ruby
+echo vagrant | sudo -S bash -c \"echo 'PATH=$PATH:/opt/ruby/bin/'> /etc/profile.d/rubyenterprise.sh\"
+
+echo vagrant | sudo -S /opt/ruby/bin/gem install chef")
+
+
+thebox.execute("mkdir $HOME/.ssh; cd .ssh ;"+
+wget 'http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub' -O authorized_keys
+/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso
+echo vagrant|sudo -S mount /dev/dvd /mnt
+echo vagrant|sudo -S sh /mnt/VBoxLinuxAdditions-x86.run
+
+currently vagrant has a problem with the machine up, it calculates the wrong port to ssh to poweroff the system
+thebox.execute("echo vagrant| sudo -S shutdown -h now")
+ thebox.wait_for_state("poweroff")
+ Shellutil.execute("echo 'Vagrant::Config.run do |config|' > /tmp/Vagrantfile")
+ Shellutil.execute("echo ' config.ssh.forwarded_port_key = \"ssh\"' >> /tmp/Vagrantfile")
+ Shellutil.execute("echo ' config.vm.forward_port(\"ssh\",22,#{host_port})' >> /tmp/Vagran
+tfile")
+ Shellutil.execute("echo 'end' >> /tmp/Vagrantfile")
+ Shellutil.execute("vagrant package --base #{vmname} --include /tmp/Vagrantfile --output /tm
+p/#{vmname}.box", {:progress => "on"})
+
+ #vagrant export disables the machine
+ thebox.ssh_enable_vmachine({:hostport => host_port , :guestport => 22} )
+
+ end
+ #vagrant box add ubuntu package.box
+ #vagrant init ubuntu
+ #vagrant up
+ #vagrant ssh
+
92 templates/ubuntu-10-10-64bit/preseed.cfg
@@ -0,0 +1,92 @@
+## Options to set on the command line
+d-i debian-installer/locale string en_US
+d-i console-setup/ask_detect boolean false
+d-i console-setup/layout string Belgium
+
+#d-i netcfg/get_hostname string dummy
+d-i netcfg/get_hostname string unassigned-hostname
+d-i netcfg/get_domain string unassigned-domain
+
+# Continue without a default route
+# Not working , specify a dummy in the DHCP
+#d-i netcfg/no_default_route boolean
+
+d-i time/zone string Europe/Brussels
+d-i clock-setup/utc-auto boolean true
+d-i clock-setup/utc boolean true
+
+d-i kbd-chooser/method select Belgian
+
+d-i netcfg/wireless_wep string
+
+d-i base-installer/kernel/override-image string linux-server
+#d-i base-installer/kernel/override-image string linux-image-2.6.32-21-generic
+
+# Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
+d-i debconf debconf/frontend select Noninteractive
+
+d-i pkgsel/install-language-support boolean false
+tasksel tasksel/first multiselect standard, ubuntu-server
+
+#d-i partman-auto/method string regular
+d-i partman-auto/method string lvm
+d-i partman-auto/purge_lvm_from_device boolean true
+
+d-i partman-lvm/confirm boolean true
+d-i partman-auto/choose_recipe select atomic
+
+d-i partman/confirm_write_new_label boolean true
+d-i partman/confirm_nooverwrite boolean true
+d-i partman/choose_partition select finish
+d-i partman/confirm boolean true
+
+#http://ubuntu-virginia.ubuntuforums.org/showthread.php?p=9626883
+#Message: "write the changes to disk and configure lvm preseed"
+#http://serverfault.com/questions/189328/ubuntu-kickstart-installation-using-lvm-waits-for-input
+#preseed partman-lvm/confirm_nooverwrite boolean true
+
+# Write the changes to disks and configure LVM?
+d-i partman-lvm/confirm boolean true
+d-i partman-lvm/confirm_nooverwrite boolean true
+d-i partman-auto-lvm/guided_size string max
+
+## Default user, we can get away with a recipe to change this
+d-i passwd/user-fullname string vagrant
+d-i passwd/username string vagrant
+d-i passwd/user-password password vagrant
+d-i passwd/user-password-again password vagrant
+d-i user-setup/encrypt-home boolean false
+d-i user-setup/allow-password-weak boolean true
+
+## minimum is puppet and ssh and ntp
+# Individual additional packages to install
+d-i pkgsel/include string openssh-server puppet ntp
+
+# Whether to upgrade packages after debootstrap.
+# Allowed values: none, safe-upgrade, full-upgrade
+d-i pkgsel/upgrade select none
+
+d-i grub-installer/only_debian boolean true
+d-i grub-installer/with_other_os boolean true
+d-i finish-install/reboot_in_progress note
+
+#For the update
+d-i pkgsel/update-policy select none
+
+# debconf-get-selections --install
+#Use mirror
+#d-i apt-setup/use_mirror boolean true
+#d-i mirror/country string manual
+#choose-mirror-bin mirror/protocol string http
+#choose-mirror-bin mirror/http/hostname string 192.168.4.150
+#choose-mirror-bin mirror/http/directory string /ubuntu
+#choose-mirror-bin mirror/suite select maverick
+#d-i debian-installer/allow_unauthenticated string true
+
+## Make all apt request proxied by apt-cacher
+#choose-mirror-bin mirror/http/proxy string http://192.168.4.150/
+choose-mirror-bin mirror/http/proxy string
+#d-i mirror/http/proxy string http://192.168.4.150:3142
+
+## Execute the final touches on the machine
+#d-i preseed/late_command string wget -O /target/etc/post-install http://192.168.4.150/post-install ; in-target chmod +x /etc/post-install; in-target sh /etc/post-install
2  tmp/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
7 veewee.ENV
@@ -0,0 +1,7 @@
+export GEM_HOME=`pwd`/gems
+export GEM_PATH=$GEM_HOME
+
+export RUBY_HOME="/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/"
+export PATH=$RUBY_HOME/bin:$PATH
+export PATH=$GEM_HOME/bin:$PATH
+export VBOX_USER_HOME=`pwd`/tmp
Please sign in to comment.
Something went wrong with that request. Please try again.