Index: /trunk/src/VBox/Installer/linux/debian/postinst.in
===================================================================
--- /trunk/src/VBox/Installer/linux/debian/postinst.in	(revision 57887)
+++ /trunk/src/VBox/Installer/linux/debian/postinst.in	(revision 57888)
@@ -90,82 +90,40 @@
 #DEBHELPER#
 
-if [ "$1" = "configure" ]; then
-  # Start vboxdrv/vboxballoonctrl/vboxweb-service manually as we use our own error handling in postrm
-  if [ -x "/etc/init.d/vboxdrv" ]; then
-    update-rc.d vboxdrv defaults 20 80 >/dev/null
-
-    BUILD_MODULES=0
-    REGISTER_MODULES=1
-    # Disable module compilation with INSTALL_NO_VBOXDRV=1 in /etc/default/virtualbox
-    if [ ! -f /lib/modules/`uname -r`/misc/vboxdrv.ko ]; then
-      REGISTER_MODULES=0
-      if [ "$INSTALL_NO_VBOXDRV" != "1" ]; then
-        db_get virtualbox/module-compilation-allowed
-        if [ "$RET" = "false" ]; then
-          cat << EOF
+BUILD_MODULES=0
+REGISTER_MODULES=1
+# Disable module compilation with INSTALL_NO_VBOXDRV=1 in /etc/default/virtualbox
+if [ ! -f /lib/modules/`uname -r`/misc/vboxdrv.ko ]; then
+  REGISTER_MODULES=0
+  if [ "$1" = "configure" ]; then
+    if [ "$INSTALL_NO_VBOXDRV" != "1" ]; then
+      db_get virtualbox/module-compilation-allowed
+      if [ "$RET" = "false" ]; then
+        cat << EOF
 Unable to find a precompiled module for the current kernel
 though module compilation denied by debconf setting.
 EOF
-        else
-          db_input low virtualbox/module-compilation-allowed || true
-          db_go || true
-          db_get virtualbox/module-compilation-allowed
-          if [ "$RET" = "true" ]; then
-            BUILD_MODULES=1
-          fi
+      else
+        db_input low virtualbox/module-compilation-allowed || true
+        db_go || true
+        db_get virtualbox/module-compilation-allowed
+        if [ "$RET" = "true" ]; then
+          BUILD_MODULES=1
         fi
       fi
     fi
+  fi # $1 = "configure"
+fi
 
-    if [ $BUILD_MODULES -eq 1 ]; then
-      if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-        invoke-rc.d vboxdrv setup || true
-      else
-        /etc/init.d/vboxdrv setup || true
-      fi
-    else
-      # shipped modules found, register sources at DKMS anyway
-      if lsmod | grep -q "vboxdrv[^_-]"; then
-        /etc/init.d/vboxdrv stop || true
-      fi
-      if [ $REGISTER_MODULES -eq 1 ]; then
-        DKMS=`which dkms 2>/dev/null`
-        if [ -n "$DKMS" ]; then
-          $DKMS add -m vboxhost -v %VER% > /dev/null 2>&1 || true
-        fi
-      fi
-      if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-        invoke-rc.d vboxdrv start || exit $?
-      else
-        /etc/init.d/vboxdrv start || exit $?
-      fi
-    fi
-  fi
-  if [ -x "/etc/init.d/vboxballoonctrl-service" ]; then
-    update-rc.d vboxballoonctrl-service defaults 35 65 >/dev/null
-    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-        invoke-rc.d vboxballoonctrl-service start || exit $?
-    else
-        /etc/init.d/vboxballoonctrl-service start || exit $?
-    fi
-  fi
-  if [ -x "/etc/init.d/vboxautostart-service" ]; then
-    update-rc.d vboxautostart-service defaults 35 65 >/dev/null
-    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-        invoke-rc.d vboxautostart-service start || exit $?
-    else
-        /etc/init.d/vboxautostart-service start || exit $?
-    fi
-  fi
-  if [ -x "/etc/init.d/vboxweb-service" ]; then
-    update-rc.d vboxweb-service defaults 35 65 >/dev/null
-    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-        invoke-rc.d vboxweb-service start || exit $?
-    else
-        /etc/init.d/vboxweb-service start || exit $?
-    fi
-  fi
+if [ $BUILD_MODULES -eq 1 ]; then
+  /usr/lib/virtualbox/vboxdrv.sh setup || true
+fi
 
