VirtualBox

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

Last change on this file since 44093 was 39416, checked in by vboxsync, 13 years ago

installer/linux: fix access to /dev/vboxnetctl for development builds

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 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==\"vboxnetctl\", NAME=\"vboxnetctl\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
29}
30
31udev_write_usb() {
32 INSTALLATION_DIR="$1"
33 USB_GROUP="$2"
34
35 echo "SUBSYSTEM==\"usb_device\", ACTION==\"add\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
36 echo "SUBSYSTEM==\"usb\", ACTION==\"add\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
37 echo "SUBSYSTEM==\"usb_device\", ACTION==\"remove\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
38 echo "SUBSYSTEM==\"usb\", ACTION==\"remove\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
39}
40
41generate_udev_rule() {
42 VBOXDRV_GRP="$1" # The group owning the vboxdrv device
43 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device
44 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
45 USB_GROUP="$4" # The group that has permission to access USB devices
46 NO_INSTALL="$5" # Set this to "1" to remove but not re-install rules
47 UDEV_STRING="$6" # The output of the udev version command
48
49 # Extra space!
50 case "$USB_GROUP" in ?*) USB_GROUP=" $USB_GROUP" ;; esac
51 case "$NO_INSTALL" in
52 "1") ;;
53 *)
54 udev_ver=`expr "$UDEV_STRING" : '[^0-9]*\([0-9]*\)'`
55 udev_fix=""
56 test "$udev_ver" = "" -o "$udev_ver" -lt 55 &&
57 udev_fix="1"
58 udev_do_usb=""
59 test "$udev_ver" -ge 59 &&
60 udev_do_usb="1"
61 case "$udev_fix" in
62 "1")
63 udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE" |
64 sed 's/\([^+=]*\)[+=]*\([^"]*"[^"]*"\)/\1=\2/g'
65 ;;
66 *)
67 udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE"
68 case "$udev_do_usb" in "1")
69 udev_write_usb "$INSTALLATION_DIR" "$USB_GROUP" ;;
70 esac
71 ;;
72 esac
73 ;;
74 esac
75}
76
77install_udev() {
78 # install udev rule (disable with INSTALL_NO_UDEV=1 in /etc/default/virtualbox) for distribution packages
79 VBOXDRV_GRP="$1" # The group owning the vboxdrv device
80 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device
81 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
82 USB_GROUP="$4" # The group that has permission to access USB devices
83 NO_INSTALL="$5" # Set this to "1" to remove but not re-install rules
84
85 if test -d /etc/udev/rules.d; then
86 udev_out="`udevadm version 2>/dev/null || udevinfo -V 2>/dev/null`"
87 generate_udev_rule "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR" \
88 "$USB_GROUP" "$NO_INSTALL" "$udev_out"
89 fi
90 # Remove old udev description file
91 rm -f /etc/udev/rules.d/60-vboxdrv.rules 2> /dev/null
92}
93
94# Add a unit test if/when needed following the same pattern as for
95# install_udev.
96
97install_create_usb_node_for_sysfs() {
98 # Create a usb device node for a given sysfs path
99 path="$1" # sysfs path for the device
100 usb_createnode="$2" # Path to the USB device node creation script
101 usb_group="$3" # The group to give ownership of the node to
102 if $EXTERN test -r "${path}/dev"; then
103 dev="`$EXTERN cat "${path}/dev" 2> /dev/null`"
104 major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
105 minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
106 class="`$EXTERN cat ${path}/bDeviceClass 2> /dev/null`"
107 $EXTERN sh "${usb_createnode}" "$major" "$minor" "$class" \
108 "${usb_group}" 2>/dev/null
109 fi
110}
111
112# install_device_node_setup contains some aliases for unit testing purposes. # Set them to their normal values here.
113udev_rule_file=/etc/udev/rules.d/10-vboxdrv.rules # Set this to /dev/null
114 # for unit testing
115sysfs_usb_devices="/sys/bus/usb/devices/*"
116
117install_device_node_setup() {
118 # Install udev rules and create device nodes for usb access
119 # To unit test, set $EXTERN to point to a function simulating these
120 # functions (defined further up in this file): install_udev;
121 # install_create_usb_node_for_sysfs. See the code for usage.
122 VBOXDRV_GRP="$1" # The group that should own /dev/vboxdrv
123 VBOXDRV_MODE="$2" # The mode to be used for /dev/vboxdrv
124 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
125 USB_GROUP="$4" # The group that should own the /dev/vboxusb device
126 # nodes unless INSTALL_NO_GROUP=1 in
127 # /etc/default/virtualbox. Optional.
128 usb_createnode="$INSTALLATION_DIR/VBoxCreateUSBNode.sh"
129 # install udev rule (disable with INSTALL_NO_UDEV=1 in
130 # /etc/default/virtualbox)
131 if [ "$INSTALL_NO_GROUP" != "1" ]; then
132 usb_group=$USB_GROUP
133 vboxdrv_group=$VBOXDRV_GRP
134 else
135 usb_group=root
136 vboxdrv_group=root
137 fi
138 $EXTERN install_udev "${vboxdrv_group}" "$VBOXDRV_MODE" \
139 "$INSTALLATION_DIR" "${usb_group}" \
140 "$INSTALL_NO_UDEV" > ${udev_rule_file}
141 # Build our device tree
142 for i in ${sysfs_usb_devices}; do # This line intentionally without quotes.
143 $EXTERN install_create_usb_node_for_sysfs "$i" "${usb_createnode}" \
144 "${usb_group}"
145 done
146}
147
148set_selinux_permissions() {
149 # XXX SELinux: allow text relocation entries
150 INSTALLATION_DIR="$1" # Where the VirtualBox binaries are installed to
151 SHARE_DIR="$2" # Where shared bits are installed to
152 if [ -x /usr/bin/chcon ]; then
153 chcon -t texrel_shlib_t "$INSTALLATION_DIR"/*VBox* > /dev/null 2>&1
154 chcon -t texrel_shlib_t "$INSTALLATION_DIR"/VBoxAuth.so \
155 > /dev/null 2>&1
156 chcon -t texrel_shlib_t "$INSTALLATION_DIR"/VirtualBox.so \
157 > /dev/null 2>&1
158 chcon -t texrel_shlib_t "$INSTALLATION_DIR"/components/VBox*.so \
159 > /dev/null 2>&1
160 chcon -t java_exec_t "$INSTALLATION_DIR"/VirtualBox > /dev/null 2>&1
161 chcon -t java_exec_t "$INSTALLATION_DIR"/VBoxSDL > /dev/null 2>&1
162 chcon -t java_exec_t "$INSTALLATION_DIR"/VBoxHeadless \
163 > /dev/null 2>&1
164 chcon -t java_exec_t "$INSTALLATION_DIR"/VBoxNetDHCP \
165 > /dev/null 2>&1
166 chcon -t java_exec_t "$INSTALLATION_DIR"/VBoxExtPackHelperApp \
167 > /dev/null 2>&1
168 chcon -t java_exec_t "$INSTALLATION_DIR"/vboxwebsrv > /dev/null 2>&1
169 chcon -t java_exec_t "$INSTALLATION_DIR"/webtest > /dev/null 2>&1
170 chcon -t bin_t "$SHARE_DIR"/src/vboxhost/build_in_tmp \
171 > /dev/null 2>&1
172 fi
173}
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