#!/bin/bash -e
#
# Copyright (C) 2006-2008 Sun Microsystems, Inc.
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation,
# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
# distribution. VirtualBox OSE is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY of any kind.
#

. /usr/share/debconf/confmodule
db_version 2.0
db_capb backup

# check for upgrade, disable this check for now
if false; then
  ver_new=%VER%
  ver_old=`echo $2 | cut -f1 -d"-"`
  if [ -n "$ver_old" -a "$ver_new" == "$ver_old" ]; then
    db_get virtualbox-ose/update_version_change
    db_input critical virtualbox-ose/update_version_change || true
    db_go || true
    db_get virtualbox-ose/update_version_change || true
    if [ "$RET" = false ]; then
      db_stop
      exit 1
    fi
  fi
fi

# check for old installation
if [ -r /etc/vbox/vbox.cfg ]; then
  . /etc/vbox/vbox.cfg
  if [ "x$INSTALL_DIR" != "x" -a -d "$INSTALL_DIR" ]; then
    db_fset virtualbox/old-installation-found seen false || true
    db_input high virtualbox/old-installation-found || true
    db_go || true
    exit 1
  fi
  # we will remove that file in postinst
fi

# check for old vboxdrv modules
if find /lib/modules -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
  # old modules found
  db_get virtualbox-ose/delete-old-modules
  if [ "$RET" = "false" ]; then
    cat << EOF
Old vboxdrv kernel modules found in
EOF
    find /lib/modules -name "vboxdrv\.*" 2>/dev/null|sed "s+\(.*\)+  \1+g"
    cat << EOF
Removing of these modules denied by debconf setting
EOF
  else
    db_input critical virtualbox-ose/delete-old-modules || true
    db_go || true
    db_get virtualbox-ose/delete-old-modules
    if [ "$RET" = "true" ]; then
      find /lib/modules -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
    fi
  fi
fi

#DEBHELPER#

