From 1a2e91ac570f63e39d3fb79345462f230be05cfe Mon Sep 17 00:00:00 2001 From: Patrick Debois Date: Sat, 13 Nov 2010 16:43:12 +0100 Subject: [PATCH] Added support to find out the current version of virtualbox in the guest by putting .vbox_version in the sudo user homedir --- Rakefile | 4 +++- lib/veewee/session.rb | 22 ++++++++++++------ templates/CentOS-4.8-i386/postinstall.sh | 23 +++++++++++++++---- templates/CentOS-5.5-i386/postinstall.sh | 18 ++++++++++++--- .../ubuntu-10.04.1-server-i386/postinstall.sh | 10 +++++--- .../ubuntu-10.10-server-i386/postinstall.sh | 10 +++++--- 6 files changed, 66 insertions(+), 21 deletions(-) diff --git a/Rakefile b/Rakefile index 2b00ede6..abcfe068 100644 --- a/Rakefile +++ b/Rakefile @@ -32,6 +32,7 @@ lib_dir= File.expand_path(File.join(veewee_dir, "lib")) box_dir= File.expand_path(File.join(veewee_dir, "boxes")) template_dir=File.expand_path(File.join(veewee_dir, "templates")) vbox_dir=File.expand_path(File.join(veewee_dir, "tmp")) +tmp_dir=File.expand_path(File.join(veewee_dir, "tmp")) iso_dir=File.expand_path(File.join(veewee_dir, "iso")) ENV['VBOX_USER_HOME']=vbox_dir @@ -40,7 +41,8 @@ Dir.glob(File.join(lib_dir, '**','*.rb')).each {|f| require f } #Initialize -Veewee::Session.setenv({:veewee_dir => veewee_dir, :definition_dir => definition_dir, :template_dir => template_dir, :iso_dir => iso_dir, :box_dir => box_dir}) +Veewee::Session.setenv({:veewee_dir => veewee_dir, :definition_dir => definition_dir, + :template_dir => template_dir, :iso_dir => iso_dir, :box_dir => box_dir, :tmp_dir => tmp_dir}) desc 'Default: list templates' task :default => [:templates] diff --git a/lib/veewee/session.rb b/lib/veewee/session.rb index 9ca70a0b..13725b2d 100644 --- a/lib/veewee/session.rb +++ b/lib/veewee/session.rb @@ -17,6 +17,7 @@ def self.setenv(env) @template_dir=env[:template_dir] @box_dir=env[:box_dir] @iso_dir=env[:iso_dir] + @tmp_dir=env[:tmp_dir] end def self.declare(options) @@ -188,19 +189,26 @@ def self.build(boxname) end #initial Transaction Veewee::Ssh.when_ssh_login_works("localhost",ssh_options) do + + #Transfer version of Virtualbox to $HOME/.vbox_version + versionfile=File.join(@tmp_dir,".vbox_version") + File.open(versionfile, 'w') {|f| f.write("#{VirtualBox::Global.global.lib.virtualbox.version}") } + Veewee::Ssh.transfer_file("localhost",versionfile,ssh_options) + counter=0 @definition[:postinstall_files].each do |postinstall_file| - filename=File.join(@definition_dir,boxname,postinstall_file) + filename=File.join(@definition_dir,boxname,postinstall_file) transaction(boxname,"#{counter}-#{filename}","postinstall") do - Veewee::Ssh.transfer_file("localhost",filename,ssh_options) - command=@definition[:sudo_cmd] - command.gsub!(/%p/,"#{@definition[:ssh_password]}") + + Veewee::Ssh.transfer_file("localhost",filename,ssh_options) + command=@definition[:sudo_cmd] + command.gsub!(/%p/,"#{@definition[:ssh_password]}") command.gsub!(/%u/,"#{@definition[:ssh_user]}") command.gsub!(/%f/,"#{postinstall_file}") - Veewee::Ssh.execute("localhost","#{command}",ssh_options) - counter+=1 + Veewee::Ssh.execute("localhost","#{command}",ssh_options) + counter+=1 end end end @@ -380,7 +388,7 @@ def self.transaction(boxname,name,checksum_params, &block) end end - #VirtualBox::Global.global.lib.virtualbox.version + def self.list_ostypes puts diff --git a/templates/CentOS-4.8-i386/postinstall.sh b/templates/CentOS-4.8-i386/postinstall.sh index 0cf79e5a..2e4c9ad8 100644 --- a/templates/CentOS-4.8-i386/postinstall.sh +++ b/templates/CentOS-4.8-i386/postinstall.sh @@ -7,16 +7,24 @@ yum -y install gcc bzip2 make kernel-devel-`uname -r` #yum -y upgrade yum -y install gcc-c++ zlib-devel openssl-devel readline-devel sqlite3-devel + +yum -y erase wireless-tools gtk2 libX11 hicolor-icon-theme avahi freetype bitstream-vera-fonts #Installing ruby wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz tar xzvf ruby-enterprise-1.8.7-2010.02.tar.gz ./ruby-enterprise-1.8.7-2010.02/installer -a /opt/ruby echo 'PATH=$PATH:/opt/ruby/bin/'> /etc/profile.d/rubyenterprise.sh +rm -rf ./ruby-enterprise-1.8.7-2010.02/ +rm ruby-enterprise-1.8.7-2010.02.tar.gz #Installing chef /opt/ruby/bin/gem install chef +#Enable sudo +echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +# Defaults requiretty + #Installing vagrant keys mkdir /home/vagrant/.ssh chmod 600 /home/vagrant/.ssh @@ -24,13 +32,20 @@ cd /home/vagrant/.ssh wget --no-check-certificate 'http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub' -O authorized_keys chown -R vagrant /home/vagrant/.ssh +VBOX_VERSION=$(cat /home/vagrant/.vbox_version) #INstalling the virtualbox guest additions cd /tmp -wget http://download.virtualbox.org/virtualbox/3.2.8/VBoxGuestAdditions_3.2.8.iso -mount -o loop VBoxGuestAdditions_3.2.8.iso /mnt +wget http://download.virtualbox.org/virtualbox/$VBOX_VERSION/VBoxGuestAdditions_$VBOX_VERSION.iso +mount -o loop VBoxGuestAdditions_$VBOX_VERSION.iso /mnt sh /mnt/VBoxLinuxAdditions-x86.run umount /mnt -poweroff -h +rm VBoxGuestAdditions_$VBOX_VERSION.iso + +#poweroff -h + +exit + + + -exit \ No newline at end of file diff --git a/templates/CentOS-5.5-i386/postinstall.sh b/templates/CentOS-5.5-i386/postinstall.sh index 90517cbf..7bc0eb44 100644 --- a/templates/CentOS-5.5-i386/postinstall.sh +++ b/templates/CentOS-5.5-i386/postinstall.sh @@ -7,16 +7,24 @@ yum -y install gcc bzip2 make kernel-devel-`uname -r` #yum -y upgrade yum -y install gcc-c++ zlib-devel openssl-devel readline-devel sqlite3-devel + +yum -y erase wireless-tools gtk2 libX11 hicolor-icon-theme avahi freetype bitstream-vera-fonts #Installing ruby wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz tar xzvf ruby-enterprise-1.8.7-2010.02.tar.gz ./ruby-enterprise-1.8.7-2010.02/installer -a /opt/ruby echo 'PATH=$PATH:/opt/ruby/bin/'> /etc/profile.d/rubyenterprise.sh +rm -rf ./ruby-enterprise-1.8.7-2010.02/ +rm ruby-enterprise-1.8.7-2010.02.tar.gz #Installing chef /opt/ruby/bin/gem install chef +#Enable sudo +echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +# Defaults requiretty + #Installing vagrant keys mkdir /home/vagrant/.ssh chmod 600 /home/vagrant/.ssh @@ -24,17 +32,21 @@ cd /home/vagrant/.ssh wget --no-check-certificate 'http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub' -O authorized_keys chown -R vagrant /home/vagrant/.ssh +VBOX_VERSION=$(cat /home/vagrant/.vbox_version) #INstalling the virtualbox guest additions cd /tmp -wget http://download.virtualbox.org/virtualbox/3.2.8/VBoxGuestAdditions_3.2.8.iso -mount -o loop VBoxGuestAdditions_3.2.8.iso /mnt +wget http://download.virtualbox.org/virtualbox/$VBOX_VERSION/VBoxGuestAdditions_$VBOX_VERSION.iso +mount -o loop VBoxGuestAdditions_$VBOX_VERSION.iso /mnt sh /mnt/VBoxLinuxAdditions-x86.run umount /mnt -/sbin/shutdown -H now +rm VBoxGuestAdditions_$VBOX_VERSION.iso + +#poweroff -h exit + diff --git a/templates/ubuntu-10.04.1-server-i386/postinstall.sh b/templates/ubuntu-10.04.1-server-i386/postinstall.sh index 60ea730d..714aebdd 100644 --- a/templates/ubuntu-10.04.1-server-i386/postinstall.sh +++ b/templates/ubuntu-10.04.1-server-i386/postinstall.sh @@ -17,6 +17,8 @@ wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.t tar xzvf ruby-enterprise-1.8.7-2010.02.tar.gz ./ruby-enterprise-1.8.7-2010.02/installer -a /opt/ruby echo 'PATH=$PATH:/opt/ruby/bin/'> /etc/profile.d/rubyenterprise.sh +rm -rf ./ruby-enterprise-1.8.7-2010.02/ +rm ruby-enterprise-1.8.7-2010.02.tar.gz #Installing chef /opt/ruby/bin/gem install chef @@ -28,12 +30,14 @@ cd /home/vagrant/.ssh wget --no-check-certificate 'http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub' -O authorized_keys chown -R vagrant /home/vagrant/.ssh +#INstalling the virtualbox guest additions +VBOX_VERSION=$(cat /home/vagrant/.vbox_version) #INstalling the virtualbox guest additions cd /tmp -wget http://download.virtualbox.org/virtualbox/3.2.8/VBoxGuestAdditions_3.2.8.iso -mount -o loop VBoxGuestAdditions_3.2.8.iso /mnt +wget http://download.virtualbox.org/virtualbox/$VBOX_VERSION/VBoxGuestAdditions_$VBOX_VERSION.iso +mount -o loop VBoxGuestAdditions_$VBOX_VERSION.iso /mnt sh /mnt/VBoxLinuxAdditions-x86.run umount /mnt -shutdown -h now +rm VBoxGuestAdditions_$VBOX_VERSION.iso exit \ No newline at end of file diff --git a/templates/ubuntu-10.10-server-i386/postinstall.sh b/templates/ubuntu-10.10-server-i386/postinstall.sh index 60ea730d..714aebdd 100644 --- a/templates/ubuntu-10.10-server-i386/postinstall.sh +++ b/templates/ubuntu-10.10-server-i386/postinstall.sh @@ -17,6 +17,8 @@ wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.t tar xzvf ruby-enterprise-1.8.7-2010.02.tar.gz ./ruby-enterprise-1.8.7-2010.02/installer -a /opt/ruby echo 'PATH=$PATH:/opt/ruby/bin/'> /etc/profile.d/rubyenterprise.sh +rm -rf ./ruby-enterprise-1.8.7-2010.02/ +rm ruby-enterprise-1.8.7-2010.02.tar.gz #Installing chef /opt/ruby/bin/gem install chef @@ -28,12 +30,14 @@ cd /home/vagrant/.ssh wget --no-check-certificate 'http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub' -O authorized_keys chown -R vagrant /home/vagrant/.ssh +#INstalling the virtualbox guest additions +VBOX_VERSION=$(cat /home/vagrant/.vbox_version) #INstalling the virtualbox guest additions cd /tmp -wget http://download.virtualbox.org/virtualbox/3.2.8/VBoxGuestAdditions_3.2.8.iso -mount -o loop VBoxGuestAdditions_3.2.8.iso /mnt +wget http://download.virtualbox.org/virtualbox/$VBOX_VERSION/VBoxGuestAdditions_$VBOX_VERSION.iso +mount -o loop VBoxGuestAdditions_$VBOX_VERSION.iso /mnt sh /mnt/VBoxLinuxAdditions-x86.run umount /mnt -shutdown -h now +rm VBoxGuestAdditions_$VBOX_VERSION.iso exit \ No newline at end of file