VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/installer-common.sh@ 44760

Last change on this file since 44760 was 44594, checked in by vboxsync, 12 years ago

HostDrivers, Installer/linux: properly handle the unrestricted device

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1# Oracle VM VirtualBox
2# VirtualBox installer shell routines
3#
4
5# Copyright (C) 2007-2011 Oracle Corporation
6#
7# This file is part of VirtualBox Open Source Edition (OSE), as
8# available from http://www.virtualbox.org. This file is free software;
9# you can redistribute it and/or modify it under the terms of the GNU
10# General Public License (GPL) as published by the Free Software
11# Foundation, in version 2 as it comes in the "COPYING" file of the
12# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14#
15
16## @todo Make this file into a script in the VirtualBox lib directory once
17# enough code has been made shared between the different installers.
18
19# This is used for unit testing and will be reset after the file is sourced for
20# test runs.
21unset EXTERN
22
23udev_write_vboxdrv() {
24 VBOXDRV_GRP="$1"
25 VBOXDRV_MODE="$2"
26
27 echo "KERNEL==\"vboxdrv\", NAME=\"vboxdrv\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
28 echo "KERNEL==\"vboxdrvu\", NAME=\"vboxdrvu\", OWNER=\"root\", GROUP=\"root\", MODE=\"0666\""
29 echo "KERNEL==\"vboxnetctl\", NAME=\"vboxnetctl\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
30}
31
32udev_write_usb() {
33 INSTALLATION_DIR="$1"
34 USB_GROUP="$2"
35
36 echo "SUBSYSTEM==\"usb_device\", ACTION==\"add\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
37 echo "SUBSYSTEM==\"usb\", ACTION==\"add\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
38 echo "SUBSYSTEM==\"usb_device\", ACTION==\"remove\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
39 echo "SUBSYSTEM==\"usb\", ACTION==\"remove\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
40}
41
42generate_udev_rule() {
43 VBOXDRV_GRP="$1" # The group owning the vboxdrv device
44 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device
45 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
46 USB_GROUP="$4" # The group that has permission to access USB devices
47 NO_INSTALL="$5" # Set this to "1" to remove but not re-install rules
48 UDEV_STRING="$6" # The output of the udev version command
49
50 # Extra space!
51 case "$USB_GROUP" in ?*) USB_GROUP=" $USB_GROUP" ;; esac
52 case "$NO_INSTALL" in
53 "1") ;;
54 *)
55 udev_ver=`expr "$UDEV_STRING" : '[^0-9]*\([0-9]*\)'`
56 udev_fix=""
57 test "$udev_ver" = "" -o "$udev_ver" -lt 55 &&
58 udev_fix="1"
59 udev_do_usb=""
60 test "$udev_ver" -ge 59 &&
61 udev_do_usb="1"
62 case "$udev_fix" in
63 "1")
64 udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE" |
65 sed 's/\([^+=]*\)[+=]*\([^"]*"[^"]*"\)/\1=\2/g'
66 ;;
67 *)
68 udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE"
69 case "$udev_do_usb" in "1")
70 udev_write_usb "$INSTALLATION_DIR" "$USB_GROUP" ;;
71 esac
72 ;;
73 esac
74 ;;
75 esac
76}
77
78install_udev() {
79 # install udev rule (disable with INSTALL_NO_UDEV=1 in /etc/default/virtualbox) for distribution packages
80 VBOXDRV_GRP="$1" # The group owning the vboxdrv device
81 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device
82 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
83 USB_GROUP="$4" # The group that has permission to access USB devices
84 NO_INSTALL="$5" # Set this to "1" to remove but not re-install rules
85
86 if test -d /etc/udev/rules.d; then
87 udev_out="`udevadm version 2>/dev/null || udevinfo -V 2>/dev/null`"
88 generate_udev_rule "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR" \
89 "$USB_GROUP" "$NO_INSTALL" "$udev_out"
90 fi
91 # Remove old udev description file
92 rm -f /etc/udev/rules.d/60-vboxdrv.rules 2> /dev/null
93}
94
95# Add a unit test if/when needed following the same pattern as for
96# install_udev.
97
98install_create_usb_node_for_sysfs() {
99 # Create a usb device node for a given sysfs path
100 path="$1" # sysfs path for the device
101 usb_createnode="$2" # Path to the USB device node creation script
102 usb_group="$3" # The group to give ownership of the node to
103 if $EXTERN test -r "${path}/dev"; then
104 dev="`$EXTERN cat "${path}/dev" 2> /dev/null`"
105 major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
106 minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
107 class="`$EXTERN cat ${path}/bDeviceClass 2> /dev/null`"
108 $EXTERN sh "${usb_createnode}" "$major" "$minor" "$class" \
109 "${usb_group}" 2>/dev/null
110 fi
111}
112
113# install_device_node_setup contains some aliases for unit testing purposes. # Set them to their normal values here.
114udev_rule_file=/etc/udev/rules.d/10-vboxdrv.rules # Set this to /dev/null
115 # for unit testing
116sysfs_usb_devices="/sys/bus/usb/devices/*"
117
118install_device_node_setup() {
119 # Install udev rules and create device nodes for usb access
120 # To unit test, set $EXTERN to point to a function simulating these
121 # functions (defined further up in this file): install_udev;
122 # install_create_usb_node_for_sysfs. See the code for usage.
123 VBOXDRV_GRP="$1" # The group that should own /dev/vboxdrv
124 VBOXDRV_MODE="$2" # The mode to be used for /dev/vboxdrv
125 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
126 USB_GROUP="$4" # The group that should own the /dev/vboxusb device
127 # nodes unless INSTALL_NO_GROUP=1 in
128 # /etc/default/virtualbox. Optional.
129 usb_createnode="$INSTALLATION_DIR/VBoxCreateUSBNode.sh"
130 # install udev rule (disable with INSTALL_NO_UDEV=1 in
131 # /etc/default/virtualbox)
132 if [ "$INSTALL_NO_GROUP" != "1" ]; then
133 usb_group=$USB_GROUP
134 vboxdrv_group=$VBOXDRV_GRP
135 else
136 usb_group=root
137 vboxdrv_group=root
138 fi
139 $EXTERN install_udev "${vboxdrv_group}" "$VBOXDRV_MODE" \
140 "$INSTALLATION_DIR" "${usb_group}" \
141 "$INSTALL_NO_UDEV" > ${udev_rule_file}
142 # Build our device tree
143 for i in ${sysfs_usb_devices}; do # This line intentionally without quotes.
144 $EXTERN install_create_usb_node_for_sysfs "$i" "${usb_createnode}" \
145 "${usb_group}"
146 done
147}
148
149set_selinux_permissions() {
150 # XXX SELinux: allow text relocation entries
151 INSTALLATION_DIR="$1" # Where the VirtualBox binaries are installed to
152 SHARE_DIR="$2" # Where shared bits are installed to
153 if [ -x /usr/bin/chcon ]; then
154 chcon -t texrel_shlib_t "$INSTALLATION_DIR"/*VBox* > /dev/null 2>&1
155 chcon -t texrel_shlib_t "$INSTALLATION_DIR"/VBoxAuth.so \
156 > /dev/null 2>&1
157 chcon -t texrel_shlib_t "$INSTALLATION_DIR"/VirtualBox.so \
158 > /dev/null 2>&1
159 chcon -t texrel_shlib_t "$INSTALLATION_DIR"/components/VBox*.so \
160 > /dev/null 2>&1
161 chcon -t java_exec_t "$INSTALLATION_DIR"/VirtualBox > /dev/null 2>&1
162 chcon -t java_exec_t "$INSTALLATION_DIR"/VBoxSDL > /dev/null 2>&1
163 chcon -t java_exec_t "$INSTALLATION_DIR"/VBoxHeadless \
164 > /dev/null 2>&1
165 chcon -t java_exec_t "$INSTALLATION_DIR"/VBoxNetDHCP \
166 > /dev/null 2>&1
167 chcon -t java_exec_t "$INSTALLATION_DIR"/VBoxExtPackHelperApp \
168 > /dev/null 2>&1
169 chcon -t java_exec_t "$INSTALLATION_DIR"/vboxwebsrv > /dev/null 2>&1
170 chcon -t java_exec_t "$INSTALLATION_DIR"/webtest > /dev/null 2>&1
171 chcon -t bin_t "$SHARE_DIR"/src/vboxhost/build_in_tmp \
172 > /dev/null 2>&1
173 fi
174}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette