summaryrefslogtreecommitdiff
path: root/debian/prerm.in
blob: 496bbf8ef0b8585d1940a513cce3217220ebe153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh

#
# Copyright (C) 2006-2012 Oracle Corporation
#
# 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 (GPL) 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.
#

# we can be called with the following arguments (6.5 of Debian policy):
#  upgrade:          (new version): upgrade to a new version
#  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

rm -f /etc/udev/rules.d/60-vboxdrv.rules
rm -f /etc/vbox/license_agreed
rm -f /etc/vbox/module_not_compiled

# defaults
[ -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

  # 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
  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
fi

#DEBHELPER#

exit 0