-fi # $1 = "configure"
+# Install and start the new service scripts.
+PRERM_DKMS=
+test "${REGISTER_MODULES}" = 1 && PRERM_DKMS="--dkms %VER%"
+POSTINST_START=--start
+test "${INSTALL_NO_VBOXDRV}" = 1 && POSTINST_START=
+/usr/lib/virtualbox/prerm-common.sh ${PRERM_DKMS} || true
+/usr/lib/virtualbox/postinst-common.sh /usr/lib/virtualbox "${POSTINST_START}" > /dev/null || true
 
 exit 0
Index: /trunk/src/VBox/Installer/linux/debian/preinst.in
===================================================================
--- /trunk/src/VBox/Installer/linux/debian/preinst.in	(revision 57887)
+++ /trunk/src/VBox/Installer/linux/debian/preinst.in	(revision 57888)
@@ -26,33 +26,4 @@
   db_capb backup
 
-  # check for active VMs
-  VBOXSVC_PID=`pidof VBoxSVC 2> /dev/null || true`
-  if [ -n "$VBOXSVC_PID" ]; then
-    if [ -f /etc/init.d/vboxballoonctrl-service ]; then
-      # try graceful termination; terminate the ballon control service first
-      if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-        invoke-rc.d vboxballoonctrl-service stop || true
-      else
-        /etc/init.d/vboxballoonctrl-service stop || true
-      fi
-    fi
-    if [ -f /etc/init.d/vboxweb-service ]; then
-      # try graceful termination; terminate the webservice first
-      if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-        invoke-rc.d vboxweb-service stop || true
-      else
-        /etc/init.d/vboxweb-service stop || true
-      fi
-    fi
-    kill -USR1 $VBOXSVC_PID
-    sleep 1
-    if pidof VBoxSVC > /dev/null 2>&1; then
-      db_fset virtualbox/old-running seen false || true
-      db_input critical virtualbox/old-running || true
-      db_go || true
-      exit 1
-    fi
-  fi
-
   # check for old installation
   if [ -r /etc/vbox/vbox.cfg ]; then
@@ -65,4 +36,27 @@
     fi
     # we will remove that file in postinst
+  fi
+
+  # check for active VMs
+  # Execute the installed package's pre-uninstaller if present.
+  /usr/lib/virtualbox/prerm-common.sh 2>/dev/null || true
+  # Stop services from older versions without pre-uninstaller.
+  invoke-rc.d vboxballoonctrl-service stop 2>/dev/null || true
+  /etc/init.d/vboxballoonctrl-service stop 2>/dev/null || true
+  invoke-rc.d vboxautostart-service stop 2>/dev/null || true
+  /etc/init.d/vboxautostart-service stop 2>/dev/null || true
+  invoke-rc.d vboxweb-service stop 2>/dev/null || true
+  /etc/init.d/vboxweb-service stop 2>/dev/null || true
+  VBOXSVC_PID=`pidof VBoxSVC 2>/dev/null || true`
+  if [ -n "$VBOXSVC_PID" ]; then
+    # ask the daemon to terminate immediately
+    kill -USR1 $VBOXSVC_PID
+    sleep 1
+    if pidof VBoxSVC > /dev/null 2>&1; then
+      db_fset virtualbox/old-running seen false || true
+      db_input critical virtualbox/old-running || true
+      db_go || true
+      exit 1
+    fi
   fi
 
Index: /trunk/src/VBox/Installer/linux/debian/prerm.in
===================================================================
--- /trunk/src/VBox/Installer/linux/debian/prerm.in	(revision 57887)
+++ /trunk/src/VBox/Installer/linux/debian/prerm.in	(revision 57888)
@@ -17,5 +17,4 @@
 #  failed-upgrade:   (our version): failed to upgrade
 #  remove:           (our version): remove this package
-#  purge:            (our version): purge this package
 #  deconfigure:      (our version): removing conflicting version
 
@@ -27,59 +26,15 @@
 [ -r /etc/default/virtualbox ] && . /etc/default/virtualbox
 
-if [ "$1" = "upgrade" -o "$1" = "remove" -o "$1" = "failed-upgrade" ]; then
-  . /usr/share/debconf/confmodule
-  db_version 2.0
-  db_capb backup
+. /usr/share/debconf/confmodule
+db_version 2.0
+db_capb backup
 
