VirtualBox

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

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

Installer/linux: nicer test case.

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