VirtualBox

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


Ignore:
Timestamp:
Oct 12, 2015 1:51:26 PM (9 years ago)
Author:
vboxsync
Message:

Installer/linux: move host udev rule generation to run-time (and SELinux permission setting to routines.sh).

Location:
trunk/src/VBox/Installer/linux
Files:
8 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/linux/debian/postinst

    r58169 r58186  
    1717#  abort-remove:      (our version): removing this package failed
    1818#  abort-deconfigure: (our version): error during resolving conflicts
    19 
    20 #include installer-common.sh
    2119
    2220LOG="/var/log/vbox-install.log"
     
    4846    addgroup --system vboxusers || true
    4947  fi
    50 
    51   # install udev rule (disable with INSTALL_NO_UDEV=1 in
    52   # /etc/default/virtualbox) and /dev/vboxdrv and /dev/vboxusb/*/* device nodes
    53   install_device_node_setup root 0600 /usr/share/virtualbox "${usb_group}"
    5448
    5549  # The starters need to be Suid root. They drop the privileges before starting
  • trunk/src/VBox/Installer/linux/debian/rules

    r58073 r58186  
    191191        dh_testroot
    192192        rm -f debian/changelog
    193         rm -f debian/preinst debian/postinst debian/prerm
     193        rm -f debian/preinst debian/prerm
    194194        rm -f debian/$(package).init debian/vboxdrv.init
    195195        rm -f debian/vboxballoonctrl-service.init debian/vboxautostart-service.init debian/vboxweb-service.init
     
    265265        sed -e 's|%VER%|$(ver)|g' \
    266266            debian/prerm.in > debian/prerm
    267         sed -e 's|%VER%|$(ver)|g' \
    268             -e '/#include installer-common.sh/ {' \
    269             -e "r $(vboxroot)/src/VBox/Installer/linux/installer-common.sh" \
    270             -e 'd' \
    271             -e '}' \
    272             debian/postinst.in > debian/postinst
    273267        dh_installdebconf
    274268        dh_installchangelogs
  • trunk/src/VBox/Installer/linux/install.sh

    r58090 r58186  
    2020# Include routines and utilities needed by the installer
    2121. ./routines.sh
    22 #include installer-common.sh
    2322
    2423LOG="/var/log/vbox-install.log"
     
    362361    fi
    363362
    364     install_device_node_setup "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR"
    365 
    366363    # Do post-installation common to all installer types, currently service
    367364    # script set-up.
  • trunk/src/VBox/Installer/linux/routines.sh

    r58109 r58186  
    358358    return 0
    359359}
     360
     361set_selinux_permissions() {
     362    # XXX SELinux: allow text relocation entries
     363    local_INSTALLATION_DIR="$1"  # Where the VirtualBox binaries are installed to
     364    local_SHARE_DIR="$2"         # Where shared bits are installed to
     365    if [ -x /usr/bin/chcon ]; then
     366        chcon -t texrel_shlib_t "$local_INSTALLATION_DIR"/*VBox* > /dev/null 2>&1
     367        chcon -t texrel_shlib_t "$local_INSTALLATION_DIR"/VBoxAuth.so \
     368            > /dev/null 2>&1
     369        chcon -t texrel_shlib_t "$local_INSTALLATION_DIR"/VirtualBox.so \
     370            > /dev/null 2>&1
     371        chcon -t texrel_shlib_t "$local_INSTALLATION_DIR"/components/VBox*.so \
     372            > /dev/null 2>&1
     373        chcon -t java_exec_t    "$local_INSTALLATION_DIR"/VirtualBox > /dev/null 2>&1
     374        chcon -t java_exec_t    "$local_INSTALLATION_DIR"/VBoxSDL > /dev/null 2>&1
     375        chcon -t java_exec_t    "$local_INSTALLATION_DIR"/VBoxHeadless \
     376            > /dev/null 2>&1
     377        chcon -t java_exec_t    "$local_INSTALLATION_DIR"/VBoxNetDHCP \
     378            > /dev/null 2>&1
     379        chcon -t java_exec_t    "$local_INSTALLATION_DIR"/VBoxNetNAT \
     380            > /dev/null 2>&1
     381        chcon -t java_exec_t    "$local_INSTALLATION_DIR"/VBoxExtPackHelperApp \
     382            > /dev/null 2>&1
     383        chcon -t java_exec_t    "$local_INSTALLATION_DIR"/vboxwebsrv > /dev/null 2>&1
     384        chcon -t java_exec_t    "$local_INSTALLATION_DIR"/webtest > /dev/null 2>&1
     385        chcon -t bin_t          "$local_SHARE_DIR"/src/vboxhost/build_in_tmp \
     386             > /dev/null 2>&1
     387    fi
     388}
  • trunk/src/VBox/Installer/linux/rpm/VirtualBox.tmpl.spec

    r58090 r58186  
    101101mv VBox.sh $RPM_BUILD_ROOT/usr/bin/VBox
    102102mv VBoxSysInfo.sh $RPM_BUILD_ROOT/usr/share/virtualbox
    103 mv VBoxCreateUSBNode.sh $RPM_BUILD_ROOT/usr/share/virtualbox
     103mv VBoxCreateUSBNode.sh $RPM_BUILD_ROOT/usr/lib/virtualbox
    104104cp icons/128x128/virtualbox.png $RPM_BUILD_ROOT/usr/share/pixmaps/virtualbox.png
    105105cd icons
     
    246246
    247247%post
    248 #include installer-common.sh
    249 
    250248LOG="/var/log/vbox-install.log"
    251249
     
    277275fi
    278276
    279 # install udev rule (disable with INSTALL_NO_UDEV=1 in /etc/default/virtualbox)
    280 # and /dev/vboxdrv and /dev/vboxusb/*/* device nodes
    281 install_device_node_setup root 0600 /usr/share/virtualbox "${usb_group}"
    282277%if %{?rpm_mdv:1}%{!?rpm_mdv:0}
    283278/sbin/ldconfig
  • trunk/src/VBox/Installer/linux/rpm/rules

    r58012 r58186  
    238238            -e 's|%INITSCRIPTS%|$(if $(filter fedora,$(rpmspec)),initscripts,)|g' \
    239239            -e "s|%WEBSVC%|$(if $(NOWEBSVC),false,true)|g" \
    240             -e '/#include installer-common.sh/ {' \
    241             -e "r $(vboxroot)/src/VBox/Installer/linux/installer-common.sh" \
    242             -e 'd' \
    243             -e '}' \
    244240            rpm/VirtualBox.tmpl.spec > $(archdir)/VirtualBox.spec
    245241        cp vboxdrv.sh $(archdir)
  • trunk/src/VBox/Installer/linux/scripts/install.sh

    r56299 r58186  
    237237    install -d -g 0 -o 0 "${PREFIX}/share/${PACKAGE}"
    238238    mv "${INSTALL_SOURCE}/VBoxSysInfo.sh" "${PREFIX}/share/${PACKAGE}"
    239     mv "${INSTALL_SOURCE}/VBoxCreateUSBNode.sh" "${PREFIX}/share/${PACKAGE}"
    240239    mv "${INSTALL_SOURCE}/src" "${PREFIX}/share/${PACKAGE}"
    241240    test -z "${NO_QT}" &&
  • trunk/src/VBox/Installer/linux/uninstall.sh

    r57980 r58186  
    102102  2> /dev/null
    103103
    104 # Remove udev description file
    105 if [ -f /etc/udev/rules.d/60-vboxdrv.rules ]; then
    106     rm -f /etc/udev/rules.d/60-vboxdrv.rules 2> /dev/null
    107 fi
    108 if [ -f /etc/udev/rules.d/10-vboxdrv.rules ]; then
    109     rm -f /etc/udev/rules.d/10-vboxdrv.rules 2> /dev/null
    110 fi
    111 
    112 # Remove our USB device tree
    113 rm -rf /dev/vboxusb 2> /dev/null
    114 
    115104cwd=`pwd`
    116105if [ -f $PREV_INSTALLATION/src/Makefile ]; then
  • trunk/src/VBox/Installer/linux/vboxdrv.sh

    r58012 r58186  
    4343
    4444if [ -n "$INSTALL_DIR" ]; then
     45    MODULE_SRC="$INSTALL_DIR/src/vboxhost"
     46else
     47    INSTALL_DIR=/usr/lib/virtualbox
     48    MODULE_SRC="/usr/share/virtualbox/src/vboxhost"
     49fi
    4550    VIRTUALBOX="$INSTALL_DIR/VirtualBox"
    4651    VBOXMANAGE="$INSTALL_DIR/VBoxManage"
    47     MODULE_SRC="$INSTALL_DIR/src/vboxhost"
    48 else
    49     VIRTUALBOX="/usr/lib/virtualbox/VirtualBox"
    50     VBOXMANAGE="/usr/lib/virtualbox/VBoxManage"
    51     MODULE_SRC="/usr/share/virtualbox/src/vboxhost"
    52 fi
    5352BUILDINTMP="$MODULE_SRC/build_in_tmp"
    5453if test -u "${VIRTUALBOX}"; then
    5554    GROUP=root
     55    DEVICE_MODE=0600
    5656else
    5757    GROUP=vboxusers
     58    DEVICE_MODE=0660
    5859fi
    5960
     
    9798}
    9899
     100## Output the vboxdrv part of our udev rule.  This is redirected to the right file.
     101udev_write_vboxdrv() {
     102    VBOXDRV_GRP="$1"
     103    VBOXDRV_MODE="$2"
     104
     105    echo "KERNEL==\"vboxdrv\", NAME=\"vboxdrv\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
     106    echo "KERNEL==\"vboxdrvu\", NAME=\"vboxdrvu\", OWNER=\"root\", GROUP=\"root\", MODE=\"0666\""
     107    echo "KERNEL==\"vboxnetctl\", NAME=\"vboxnetctl\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
     108}
     109
     110## Output the USB part of our udev rule.  This is redirected to the right file.
     111udev_write_usb() {
     112    INSTALLATION_DIR="$1"
     113    USB_GROUP="$2"
     114
     115    echo "SUBSYSTEM==\"usb_device\", ACTION==\"add\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
     116    echo "SUBSYSTEM==\"usb\", ACTION==\"add\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
     117    echo "SUBSYSTEM==\"usb_device\", ACTION==\"remove\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
     118    echo "SUBSYSTEM==\"usb\", ACTION==\"remove\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
     119}
     120
     121## Generate our udev rule file.  This takes a change in udev rule syntax in
     122## version 55 into account.  It only creates rules for USB for udev versions
     123## recent enough to support USB device nodes.
     124generate_udev_rule() {
     125    VBOXDRV_GRP="$1"      # The group owning the vboxdrv device
     126    VBOXDRV_MODE="$2"     # The access mode for the vboxdrv device
     127    INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
     128    USB_GROUP="$4"        # The group that has permission to access USB devices
     129    NO_INSTALL="$5"       # Set this to "1" to remove but not re-install rules
     130    UDEV_STRING="$6"      # The output of the udev version command
     131
     132    # Extra space!
     133    case "$USB_GROUP" in ?*) USB_GROUP=" $USB_GROUP" ;; esac
     134    case "$NO_INSTALL" in
     135    "1") ;;
     136    *)
     137        udev_ver=`expr "$UDEV_STRING" : '[^0-9]*\([0-9]*\)'`
     138        udev_fix=""
     139        test "$udev_ver" = "" -o "$udev_ver" -lt 55 &&
     140            udev_fix="1"
     141        udev_do_usb=""
     142        test "$udev_ver" -ge 59 &&
     143            udev_do_usb="1"
     144        case "$udev_fix" in
     145        "1")
     146            udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE" |
     147                sed 's/\([^+=]*\)[+=]*\([^"]*"[^"]*"\)/\1=\2/g'
     148            ;;
     149        *)
     150            udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE"
     151            case "$udev_do_usb" in "1")
     152                udev_write_usb "$INSTALLATION_DIR" "$USB_GROUP" ;;
     153            esac
     154            ;;
     155        esac
     156        ;;
     157    esac
     158}
     159
     160## Install udev rule (disable with INSTALL_NO_UDEV=1 in
     161## /etc/default/virtualbox).
     162install_udev() {
     163    VBOXDRV_GRP="$1"      # The group owning the vboxdrv device
     164    VBOXDRV_MODE="$2"     # The access mode for the vboxdrv device
     165    INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
     166    USB_GROUP="$4"        # The group that has permission to access USB devices
     167    NO_INSTALL="$5"       # Set this to "1" to remove but not re-install rules
     168
     169    if test -d /etc/udev/rules.d; then
     170        udev_out="`udevadm version 2>/dev/null ||  udevinfo -V 2>/dev/null`"
     171        generate_udev_rule "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR" \
     172                           "$USB_GROUP" "$NO_INSTALL" "$udev_out"
     173    fi
     174    # Remove old udev description file
     175    rm -f /etc/udev/rules.d/10-vboxdrv.rules 2> /dev/null
     176}
     177
     178## Create a usb device node for a given sysfs path to a USB device.
     179install_create_usb_node_for_sysfs() {
     180    path="$1"           # sysfs path for the device
     181    usb_createnode="$2" # Path to the USB device node creation script
     182    usb_group="$3"      # The group to give ownership of the node to
     183    if test -r "${path}/dev"; then
     184        dev="`cat "${path}/dev" 2> /dev/null`"
     185        major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
     186        minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
     187        class="`cat ${path}/bDeviceClass 2> /dev/null`"
     188        sh "${usb_createnode}" "$major" "$minor" "$class" \
     189              "${usb_group}" 2>/dev/null
     190    fi
     191}
     192
     193udev_rule_file=/etc/udev/rules.d/60-vboxdrv.rules
     194sysfs_usb_devices="/sys/bus/usb/devices/*"
     195
     196## Install udev rules and create device nodes for usb access
     197install_device_node_setup() {
     198    VBOXDRV_GRP="$1"      # The group that should own /dev/vboxdrv
     199    VBOXDRV_MODE="$2"     # The mode to be used for /dev/vboxdrv
     200    INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
     201    USB_GROUP="$4"        # The group that should own the /dev/vboxusb device
     202                          # nodes unless INSTALL_NO_GROUP=1 in
     203                          # /etc/default/virtualbox.  Optional.
     204    usb_createnode="$INSTALLATION_DIR/VBoxCreateUSBNode.sh"
     205    # install udev rule (disable with INSTALL_NO_UDEV=1 in
     206    # /etc/default/virtualbox)
     207    if [ "$INSTALL_NO_GROUP" != "1" ]; then
     208        usb_group=$USB_GROUP
     209        vboxdrv_group=$VBOXDRV_GRP
     210    else
     211        usb_group=root
     212        vboxdrv_group=root
     213    fi
     214    install_udev "${vboxdrv_group}" "$VBOXDRV_MODE" \
     215                 "$INSTALLATION_DIR" "${usb_group}" \
     216                 "$INSTALL_NO_UDEV" > ${udev_rule_file}
     217    # Build our device tree
     218    for i in ${sysfs_usb_devices}; do  # This line intentionally without quotes.
     219        install_create_usb_node_for_sysfs "$i" "${usb_createnode}" \
     220                                          "${usb_group}"
     221    done
     222}
     223
    99224start()
    100225{
    101     begin_msg "Starting VirtualBox kernel modules" console
     226    begin_msg "Starting VirtualBox services" console
     227    # Create udev rule and USB device nodes.
     228    ## todo Wouldn't it make more sense to install the rule to /lib/udev?  This
     229    ## is not a user-created configuration file after all.
     230    ## todo Do we need a udev rule to create /dev/vboxdrv[u] at all?  We have
     231    ## working fall-back code here anyway, and the "right" code is more complex
     232    ## than the fall-back.  Unnecessary duplication?
     233    install_device_node_setup "$GROUP" "$DEVICE_MODE" "$INSTALL_DIR"
    102234    if [ -d /proc/xen ]; then
    103235        failure "Running VirtualBox in a Xen environment is not supported"
     
    163295stop()
    164296{
    165     begin_msg "Stopping VirtualBox kernel modules" console
     297    begin_msg "Stopping VirtualBox services" console
     298    # Remove udev description file
     299    rm -f /etc/udev/rules.d/60-vboxdrv.rules
     300    rm -f /etc/udev/rules.d/10-vboxdrv.rules
     301
     302    # Remove our USB device tree
     303    rm -rf /dev/vboxusb
     304
    166305    if running vboxpci; then
    167306        if ! rmmod vboxpci 2>/dev/null; then
     
    241380{
    242381    begin_msg "Building VirtualBox kernel modules" console
    243     stop >/dev/null
    244382    if find /lib/modules/`uname -r` -name "vboxpci\.*" 2>/dev/null|grep -q vboxpci; then
    245383        begin_msg "Removing old VirtualBox pci kernel module"
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