Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/56884


Change subject: Helpers for updating VirtualBox guest additions
......................................................................

Helpers for updating VirtualBox guest additions

This change automates much of the process of keeping VirtualBox guest additions
up-to-date.

* In Vagrantfile, get host's VirtualBox version and add it as a custom fact.
* Write host's VirtualBox version to '/etc/virtualbox-version' on guest.
* Upon starting new interactive shells, check if VirtualBox guest additions are
  missing or out-of-date. If so, prompt user to update.
* Install kernel headers and build-essential, since they are prerequisite for
  building new versions of guest additions.
* Provide a script, 'update-guest-additions', that downloads and installs the
  correct version of VirtualBox guest additions.

Change-Id: I95fca5bd4692eee55de72f82af3035cbd0d3ac6f
---
M Vagrantfile
M puppet/manifests/site.pp
A puppet/modules/misc/files/check-guest-additions.sh
A puppet/modules/misc/files/update-guest-additions
M puppet/modules/misc/manifests/init.pp
A puppet/modules/misc/manifests/virtualbox.pp
6 files changed, 131 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/84/56884/1

diff --git a/Vagrantfile b/Vagrantfile
index 3178932..16001a4 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -1,6 +1,8 @@
 # -*- mode: ruby -*-
 # vi: set ft=ruby :
 
+virtualbox_version = `VBoxManage -v`.gsub(/r.*/m, '')
+
 Vagrant.configure('2') do |config|
 
     config.vm.hostname = 'mediawiki-vagrant'
@@ -48,7 +50,8 @@
         puppet.module_path = 'puppet/modules'
         puppet.manifests_path = 'puppet/manifests'
         puppet.manifest_file = 'site.pp'
-        puppet.options = '--verbose'  # Add '--debug' for more output
+        puppet.options = '--verbose'  # Add ' --debug' for more output
+        puppet.facter = { 'virtualbox_version' => virtualbox_version }
     end
 
 end
diff --git a/puppet/manifests/site.pp b/puppet/manifests/site.pp
index 102f8a2..804ab86 100644
--- a/puppet/manifests/site.pp
+++ b/puppet/manifests/site.pp
@@ -19,10 +19,6 @@
        unless  => 'bash -c \'(( $(date +%s) - $(stat -c %Y 
/var/lib/apt/periodic/update-success-stamp) < 86400 ))\''
 }
 
-package { [ 'virtualbox-guest-dkms', 'virtualbox-guest-utils' ]:
-       ensure => present,
-}
-
 group { 'puppet':
        ensure => present,
 }
