summaryrefslogtreecommitdiff
path: root/debian/preinst.in
blob: d065ead95fdcf26192d74e515120c6d2a2ae7685 (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
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
#
# 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):
#  install:          (our version): install our version
#  upgrade:          (our version): upgrade to our version
#  abort-upgrade:    (old version): upgrade to a new version failed

# defaults
[ -r /etc/default/virtualbox ] && . /etc/default/virtualbox

if [ "$1" = "install" -o "$1" = "upgrade" ]; then

  . /usr/share/debconf/confmodule
  db_version 2.0
  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
    . /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 critical 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 [ "$INSTALL_NO_VBOXDRV" != "1" ]; then
    if find /lib/modules -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
      # old modules found
      db_get virtualbox/delete-old-modules || true
      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 low virtualbox/delete-old-modules || true
        db_go || true
        db_get virtualbox/delete-old-modules || true
        if [ "$RET" = "true" ]; then
          find /lib/modules -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
          find /lib/modules -name "vboxnetflt\.*" 2>/dev/null|xargs rm -f 2>/dev/null
          find /lib/modules -name "vboxnetadp\.*" 2>/dev/null|xargs rm -f 2>/dev/null
        fi
      fi
    fi
  fi

fi # "$1" = "install" -o "$1" = "upgrade"

#DEBHELPER#