summaryrefslogtreecommitdiffstats
path: root/src/VBox/Installer/linux/postinst-common.sh
blob: 37e1a710c43fbbadb0fc9cec8381704c5197fe81 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
# $Id: postinst-common.sh $
## @file
# Oracle VM VirtualBox
# VirtualBox Linux post-installer common portions
#

#
# Copyright (C) 2015-2023 Oracle and/or its affiliates.
#
# This file is part of VirtualBox base platform packages, as
# available from https://www.virtualbox.org.
#
# This program 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 3 of the
# License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses>.
#
# SPDX-License-Identifier: GPL-3.0-only
#

# Put bits of the post-installation here which should work the same for all of
# the Linux installers.  We do not use special helpers (e.g. dh_* on Debian),
# but that should not matter, as we know what those helpers actually do, and we
# have to work on those systems anyway when installed using the all
# distributions installer.
#
# We assume that all required files are in the same folder as this script
# (e.g. /opt/VirtualBox, /usr/lib/VirtualBox, the build output directory).

# The below is GNU-specific.  See VBox.sh for the longer Solaris/OS X version.
TARGET=`readlink -e -- "${0}"` || exit 1
MY_PATH="${TARGET%/[!/]*}"
cd "${MY_PATH}"
. "./routines.sh"

START=true
while test -n "${1}"; do
    case "${1}" in
        --nostart)
            START=
            ;;
        *)
            echo "Bad argument ${1}" >&2
            exit 1
            ;;
    esac
    shift
done

# Remove any traces of DKMS from previous installations.
for i in vboxhost vboxdrv vboxnetflt vboxnetadp; do
    rm -rf "/var/lib/dkms/${i}"*
done

# Install runlevel scripts and systemd unit files
install_init_script "${MY_PATH}/vboxdrv.sh" vboxdrv
install_init_script "${MY_PATH}/vboxballoonctrl-service.sh" vboxballoonctrl-service
install_init_script "${MY_PATH}/vboxautostart-service.sh" vboxautostart-service
install_init_script "${MY_PATH}/vboxweb-service.sh" vboxweb-service
finish_init_script_install

delrunlevel vboxdrv
addrunlevel vboxdrv
delrunlevel vboxballoonctrl-service
addrunlevel vboxballoonctrl-service
delrunlevel vboxautostart-service
addrunlevel vboxautostart-service
delrunlevel vboxweb-service
addrunlevel vboxweb-service

ln -sf "${MY_PATH}/postinst-common.sh" /sbin/vboxconfig

# Set SELinux permissions
# XXX SELinux: allow text relocation entries
if [ -x /usr/bin/chcon ]; then
    chcon -t texrel_shlib_t "${MY_PATH}"/*VBox* > /dev/null 2>&1
    chcon -t texrel_shlib_t "${MY_PATH}"/VBoxAuth.so \
        > /dev/null 2>&1
    chcon -t texrel_shlib_t "${MY_PATH}"/VirtualBox.so \
        > /dev/null 2>&1
    chcon -t texrel_shlib_t "${MY_PATH}"/components/VBox*.so \
        > /dev/null 2>&1
    chcon -t java_exec_t    "${MY_PATH}"/VirtualBox > /dev/null 2>&1
    chcon -t java_exec_t    "${MY_PATH}"/VBoxSDL > /dev/null 2>&1
    chcon -t java_exec_t    "${MY_PATH}"/VBoxHeadless \
        > /dev/null 2>&1
    chcon -t java_exec_t    "${MY_PATH}"/VBoxNetDHCP \
        > /dev/null 2>&1
    chcon -t java_exec_t    "${MY_PATH}"/VBoxNetNAT \
        > /dev/null 2>&1
    chcon -t java_exec_t    "${MY_PATH}"/VBoxExtPackHelperApp \
        > /dev/null 2>&1
    chcon -t java_exec_t    "${MY_PATH}"/vboxwebsrv > /dev/null 2>&1
    chcon -t bin_t          "${MY_PATH}"/src/vboxhost/build_in_tmp \
         > /dev/null 2>&1
    chcon -t bin_t          /usr/share/virtualbox/src/vboxhost/build_in_tmp \
         > /dev/null 2>&1
fi

test -n "${START}" &&
{
    if ! "${MY_PATH}/vboxdrv.sh" setup; then
        "${MY_PATH}/check_module_dependencies.sh" >&2
        echo >&2
        echo "There were problems setting up VirtualBox.  To re-start the set-up process, run" >&2
        echo "  /sbin/vboxconfig" >&2
        echo "as root.  If your system is using EFI Secure Boot you may need to sign the" >&2
        echo "kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load" >&2
        echo "them. Please see your Linux system's documentation for more information." >&2
    else
        start_init_script vboxdrv
        start_init_script vboxballoonctrl-service
        start_init_script vboxautostart-service
        start_init_script vboxweb-service
    fi
}