Automatically set up shared folder environment if running in VirtualBox environment.
authorMichael Prokop <mika@grml.org>
Mon, 11 Jul 2011 15:52:26 +0000 (17:52 +0200)
committerMichael Prokop <mika@grml.org>
Mon, 11 Jul 2011 17:13:31 +0000 (19:13 +0200)
If the Shared Folder configuration is enabled in the host
settings then Grml automatically provides the mountpoint
/media/sf_Shared-Folder enabled if running in VirtualBox
environment and if virtualbox tools and drivers are present.

Acked by: Christian Hofstaedtler <ch@grml.org>

autoconfig
autoconfig.functions
grml-autoconfig

index 3a01933..b4c48a4 100644 (file)
@@ -101,6 +101,7 @@ CONFIG_TIME='yes'             # set clock, check for bootparam utc/gmt [only in
 CONFIG_TIMEZONE='yes'         # get bootparam 'tz' and set it as /etc/localtime [only in live-mode]
 CONFIG_TOHD='yes'             # bootoption tohd=...
 CONFIG_USERFSTAB='yes'        # check for username of uid 1000
+CONFIG_VIRTUALBOX_SHARED_FOLDERS='yes' # set up shared folders in VirtualBox environment
 CONFIG_VNC='yes'              # check for bootparam vnc
 CONFIG_WELCOME='yes'          # play welcome sound (audio)
 CONFIG_WONDERSHAPER='yes'     # start wondershaper with options provided via bootparam
index 04f8088..5e7c807 100755 (executable)
@@ -2300,6 +2300,45 @@ fi # checkbootparam "BOOT_IMAGE=debian2hd
 }
 # }}}
 
+config_virtualbox_shared_folders() {
+if [ -r /proc/acpi/battery/BAT0/info ] && grep -q 'OEM info:.*innotek' /proc/acpi/battery/BAT0/info ; then
+  einfo "VirtualBox detected, trying to set up Shared Folders."
+  if ! modprobe -l | grep -q vboxsf.ko ; then
+    ewarn "vboxsf driver not present, not setting up VirtualBox Shared Folders."
+    eend 0
+  elif ! [ -x /usr/sbin/VBoxService ] ; then
+    ewarn "virtualbox-guest-utils not installed, not setting up VirtualBox Shared Folders."
+    eend 0
+  else
+    eindent
+
+      einfo "Loading vboxsf driver."
+      lsmod | grep -q vboxsf || modprobe vboxsf
+      eend $?
+
+      einfo "Adjusting /dev/vboxguest."
+      chown root:vboxsf /dev/vboxguest
+      chmod 660 /dev/vboxguest
+      eend $?
+
+      if [ -n "$CONFIG_FSTAB_USER" ] ; then
+        fstabuser="$CONFIG_FSTAB_USER"
+      else
+        fstabuser=$(getent passwd 1000 | cut -d: -f1)
+      fi
+      einfo "Adding $fstabuser to group vboxsf."
+      adduser grml vboxsf &>/dev/null
+      eend $?
+
+      einfo "Starting VBoxService."
+      VBoxService >/dev/null &
+      eend $?
+
+    eoutdent
+  fi
+fi
+}
+
 # {{{ Support customization
 config_distri(){
 if checkbootparam 'distri'; then
index 0952394..b15acb0 100755 (executable)
@@ -224,6 +224,8 @@ checkvalue $CONFIG_FIX_UNIONFS && fix_unionfs
 
 checkvalue $CONFIG_915RESOLUTION && config_915resolution
 
+checkvalue $CONFIG_VIRTUALBOX_SHARED_FOLDERS && config_virtualbox_shared_folders
+
 checkvalue $CONFIG_MYPATH && config_mypath
 
 checkvalue $CONFIG_DISTCC && config_distcc