Support automatic execution of scripts on VirtualBox shared folders
authorMichael Prokop <mika@grml.org>
Mon, 24 Feb 2014 14:24:22 +0000 (15:24 +0100)
committerMichael Prokop <mika@grml.org>
Mon, 24 Feb 2014 14:24:22 +0000 (15:24 +0100)
If an executable /media/sf_automation/$distri is present (where
$distri defaults to "grml" if unset) it is automatically executed
during bootup. The '/media/sf_automation' directory corresponds
to a shared folder named "automation" inside VirtualBox (which
has the auto-mount option set inside the VirtualBox configuration
to be useful).

The feature can be disabled via boot option 'novbautomation' and
the path to the automation directory can be controlled via boot
option 'vbautomation' (e.g. 'vbautomation='/media/sf_foobar', so
don't forget the "/media/sf_").

This feature provides a nice way to automate things during bootup
inside VirtualBox without having to adjust any boot options,
while still being able to control the behaviour from the host
system via setup of shared folders.

autoconfig.functions

index f2e48ac..5580812 100755 (executable)
@@ -2265,9 +2265,38 @@ if $VIRTUALBOX ; then
       eend $?
 
       einfo "Starting VBoxService."
-      VBoxService >/dev/null &
+      VBoxService >/dev/null
       eend $?
 
+      local vbox_automation='/media/sf_automation'
+      if checkbootparam 'vbautomation'; then
+        vbox_automation="$(getbootparam 'vbautomation' 2>>$DEBUG)"
+      fi
+
+      local distri="$(getbootparam 'distri' 2>>$DEBUG)"
+      [ -n "$distri" ] || distri='grml'
+
+      if [ -d "${vbox_automation}" ] ; then
+        einfo "Found shared folders automation directory $vbox_automation"
+        eend 0
+
+        eindent
+        if checkbootparam 'novbautomation' ; then
+          einfo "Bootoption novbautomation found. Disabling automation script execution."
+          eend 0
+        else
+          if ! [ -x "${vbox_automation}/${distri}" ] ; then
+            ewarn "Couldn't find an automation script named ${vbox_automation}/${distri}"
+            eend 1
+          else
+            einfo "Executing '${vbox_automation}/${distri}' now:"
+            "${vbox_automation}/${distri}"
+            eend $?
+          fi
+        fi
+        eoutdent
+      fi
+
     eoutdent
   fi
 fi