-  # check for active VMs
-  VBOXSVC_PID=`pidof VBoxSVC 2>/dev/null`
-  if [ -n "$VBOXSVC_PID" ]; then
-    # try graceful termination; terminate the balloon control servic first
-    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-      invoke-rc.d vboxballoonctrl-service stop || true
-    else
-      /etc/init.d/vboxballoonctrl-service stop || true
-    fi
-    # try graceful termination; terminate the webservice first
-    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-      invoke-rc.d vboxweb-service stop || true
-    else
-      /etc/init.d/vboxweb-service stop || true
-    fi
-    kill -USR1 $VBOXSVC_PID
-    sleep 1
-    if pidof VBoxSVC > /dev/null 2>&1; then
-      if [ "$1" != "failed-upgrade" ]; then
-        db_fset virtualbox/old-running seen false || true
-        db_input critical virtualbox/old-running || true
-        db_go || true
-      fi
-      exit 1
-    fi
+if ! /usr/lib/virtualbox/prerm-common.sh --dkms %VER% > /dev/null 2>&1; then
+  if [ "$1" != "failed-upgrade" ]; then
+    db_fset virtualbox/old-running seen false || true
+    db_input critical virtualbox/old-running || true
+    db_go || true
   fi
-fi
-
-# make sure we de-register the DMKS modules before the files get removed
-if [ "$1" = "upgrade" -o "$1" = "remove" -o "$1" = "deconfigure" ]; then
-  DKMS=`which dkms 2>/dev/null`
-  if [ -n "$DKMS" ]; then
-    $DKMS remove -m vboxhost -v %VER% --all > /dev/null 2>&1 || true
-  fi
-fi
-
-# stop vboxnet/vboxdrv manually as we use our own error handling in postrm
-if [ -x "/etc/init.d/vboxdrv" ]; then
-  if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-    invoke-rc.d vboxdrv stop || exit $?
-  else
-    /etc/init.d/vboxdrv stop || exit $?
-  fi
-fi
-if [ -x "/etc/init.d/vboxnet" ]; then
-  if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-    invoke-rc.d vboxnet stop || exit $?
-  else
-    /etc/init.d/vboxnet stop || exit $?
-  fi
+  exit 1
 fi
 
Index: /trunk/src/VBox/Installer/linux/debian/rules
===================================================================
--- /trunk/src/VBox/Installer/linux/debian/rules	(revision 57887)
+++ /trunk/src/VBox/Installer/linux/debian/rules	(revision 57888)
@@ -242,6 +242,4 @@
 	mv $(archdir) $(prefix)/usr/lib/$(package)
 	ln -s ../VBoxVMM.so $(prefix)/usr/lib/$(package)/components/VBoxVMM.so
-	mkdir $(prefix)/sbin
-	ln -s ../etc/init.d/vboxdrv $(prefix)/sbin/rcvboxdrv
 	rmdir $(prefix)/opt
 	dh_desktop
@@ -253,12 +251,8 @@
 	    -e "s|%VERSION%|$(VBOX_VERSION_STRING)|g" \
 	    -e "s|%GROUP%|$(if $(VBOX_WITHOUT_HARDENING),vboxusers,root)|g" \
-	    $(vboxroot)/src/VBox/Installer/linux/vboxdrv.sh.in > debian/vboxdrv.init
-	dh_installinit --name=vboxdrv --noscripts
-	cp $(vboxroot)/src/VBox/Installer/linux/vboxballoonctrl-service.sh debian/vboxballoonctrl-service.init
-	dh_installinit --name=vboxballoonctrl-service --noscripts
-	cp $(vboxroot)/src/VBox/Installer/linux/vboxautostart-service.sh debian/vboxautostart-service.init
-	dh_installinit --name=vboxautostart-service --noscripts
-	cp $(vboxroot)/src/VBox/Installer/linux/vboxweb-service.sh debian/vboxweb-service.init
-	dh_installinit --name=vboxweb-service --noscripts
+	    $(vboxroot)/src/VBox/Installer/linux/vboxdrv.sh.in > $(prefix)/usr/lib/$(package)/vboxdrv.sh
+	cp $(vboxroot)/src/VBox/Installer/linux/vboxballoonctrl-service.sh $(prefix)/usr/lib/$(package)
+	cp $(vboxroot)/src/VBox/Installer/linux/vboxautostart-service.sh $(prefix)/usr/lib/$(package)
+	cp $(vboxroot)/src/VBox/Installer/linux/vboxweb-service.sh $(prefix)/usr/lib/$(package)
 	sed -e 's|%VER%|$(debver)|g' \
 	    -e 's|%DATE%|$(shell date -R)|g' \
