VirtualBox

Changeset 38385 in vbox for trunk/src/VBox/Installer/linux


Ignore:
Timestamp:
Aug 9, 2011 4:22:56 PM (13 years ago)
Author:
vboxsync
Message:

Installer/Linux: cleaned up the USB device node installation for the generic installer

Location:
trunk/src/VBox/Installer/linux
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/linux/install.sh

    r37124 r38385  
    442442    fi
    443443
    444     # Create udev description file
    445     install_udev "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR" \
    446         > /etc/udev/rules.d/10-vboxdrv.rules
    447 
    448     # Build our device tree
    449     for i in /sys/bus/usb/devices/*; do
    450         if test -r "$i/dev"; then
    451             dev="`cat "$i/dev" 2> /dev/null`"
    452             major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
    453             minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
    454             class="`cat $i/bDeviceClass 2> /dev/null`"
    455             sh "$INSTALLATION_DIR/VBoxCreateUSBNode.sh" "$major" "$minor" "$class" 2>/dev/null
    456         fi
    457     done
     444    install_device_node_setup "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR"
    458445
    459446    # Write the configuration. Do this before we call /etc/init.d/vboxdrv setup!
  • trunk/src/VBox/Installer/linux/installer-utils.sh

    r37423 r38385  
    1515
    1616setup_normal_input_install_udev() {
    17     TEST_UDEV_VERSION="$1"  # udev version to simulate
     17    # The udev rule setup functions contain some aliases which are used for unit
     18    # testing purposes.  This function sets up the aliases to point to the real
     19    # commands for "normal" use.
    1820    eval 'my_which() { which "$@" ; }'
    1921    eval 'my_test() { test "$@" ; }'
     
    2123}
    2224
     25# Needs to be done before the udev setup functions are called "normally" (i.e.
     26# not in a unit testing context).  Will be overridden later in a unit test.
    2327setup_normal_input_install_udev
    2428
    2529setup_test_input_install_udev() {
     30    # Set up unit testing environment for the "install_udev" function below.
    2631    TEST_NAME="$1"          # used to identify the current test
    2732    TEST_UDEV_VERSION="$2"  # udev version to simulate
     
    3035    eval 'my_rm() { case "$2" in "/etc/udev/rules.d/60-vboxdrv.rules") true ;; *) echo "rm: bad file name \"$2\"!"; false ;; esac ; }'
    3136    eval 'test_udev() { echo "$TEST_UDEV_VERSION" ; }'
     37    DELETED_UDEV_FILE=""
     38}
     39
     40cleanup_test_input_install_udev() {
     41    # Clean up after unit testing install_udev for a given input
     42    setup_normal_input_install_udev
     43    unset test_udev
    3244    DELETED_UDEV_FILE=""
    3345}
     
    108120}
    109121
    110 cleanup_test_input_install_udev() {
    111     setup_normal_input_install_udev
    112     unset test_udev
    113     DELETED_UDEV_FILE=""
    114 }
     122setup_normal_input_install_create_usb_node() {
     123    # install_create_usb_node_for_sysfs contain some aliases for unit testing
     124    # purposes.  This function sets up the aliases to point to the real
     125    # commands for "normal" use.
     126    eval 'my_test() { test "$@" ; }'
     127    eval 'my_cat() { cat "$@" ; }'
     128    eval 'my_sh() { sh "$@" ; }'
     129}
     130
     131# Assume we will be calling the function normally, not for unit testing
     132setup_normal_input_install_create_usb_node
     133
     134# Add a unit test here if/when needed following the same pattern as
     135# setup_test_input_install_udev.
     136
     137install_create_usb_node_for_sysfs() {
     138    # Create a usb device node for a given sysfs path
     139    path="$1"           # sysfs path for the device
     140    usb_createnode="$2" # Path to the USB device node creation script
     141    usb_group="$3"      # The group to give ownership of the node to
     142    if my_test -r "${path}/dev"; then
     143        dev="`my_cat "${path}/dev" 2> /dev/null`"
     144        major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
     145        minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
     146        class="`my_cat ${path}/bDeviceClass 2> /dev/null`"
     147        my_sh "${usb_createnode}" "$major" "$minor" "$class" "${usb_group}" \
     148              2>/dev/null
     149    fi
     150}
     151
     152setup_normal_input_install_device_node_setup() {
     153    # install_device_node_setup contain some aliases for unit testing
     154    # purposes.  This function sets up the aliases to point to the real
     155    # values for "normal" use.
     156    udev_rule_file=/etc/udev/rules.d/10-vboxdrv.rules # Set this to /dev/null
     157                                                      # for unit testing
     158    sysfs_usb_devices="/sys/bus/usb/devices/*"
     159    eval 'do_install_udev() { install_udev "$@"; }'
     160    eval 'do_install_create_usb_node_for_sysfs() { \
     161                          install_create_usb_node_for_sysfs "$@" ; }'
     162}
     163
     164# Assume we will be calling the function normally, not for unit testing
     165setup_normal_input_install_device_node_setup
     166
     167setup_test_input_install_device_node_setup() {
     168    # Set up unit testing environment for the "install_udev" function below.
     169    test_drv_grp="$1"  # The expected vboxdrv group
     170    test_drv_mode="$2" # The expected vboxdrv mode
     171    test_inst_dir="$3" # The expected installation directory
     172    test_usb_grp="$4"  # The expected USB node group
     173    udev_rule_file=/dev/null
     174    sysfs_usb_devices=test_sysfs_path
     175    eval 'do_install_udev() {    test    "$1" = "${test_drv_grp}" \
     176                                      -a "$2" = "${test_drv_mode}" \
     177                                      -a "$3" = "${test_inst_dir}" \
     178                                      -a "$4" = "${test_usb_grp}" \
     179                                      -a "$5" = "${INSTALL_NO_UDEV}" \
     180                              || echo "do_install_udev: bad parameters: $@" >&2 ; }'
     181    eval 'do_install_create_usb_node_for_sysfs() { \
     182                       test    "$1" = "${sysfs_usb_devices}" \
     183                            -a "$2" = "${test_inst_dir}/VBoxCreateUSBNode.sh" \
     184                            -a "$3" = "${test_usb_grp}" \
     185                    || echo "do_install_create_usb_node_for_sysfs: \
     186bad parameters: $@" >&2 ; }'
     187}
     188
     189cleanup_test_input_install_device_node_setup() {
     190    # Clean up unit testing environment for the "install_udev" function below.
     191    # Nothing to do.
     192    true
     193}
     194
     195install_device_node_setup() {
     196    # Install udev rules and create device nodes for usb access
     197    VBOXDRV_GRP="$1"      # The group that should own /dev/vboxdrv
     198    VBOXDRV_MODE="$2"     # The mode to be used for /dev/vboxdrv
     199    INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
     200    USB_GROUP="$4"        # The group that should own the /dev/vboxusb device
     201                          # nodes unless INSTALL_NO_GROUP=1 in
     202                          # /etc/default/virtualbox.  Optional.
     203    usb_createnode="$INSTALLATION_DIR/VBoxCreateUSBNode.sh"
     204    # install udev rule (disable with INSTALL_NO_UDEV=1 in
     205    # /etc/default/virtualbox)
     206    if [ "$INSTALL_NO_GROUP" != "1" ]; then
     207        usb_group=$USB_GROUP
     208        vboxdrv_group=$VBOXDRV_GRP
     209    else
     210        usb_group=root
     211        vboxdrv_group=root
     212    fi
     213    do_install_udev "${vboxdrv_group}" "$VBOXDRV_MODE" "$INSTALLATION_DIR" \
     214                    "${usb_group}" "$INSTALL_NO_UDEV" > ${udev_rule_file}
     215    # Build our device tree
     216    for i in ${sysfs_usb_devices}; do  # This line intentionally without quotes.
     217        do_install_create_usb_node_for_sysfs "$i" "${usb_createnode}" \
     218                                             "${usb_group}"
     219    done
     220}
  • trunk/src/VBox/Installer/linux/testcase/tstInstallerLinux.sh

    r37124 r38385  
    8686cleanup_test_input_install_udev
    8787
     88echo "Testing device node setup"
     89
     90unset INSTALL_NO_GROUP
     91unset INSTALL_NO_UDEV
     92setup_test_input_install_device_node_setup vboxusers 0660 /opt/VirtualBox \
     93                                           vboxusb
     94
     95command="install_device_node_setup vboxusers 0660 /opt/VirtualBox vboxusb"
     96err="`${command} 2>&1`"
     97test -n "${err}" && {
     98    echo "${command} failed."
     99    echo "Error: ${err}"
     100    CERRS="`expr "$CERRS" + 1`"
     101}
     102
     103cleanup_test_input_install_device_node_setup
     104
     105INSTALL_NO_GROUP=1
     106unset INSTALL_NO_UDEV
     107setup_test_input_install_device_node_setup root 0660 /opt/VirtualBox root
     108
     109command="install_device_node_setup vboxusers 0660 /opt/VirtualBox vboxusb"
     110err="`${command} 2>&1`"
     111test -n "${err}" && {
     112    echo "${command} failed."
     113    echo "Error: ${err}"
     114    CERRS="`expr "$CERRS" + 1`"
     115}
     116
     117cleanup_test_input_install_device_node_setup
     118
     119unset INSTALL_NO_GROUP
     120INSTALL_NO_UDEV=1
     121setup_test_input_install_device_node_setup vboxusers 0660 /opt/VirtualBox \
     122                                           vboxusb
     123
     124command="install_device_node_setup vboxusers 0660 /opt/VirtualBox vboxusb"
     125err="`${command} 2>&1`"
     126test -n "${err}" && {
     127    echo "${command} failed."
     128    echo "Error: ${err}"
     129    CERRS="`expr "$CERRS" + 1`"
     130}
     131
     132cleanup_test_input_install_device_node_setup
     133
    88134echo "Done.  Error count $CERRS."
Note: See TracChangeset for help on using the changeset viewer.

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