diff --git a/puppet/modules/misc/files/check-guest-additions.sh 
b/puppet/modules/misc/files/check-guest-additions.sh
new file mode 100755
index 0000000..b660eb2
--- /dev/null
+++ b/puppet/modules/misc/files/check-guest-additions.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+[ -z "$BASH_VERSION" -o -z "$PS1" ] && return
+
+VIRTUALBOX_VERSION="$(</etc/virtualbox-version)"
+GUEST_ADDITIONS_VERSION="$(modinfo -Fversion vboxguest)"
+
+if [ "$VIRTUALBOX_VERSION" != "$GUEST_ADDITIONS_VERSION" ]; then
+    printf "Your VirtualBox guest additions are out-of-date. Please run 
'$(tput bold; tput setaf 3)update-guest-additions$(tput sgr0)'.\n"
+fi
diff --git a/puppet/modules/misc/files/update-guest-additions 
b/puppet/modules/misc/files/update-guest-additions
new file mode 100755
index 0000000..6bb8e17
--- /dev/null
+++ b/puppet/modules/misc/files/update-guest-additions
@@ -0,0 +1,80 @@
+#!/usr/bin/env bash
+
+VIRTUALBOX_VERSION="$(</etc/virtualbox-version)"
+BASE_URL="http://download.virtualbox.org/virtualbox/${VIRTUALBOX_VERSION}";
+GUEST_ADDITIONS_ISO="VBoxGuestAdditions_${VIRTUALBOX_VERSION}.iso"
+GUEST_ADDITIONS_VERSION="$(modinfo -Fversion vboxguest)"
+
+warn () {
+       printf "$(tput setaf 1)%s$(tput sgr0)\n" "$1" >&2
+}
+
+notice () {
+       printf "$(tput setaf 4)%s$(tput sgr0)\n" "$1"
+}
+
+[[ ! $SUDO_COMMAND ]] && {
+    sudo $0
+    exit $?
+}
+
+# Check if Guest additions need to be updated.
+
+[[ ! $VIRTUALBOX_VERSION ]] && {
+    warn 'Cannot determine host VirtualBox version.'
+    exit 1
+}
+
+[[ $GUEST_ADDITIONS_VERSION == "$VIRTUALBOX_VERSION" && $1 != "--force" ]] && {
+    notice 'Guest additions already up-to-date.' >&2
+    exit 0
+}
+
+
+# Download the Guest additions ISO.
+
+cd /tmp
+notice "Downloading ${GUEST_ADDITIONS_ISO}..."
+curl -LOf "${BASE_URL}/${GUEST_ADDITIONS_ISO}" || {
+    warn 'Unable to retrieve guest additions.'
+    exit 1
+}
+
+
+# Verify integrity of downloaded ISO using MD5 checksum
+
+( curl -Lfs "${BASE_URL}/MD5SUMS" | grep "${GUEST_ADDITIONS_ISO}" | md5sum -c 
) || {
+    warn 'Could not verify data integrity of guest additions ISO.'
+    rm "${GUEST_ADDITIONS_ISO}"
+    exit 1
+}
+
+
+# Mount Guest additions ISO
+
+MOUNTPOINT="$(mktemp -d guest-additions.XXXXXX)"
+mount -o loop,ro "${GUEST_ADDITIONS_ISO}" "${MOUNTPOINT}" || {
+    warn 'Unable to mount guest additions ISO.'
+    exit 1
+}
+
+
+# Purge conflicting packages and ensure pre-requisites are installed.
+
+notice "Installing dependencies..."
+apt-get -y -q install "dkms" "linux-headers-$(uname -r)" || {
+    warn 'Unable to install pre-requisite packages.'
+    exit 1
+}
+notice "Removing conflicting packages..."
+apt-get -y -q purge virtualbox-guest-dkms virtualbox-guest-utils 
virtualbox-guest-x11
+
+
+# Run the installer
+
+notice "Running installer. Ignore any warnings about missing X11."
+cd "${MOUNTPOINT}"
+./VBoxLinuxAdditions.run --nox11 -- --force && {
+    notice 'All done. Shutting down. Run "vagrant up" to start the machine.'
+    shutdown -h now
+}
diff --git a/puppet/modules/misc/manifests/init.pp 
b/puppet/modules/misc/manifests/init.pp
index 0740168..8649577 100644
--- a/puppet/modules/misc/manifests/init.pp
+++ b/puppet/modules/misc/manifests/init.pp
@@ -1,6 +1,8 @@
 # Provides small enhancements to the shell, such as color prompt and MOTD.
 class misc {
 
+       include virtualbox
+
        file { '/etc/profile.d/color.sh':
                ensure => file,
                mode   => '0755',
diff --git a/puppet/modules/misc/manifests/virtualbox.pp 
b/puppet/modules/misc/manifests/virtualbox.pp
new file mode 100644
index 0000000..2d0f804
--- /dev/null
+++ b/puppet/modules/misc/manifests/virtualbox.pp
@@ -0,0 +1,35 @@
+# Declare host's VirtualBox version in /etc/virtualbox-version and provide a
+# shell script for updating VirtualBox guest additions.
+class misc::virtualbox {
+
+       # Upon starting an interactive shell, check guest additions version and
+       # prompt the user to update if out-of-date.
+       file { '/etc/profile.d/check-guest-additions.sh':
+               ensure => file,
+               mode   => '0755',
+               source => 'puppet:///modules/misc/check-guest-additions.sh',
+       }
+
+       # Shell script for updating guest additions.
+       file { '/bin/update-guest-additions':
+               ensure => present,
+               source => 'puppet:///modules/misc/update-guest-additions',
+               owner  => 'root',
+               group  => 'root',
+               mode   => '0755',
+       }
+
+       file { '/etc/virtualbox-version':
+               ensure  => present,
+               content => inline_template("<%= 
scope.lookupvar('::virtualbox_version') %>\n"),
+               owner   => 'root',
+               group   => 'root',
+               mode    => '0444',
+       }
+
+       # Prerequisites for building new versions of guest additions.
+       package { [ 'build-essential', "linux-headers-${::kernelrelease}" ]:
+               ensure => present,
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/56884
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I95fca5bd4692eee55de72f82af3035cbd0d3ac6f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to