VirtualBox

Changeset 8462 in vbox


Ignore:
Timestamp:
Apr 29, 2008 1:14:07 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
30325
Message:

sync debian

Location:
trunk/debian
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/debian/vboxdrv.init.in

    r8171 r8462  
    66
    77#
    8 # Copyright (C) 2006-2007 Sun Microsystems, Inc. GmbH
     8# Copyright (C) 2006-2007 Sun Microsystems, Inc.
    99#
    1010# This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/debian/vboxnet.init.in

    r8171 r8462  
    11#! /bin/sh
    2 #
    32# Sun xVM VirtualBox
    43# Linux static host networking interface initialization
     
    65
    76#
    8 # Copyright (C) 2007 Sun Microsystems, Inc. GmbH
     7# Copyright (C) 2007 Sun Microsystems, Inc.
    98#
    109# This file is part of VirtualBox Open Source Edition (OSE), as
     
    2625# Default-Start:  3 5
    2726# Default-Stop:
    28 # Short-Description: VirtualBox permanent host networking setup
     27# Description:    VirtualBox permanent host networking setup
    2928### END INIT INFO
    3029
    31 PATH=$PATH:/bin:/sbin:/usr/sbin
     30PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
    3231CONFIG="/etc/vbox/interfaces"
    3332VARDIR="/var/run/VirtualBox"
    3433VARFILE="/var/run/VirtualBox/vboxnet"
    3534TAPDEV="/dev/net/tun"
    36 NOLSB=%LSB%
    37 
    38 if [ -z "$NOLSB" -a -f /lib/lsb/init-functions ]; then
    39   . /lib/lsb/init-functions
     35NOLSB=%NOLSB%
     36
     37[ -f /lib/lsb/init-functions ] || NOLSB=yes
     38
     39if [ -n "$NOLSB" ]; then
     40    if [ -f /etc/redhat-release ]; then
     41        system=redhat
     42    elif [ -f /etc/SuSE-release ]; then
     43        system=suse
     44    elif [ -f /etc/gentoo-release ]; then
     45        system=gentoo
     46    fi
     47fi
     48
     49if [ -z "$NOLSB" ]; then
     50    . /lib/lsb/init-functions
     51    fail_msg() {
     52        echo ""
     53        log_failure_msg "$1"
     54    }
     55    succ_msg() {
     56        log_success_msg " done."
     57    }
     58    begin_msg() {
     59        log_daemon_msg "$@"
     60    }
    4061else
    41   log_action_begin_msg()
    42   {
    43     echo -n "$@..."
    44   }
    45   log_action_end_msg()
    46   {
    47     if [ -z "${2:-}" ]; then
    48       end="."
     62    if [ "$system" = "redhat" ]; then
     63        . /etc/init.d/functions
     64        fail_msg() {
     65            echo_failure
     66            echo
     67            echo "  ($1)"
     68        }
     69        succ_msg() {
     70            echo_success
     71            echo
     72        }
     73    elif [ "$system" = "suse" ]; then
     74        . /etc/rc.status
     75        fail_msg() {
     76            rc_failed 1
     77            rc_status -v
     78            echo "  ($1)"
     79        }
     80        succ_msg() {
     81            rc_reset
     82            rc_status -v
     83        }
     84    elif [ "$system" = "gentoo" ]; then
     85        . /sbin/functions.sh
     86        fail_msg() {
     87            eerror "$1"
     88        }
     89        succ_msg() {
     90            eend "$?"
     91        }
     92        begin_msg() {
     93            ebegin "$1"
     94        }
     95        if [ "`which $0`" = "/sbin/rc" ]; then
     96            shift
     97        fi
    4998    else
    50       end=" ($2)."
    51     fi
    52     if [ $1 -eq 0 ]; then
    53       echo "done${end}"
    54     else
    55       echo "failed${end}"
    56     fi
    57   }
    58   log_success_msg()
    59   {
    60     echo "$@"
    61   }
    62   log_failure_msg()
    63   {
    64     echo "$@"
    65   }
     99        fail_msg() {
     100            echo " ...failed!"
     101            echo "  ($1)"
     102        }
     103        succ_msg() {
     104            echo " ...done."
     105        }
     106    fi
     107    if [ "$system" != "gentoo" ]; then
     108        begin_msg() {
     109            [ -z "${1:-}" ] && return 1
     110            if [ -z "${2:-}" ]; then
     111                echo -n "$1"
     112            else
     113                echo -n "$1: $2"
     114            fi
     115        }
     116    fi
    66117fi
    67118
    68119failure()
    69120{
    70   log_action_end_msg 1 "$1"
    71   exit 0
     121    fail_msg "$1"
     122    # never return with exit code != 0
     123    exit 0
    72124}
    73125
    74126running()
    75127{
    76   test -f "$VARFILE"
    77 }
    78 
    79 valid_ifname()
    80 {
    81   if expr match "$1" "vbox[0-9][0-9]*$" > /dev/null 2>&1; then
    82     return 0
    83   else
    84     return 1
    85   fi
     128    test -f "$VARFILE"
    86129}
    87130
     
    90133# /var/run/VirtualBox/vboxnet.  If this file already exists, assume that the
    91134# script has already been started and do nothing.
    92 start_network() {
    93     log_action_begin_msg "Starting VirtualBox host networking"
     135start_network()
     136{
     137    begin_msg "Starting VirtualBox host networking"
    94138    # If the service is already running, return successfully.
    95139    if [ -f "$VARFILE" ]; then
    96       log_action_end_msg 0
     140      succ_msg
    97141      return 0
    98142    fi
     
    108152    # If there is no configuration file, report success
    109153    if [ ! -f "$CONFIG" ]; then
    110       log_action_end_msg 0
     154      succ_msg
    111155      return 0
    112156    fi
     
    116160    fi
    117161    # Fail if we don't have tunctl
    118     if ! VBoxTunctl -h 2>&1 | grep -q VBoxTunctl > /dev/null; then
     162    if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then
    119163      failure "VBoxTunctl not found"
    120164    fi
     
    122166    # Make sure that the tun module is loaded (Ubuntu 7.10 needs this)
    123167    modprobe tun > /dev/null 2>&1
    124     if ! cat /proc/misc 2>/dev/null | grep tun > /dev/null
    125     then
     168    if ! cat /proc/misc 2>/dev/null | grep tun > /dev/null; then
    126169      failure "Linux tun/tap subsystem not available"
    127170    fi
     171    succ_msg
    128172    # Read the configuration file entries line by line and create the
    129173    # interfaces
     
    135179        # or two non-comment entries, possibly followed by a comment).
    136180        if ((! expr match "$2" "#" > /dev/null) &&
    137             (test -z "$4" || expr match "$4" "#" > /dev/null) &&
    138             (valid_ifname "$1"))
    139         then
     181            (test -z "$4" || expr match "$4" "#" > /dev/null)); then
     182          # As the very first thing, try delete the interface. Might already
     183          # exist with different configuration. Ignore errors.
     184          VBoxTunctl -d $1 > /dev/null 2>&1
     185          case $user in
     186            +*)
     187                group=`echo $2 | cut -c2-`
     188                cmd="VBoxTunctl -t $1 -g $group"
     189                ;;
     190            *)
     191                cmd="VBoxTunctl -t $1 -u $2"
     192                ;;
     193          esac
    140194          # Try to create the interface
    141           if VBoxTunctl -t "$1" -u "$2" > /dev/null 2>&1
    142           then
     195          if $cmd > /dev/null 2>&1; then
    143196            # On SUSE Linux Enterprise Server, the interface does not
    144197            # appear immediately, so we loop trying to bring it up.
    145198            i=1
    146             while [ $i -le 10 ]
    147             do
     199            while [ $i -le 10 ]; do
    148200              ifconfig "$1" up 2> /dev/null
    149               if ifconfig | grep "$1" > /dev/null 2>&1
    150               then
     201              if ifconfig | grep "$1" > /dev/null; then
    151202                # Add the interface to a bridge if one was specified
    152                 if [ ! -z "$3" ]
    153                 then
    154                   if brctl addif "$3" "$1" 2> /dev/null
    155                   then
    156                     echo "$1 $2 $3" > "$VARFILE"
     203                if [ -n "$3" ]; then
     204                  if brctl addif "$3" "$1" 2> /dev/null; then
     205                    echo "$1 $2 $3" >> "$VARFILE"
    157206                  else
    158                     echo "$1 $2" > "$VARFILE"
     207                    echo "$1 $2" >> "$VARFILE"
    159208                    echo "Warning - failed to add interface $1 to the bridge $3"
    160209                  fi
    161210                else
    162                   echo "$1 $2" > $VARFILE
     211                  echo "$1 $2" >> "$VARFILE"
    163212                fi
    164213                i=20
     
    168217              fi
    169218            done
    170             if [ $i -ne 20 ]
    171             then
     219            if [ $i -ne 20 ]; then
    172220              echo "Warning - failed to bring up the interface $1"
    173221            fi
     
    176224          fi
    177225        else
    178           echo
    179226          echo "Warning - invalid line in $CONFIG:"
    180227          echo "  $line"
     
    184231    # Set /dev/net/tun to belong to the group vboxusers if it exists and does
    185232    # yet belong to a group.
    186     if ls -g "$TAPDEV" 2>/dev/null | grep -q root; then
     233    if ls -g "$TAPDEV" 2>/dev/null | grep root > /dev/null; then
    187234      chgrp vboxusers "$TAPDEV"
    188235      chmod 0660 "$TAPDEV"
    189236    fi
    190     log_action_end_msg 0
    191237    return 0
    192238}
     
    194240# Shut down VirtualBox host networking and remove all permanent TAP
    195241# interfaces.  This action will fail if some interfaces could not be removed.
    196 stop_network() {
    197     log_action_begin_msg "Shutting down VirtualBox host networking"
     242stop_network()
     243{
     244    begin_msg "Shutting down VirtualBox host networking"
    198245    # If there is no runtime record file, assume that the service is not
    199246    # running.
    200247    if [ ! -f "$VARFILE" ]; then
    201       log_action_end_msg 0
     248      succ_msg
    202249      return 0
    203250    fi
     
    208255    fi
    209256    # Fail if we don't have tunctl
    210     if ! VBoxTunctl -h 2>&1 | grep -q VBoxTunctl > /dev/null; then
     257    if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then
    211258      failure "VBoxTunctl not found"
    212259    fi
     
    217264      set ""$line
    218265      # Remove the interface from a bridge if it is part of one
    219       if [ ! -z "$3" ]; then
     266      if [ -n "$3" ]; then
    220267        brctl delif "$3" "$1" 2> /dev/null
    221268      fi
     
    223270      # possible
    224271      if (! ifconfig "$1" down 2> /dev/null ||
    225           ! VBoxTunctl -d "$1" > /dev/null 2>&1)
    226       then
     272          ! VBoxTunctl -d "$1" > /dev/null 2>&1); then
    227273        while read line; do
    228274          set ""$line
    229275          VBoxTunctl -t "$1" -u "$2" > /dev/null 2>&1
    230276          ifconfig "$1" up 2> /dev/null
    231           if [ ! -z "$3" ]; then
     277          if [ -n "$3" ]; then
    232278            brctl addif "$3" "$1"
    233279          fi
    234280        done < "$VARFILE"
    235         failure "Removing of interface failed"
    236281      fi
    237282    done < "$VARFILE"
    238283    rm -f "$VARFILE" 2> /dev/null
    239     log_action_end_msg 0
     284    succ_msg
    240285    return 0
    241286}
     
    245290# removed.  It is only intended for exceptional circumstances such as
    246291# uninstalling VirtualBox.
    247 force_stop_network() {
    248     log_action_begin_msg "Shutting down VirtualBox host networking"
     292force_stop_network()
     293{
     294    begin_msg "Shutting down VirtualBox host networking"
    249295    # If there is no runtime record file, assume that the service is not
    250296    # running.
    251297    if [ ! -f "$VARFILE" ]; then
    252       log_action_end_msg 0
     298      succ_msg
    253299      return 0
    254300    fi
     
    259305    fi
    260306    # Fail if we don't have tunctl
    261     if ! VBoxTunctl -h 2>&1 | grep -q VBoxTunctl > /dev/null; then
     307    if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then
    262308      failure "VBoxTunctl not found"
    263309    fi
     
    268314      set ""$line
    269315      # Remove the interface from a bridge if it is part of one
    270       if [ ! -z "$3" ]; then
     316      if [ -n "$3" ]; then
    271317        brctl delif "$3" "$1" 2> /dev/null
    272318      fi
     
    276322    done < "$VARFILE"
    277323    rm -f "$VARFILE" 2> /dev/null
    278     log_action_end_msg 0
     324    succ_msg
    279325    return 0
    280326}
     
    287333    stop_network
    288334    ;;
    289 restart|reload|force-reload)
     335restart|reload)
     336    stop_network && start_network
     337    ;;
     338force-reload)
    290339    stop_network
    291340    start_network
     
    296345status)
    297346    if running; then
    298       log_success_msg "VirtualBox host networking is loaded."
     347        echo "VirtualBox host networking is loaded."
    299348    else
    300       log_failure_msg "VirtualBox host networking is not loaded."
     349        echo "VirtualBox host networking is not loaded."
    301350    fi
    302351    ;;
     
    306355esac
    307356
    308 exit
     357exit 0
Note: See TracChangeset for help on using the changeset viewer.

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