VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/installer-utils.sh@ 37549

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

Ran the source code massager (scm).

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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
16setup_normal_input_install_udev() {
17 TEST_UDEV_VERSION="$1" # udev version to simulate
18 eval 'my_which() { which "$@" ; }'
19 eval 'my_test() { test "$@" ; }'
20 eval 'my_rm() { rm "$@" ; }'
21}
22
23setup_normal_input_install_udev
24
25setup_test_input_install_udev() {
26 TEST_NAME="$1" # used to identify the current test
27 TEST_UDEV_VERSION="$2" # udev version to simulate
28 eval 'my_which() { echo test_udev ; }'
29 eval 'my_test() { true ; }'
30 eval 'my_rm() { case "$2" in "/etc/udev/rules.d/60-vboxdrv.rules") true ;; *) echo "rm: bad file name \"$2\"!"; false ;; esac ; }'
31 eval 'test_udev() { echo "$TEST_UDEV_VERSION" ; }'
32 DELETED_UDEV_FILE=""
33}
34
35udev_write_vboxdrv() {
36 VBOXDRV_GRP="$1"
37 VBOXDRV_MODE="$2"
38
39 echo "KERNEL==\"vboxdrv\", NAME=\"vboxdrv\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
40}
41
42udev_write_usb() {
43 INSTALLATION_DIR="$1"
44 USB_GROUP="$2"
45
46 echo "SUBSYSTEM==\"usb_device\", ACTION==\"add\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
47 echo "SUBSYSTEM==\"usb\", ACTION==\"add\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
48 echo "SUBSYSTEM==\"usb_device\", ACTION==\"remove\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
49 echo "SUBSYSTEM==\"usb\", ACTION==\"remove\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
50}
51
52install_udev() {
53 # install udev rule (disable with INSTALL_NO_UDEV=1 in /etc/default/virtualbox) for distribution packages
54 VBOXDRV_GRP="$1" # The group owning the vboxdrv device
55 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device
56 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
57 USB_GROUP="$4" # The group that has permission to access USB devices
58 NO_INSTALL="$5" # Set this to "1" to remove but not re-install rules
59
60 # Extra space!
61 case "$USB_GROUP" in ?*) USB_GROUP=" $USB_GROUP" ;; esac
62 case "$NO_INSTALL" in
63 "1") ;;
64 *)
65 if my_test -d /etc/udev/rules.d; then
66 udev_call=""
67 udev_app=`my_which udevadm 2> /dev/null`
68 if [ $? -eq 0 ]; then
69 udev_call="${udev_app} version 2> /dev/null"
70 else
71 udev_app=`my_which udevinfo 2> /dev/null`
72 if [ $? -eq 0 ]; then
73 udev_call="${udev_app} -V 2> /dev/null"
74 fi
75 fi
76 udev_fix=""
77 if [ "${udev_call}" != "" ]; then
78 udev_out=`${udev_call}`
79 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
80 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
81 udev_fix="1"
82 fi
83 udev_do_usb=""
84 if [ "$udev_ver" -ge 59 ]; then
85 udev_do_usb="1"
86 fi
87 fi
88 case "$udev_fix" in
89 "1")
90 udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE" |
91 sed 's/\([^+=]*\)[+=]*\([^"]*"[^"]*"\)/\1=\2/g'
92 ;;
93 *)
94 udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE"
95 case "$udev_do_usb" in "1")
96 udev_write_usb "$INSTALLATION_DIR" "$USB_GROUP" ;;
97 esac
98 ;;
99 esac
100
101 fi
102 ;;
103 esac
104 # Remove old udev description file
105 if my_test -f /etc/udev/rules.d/60-vboxdrv.rules; then
106 my_rm -f /etc/udev/rules.d/60-vboxdrv.rules 2> /dev/null
107 fi
108}
109
110cleanup_test_input_install_udev() {
111 setup_normal_input_install_udev
112 unset test_udev
113 DELETED_UDEV_FILE=""
114}
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