VirtualBox

Changeset 7143

Show
Ignore:
Timestamp:
02/26/08 12:26:29 (9 months ago)
Author:
vboxsync
Message:

Linux installer: unify the vboxdrv and vboxnet scripts

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/VBox/Installer/linux/Makefile.kmk

    r6933 r7143  
    3333                 VBoxAddIF.sh vboxdrv.sh vboxnet.sh \ 
    3434                 VirtualBox.tar.bz2 LICENSE) \ 
    35                  $(wildcard $(PATH_TARGET)/VirtualBox-*) 
     35                 $(wildcard $(PATH_TARGET)/VirtualBox-*) \ 
     36                 $(PATH_TARGET)/vboxdrv.sh $(PATH_TARGET)/vboxnet.sh 
    3637INSTALLS       = linux-bin linux-doc 
    3738 
     
    178179                routines.sh \ 
    179180                deffiles \ 
    180                 vboxnet.sh \ 
    181                 vboxdrv.sh \ 
     181                $(PATH_TARGET)/vboxnet.sh \ 
     182                $(PATH_TARGET)/vboxdrv.sh \ 
    182183                $(if $(VBOX_OSE),,$(PATH_ROOT)/doc/License.txt) 
    183184        $(call MSG_TOOL,makeself,,,$@) 
     
    190191        $(QUIET)$(INSTALL) -m 0755 deffiles $(PATH_TARGET)/install 
    191192        $(QUIET)$(if $(VBOX_OSE),,$(INSTALL) -m 0644 $(PATH_ROOT)/doc/License.txt $(PATH_TARGET)/install/LICENSE) 
    192         $(QUIET)$(INSTALL) -m 0755 vboxnet.sh $(PATH_TARGET)/install 
    193         $(QUIET)$(INSTALL) -m 0755 vboxdrv.sh $(PATH_TARGET)/install 
     193        $(QUIET)$(INSTALL) -m 0755 $(PATH_TARGET)/vboxnet.sh $(PATH_TARGET)/install 
     194        $(QUIET)$(INSTALL) -m 0755 $(PATH_TARGET)/vboxdrv.sh $(PATH_TARGET)/install 
    194195        $(QUIET)$(RM) -f $@ 
    195196        $(QUIET)$(VBOX_MAKESELF) --follow $(PATH_TARGET)/install $@ \ 
     
    201202        $(QUIET)tar --owner 0 --group 0 -cjRhf $@ -C $(PATH_TARGET)/archive-dbg \ 
    202203                $(addprefix $(DBGPATH)/,$(LINUXSTRIPBIN)) 
     204 
     205$(PATH_TARGET)/vboxdrv.sh: vboxdrv.sh.in 
     206        $(QUIET)$(SED_EXT) -e "s|%NOLSB%|yes|g" $< > $@ 
     207 
     208$(PATH_TARGET)/vboxnet.sh: vboxnet.sh.in 
     209        $(QUIET)$(SED_EXT) -e "s|%NOLSB%|yes|g" $< > $@ 
    203210 
    204211# .tar.bz2 for converting into .run 
  • trunk/src/VBox/Installer/linux/vboxdrv.sh.in

    r7006 r7143  
    2424# Default-Start:  3 5 
    2525# Default-Stop: 
    26 # Description:    VirtualBox Linux kernel module 
     26# Short-Description: VirtualBox Linux kernel module 
    2727### END INIT INFO 
    2828 
    29 PATH=$PATH:/bin:/sbin:/usr/sbin 
    30 CONFIG="/etc/vbox/vbox.cfg" 
    31 . "$CONFIG" 
    32 VBOXMANAGE="$INSTALL_DIR/VBoxManage" 
    33  
    34 if [ -f /etc/redhat-release ]; then 
    35     system=redhat 
    36 elif [ -f /etc/SuSE-release ]; then 
    37     system=suse 
    38 elif [ -f /etc/gentoo-release ]; then 
    39     system=gentoo 
     29PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH 
     30DEVICE=/dev/vboxdrv 
     31MODNAME=vboxdrv 
     32GROUPNAME=vboxusers 
     33LOG="/var/log/vbox-install.log" 
     34NOLSB=%NOLSB% 
     35 
     36[ -f /lib/lsb/init-functions ] || NOLSB=yes 
     37[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg 
     38 
     39if [ -n "$INSTALL_DIR" ]; then 
     40    VBOXMANAGE="$INSTALL_DIR/VBoxManage" 
     41    BUILDINTMP="$INSTALL_DIR/src/build_in_tmp" 
    4042else 
    41     system=other 
     43    VBOXMANAGE="/usr/share/virtualbox/VBoxManage" 
     44    BUILDINTMP="/usr/share/virtualbox/src/build_in_tmp" 
    4245fi 
    4346 
    44 if [ -r /etc/default/virtualbox ]; then 
    45   . /etc/default/virtualbox 
     47if [ -n "$NOLSB" ]; then 
     48    if [ -f /etc/redhat-release ]; then 
     49        system=redhat 
     50    elif [ -f /etc/SuSE-release ]; then 
     51        system=suse 
     52    elif [ -f /etc/gentoo-release ]; then 
     53        system=gentoo 
     54    fi 
    4655fi 
    4756 
    48 if [ "$system" = "redhat" ]; then 
    49     . /etc/init.d/functions 
     57[ -r /etc/default/virtualbox ] && . /etc/default/virtualbox 
     58 
     59if [ -z "$NOLSB"  ]; then 
     60    . /lib/lsb/init-functions 
    5061    fail_msg() { 
    51         echo_failure 
    52         echo 
     62        echo "" 
     63        log_failure_msg "$1" 
    5364    } 
    54  
    5565    succ_msg() { 
    56         echo_success 
    57         echo 
     66        log_success_msg " done." 
    5867    } 
    59  
    60     begin() { 
    61         echo -n "$1" 
     68    begin_msg() { 
     69        log_daemon_msg "$@" 
    6270    } 
     71else 
     72    if [ "$system" = "redhat" ]; then 
     73        . /etc/init.d/functions 
     74        fail_msg() { 
     75            echo_failure 
     76            echo 
     77            echo "  ($1)" 
     78        } 
     79        succ_msg() { 
     80            echo_success 
     81            echo 
     82        } 
     83    elif [ "$system" = "suse" ]; then 
     84        . /etc/rc.status 
     85        fail_msg() { 
     86            rc_failed 1 
     87            rc_status -v 
     88            echo "  ($1)" 
     89        } 
     90        succ_msg() { 
     91            rc_reset 
     92            rc_status -v 
     93        } 
     94    elif [ "$system" = "gentoo" ]; then 
     95        . /sbin/functions.sh 
     96        fail_msg() { 
     97            eerror $1 
     98        } 
     99        succ_msg() { 
     100            eend $? 
     101        } 
     102        begin_msg() { 
     103            ebegin $1 
     104        } 
     105        if [ "`which $0`" = "/sbin/rc" ]; then 
     106            shift 
     107        fi 
     108    else 
     109        fail_msg() { 
     110            echo " ...failed!" 
     111            echo "  ($1)" 
     112        } 
     113        succ_msg() { 
     114            echo " ...done." 
     115        } 
     116    fi 
     117    if [ "$system" != "gentoo" ]; then 
     118        begin_msg() { 
     119            [ -z "${1:-}" ] && return 1 
     120            if [ -z "${2:-}" ]; then 
     121                echo -n "$1:" 
     122                return 
     123            fi 
     124            echo -n "$1: $2" 
     125        } 
     126    fi 
    63127fi 
    64128 
    65 if [ "$system" = "suse" ]; then 
    66     . /etc/rc.status 
    67     fail_msg() { 
    68         rc_failed 1 
    69         rc_status -v 
    70     } 
    71  
    72     succ_msg() { 
    73         rc_reset 
    74         rc_status -v 
    75     } 
    76  
    77     begin() { 
    78         echo -n "$1" 
    79     } 
    80 fi 
    81  
    82 if [ "$system" = "gentoo" ]; then 
    83     . /sbin/functions.sh 
    84     fail_msg() { 
    85         eend 1 
    86     } 
    87  
    88     succ_msg() { 
    89         eend $? 
    90     } 
    91  
    92     begin() { 
    93         ebegin $1 
    94     } 
    95  
    96     if [ "`which $0`" = "/sbin/rc" ]; then 
    97         shift 
    98     fi 
    99 fi 
    100  
    101 if [ "$system" = "other" ]; then 
    102     fail_msg() { 
    103         echo " ...fail!" 
    104     } 
    105  
    106     succ_msg() { 
    107         echo " ...done." 
    108     } 
    109  
    110     begin() { 
    111         echo -n $1 
    112     } 
    113 fi 
    114  
    115  
    116 dev=/dev/vboxdrv 
    117 modname=vboxdrv 
    118 groupname=vboxusers 
    119  
    120 fail() { 
    121     if [ "$system" = "gentoo" ]; then 
    122         eerror $1 
    123         exit 1 
    124     fi 
    125     fail_msg 
    126     echo "($1)" 
    127     exit 1 
    128 
    129  
    130 running() { 
    131     lsmod | grep -q "$modname[^_-]" 
    132 
    133  
    134 start() { 
    135     begin "Starting VirtualBox kernel module " 
    136     find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv || { 
    137         fail "Kernel module not found" 
    138     } 
    139     running || { 
    140         rm -f $dev || { 
    141             fail "Cannot remove $dev" 
    142         } 
    143  
    144         modprobe $modname > /dev/null 2>&1 || { 
    145             fail "modprobe $modname failed" 
    146         } 
    147  
    148         sleep 1 
    149     } 
    150     if [ ! -c $dev ]; then 
    151         maj=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices` 
    152         if [ ! -z "$maj" ]; then 
    153             min=0 
     129failure() 
     130
     131    fail_msg "$1" 
     132    exit 0 
     133
     134 
     135running() 
     136
     137    lsmod | grep -q "$MODNAME[^_-]" 
     138
     139 
     140start() 
     141
     142    begin_msg "Starting VirtualBox kernel module" 
     143    if ! running; then 
     144        if ! find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then 
     145            failure "No suitable module for running kernel found" 
     146        fi 
     147        if ! rm -f $DEVICE; then 
     148            failure "Cannot remove $DEVICE" 
     149        fi 
     150        if ! modprobe $MODNAME > /dev/null 2>&1; then 
     151            failure "modprobe $MODNAME failed. Please use 'dmesg' to find out why" 
     152        fi 
     153        sleep .2 
     154    fi 
     155    # ensure the character special exists 
     156    if [ ! -c $DEVICE ]; then 
     157        MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices` 
     158        if [ ! -z "$MAJOR" ]; then 
     159            MINOR=0 
    154160        else 
    155             min=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc` 
    156             if [ ! -z "$min" ]; then 
    157                 maj=10 
     161            MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc` 
     162            if [ ! -z "$MINOR" ]; then 
     163                MAJOR=10 
    158164            fi 
    159165        fi 
    160         test -z "$maj" && { 
    161             rmmod $modname 2>/dev/null 
    162             fail "Cannot locate the VirtualBox device" 
    163         } 
    164  
    165         mknod -m 0660 $dev c $maj $min 2>/dev/null || { 
    166             rmmod $modname 2>/dev/null 
    167             fail "Cannot create device $dev with major $maj and minor $min" 
    168         } 
    169     fi 
    170  
    171     chown :$groupname $dev 2>/dev/null || { 
    172         rmmod $modname 2>/dev/null 
    173         fail "Cannot change owner $groupname for device $dev" 
    174     } 
    175  
     166        if [ -z "$MAJOR" ]; then 
     167            rmmod $MODNAME 2>/dev/null 
     168            failure "Cannot locate the VirtualBox device" 
     169        fi 
     170        if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then 
     171            rmmod $MODNAME 2>/dev/null 
     172            failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR" 
     173        fi 
     174    fi 
     175    # ensure permissions 
     176    if ! chown :$GROUPNAME $DEVICE 2>/dev/null; then 
     177        rmmod $MODNAME 2>/dev/null 
     178        failure "Cannot change owner $GROUPNAME for device $DEVICE" 
     179    fi 
    176180    succ_msg 
    177     return 0 
    178 
    179  
    180 stop()
    181     begin "Stopping VirtualBox kernel module
     181
     182 
     183stop() 
     184
     185    begin_msg "Stopping VirtualBox kernel module
    182186    if running; then 
    183         rmmod $modname 2>/dev/null || fail "Cannot unload module $modname" 
    184         rm -f $dev || fail "Cannot unlink $dev" 
     187        if ! rmmod $MODNAME 2>/dev/null; then 
     188            failure "Cannot unload module $MODNAME" 
     189        fi 
     190        if ! rm -f $DEVICE; then 
     191            failure "Cannot unlink $DEVICE" 
     192        fi 
    185193    fi 
    186194    succ_msg 
    187     return 0 
    188195} 
    189196 
     
    195202#   SHUTDOWN=savestate 
    196203#     select one of these shutdown methods for running VMs 
    197 stop_vms() { 
     204stop_vms() 
     205
    198206    wait=0 
    199207    for i in $SHUTDOWN_USERS; do 
     
    204212            if [ -n "$VMS" ]; then 
    205213                if [ "$SHUTDOWN" = "poweroff" ]; then 
    206                     begin "Powering off remaining VMs
     214                    begin_msg "Powering off remaining VMs
    207215                    for v in $VMS; do 
    208216                        $VBOXMANAGE -nologo controlvm $v poweroff 
     
    210218                    succ_msg 
    211219                elif [ "$SHUTDOWN" = "acpibutton" ]; then 
    212                     begin "Sending ACPI power button event to remaining VMs
     220                    begin_msg "Sending ACPI power button event to remaining VMs
    213221                    for v in $VMS; do 
    214222                        $VBOXMANAGE -nologo controlvm $v acpipowerbutton 
     
    217225                    succ_msg 
    218226                elif [ "$SHUTDOWN" = "savestate" ]; then 
    219                     begin "Saving state of remaining VMs
     227                    begin_msg "Saving state of remaining VMs
    220228                    for v in $VMS; do 
    221229                        $VBOXMANAGE -nologo controlvm $v savestate 
     
    228236    # wait for some seconds when doing ACPI shutdown 
    229237    if [ "$wait" -ne 0 ]; then 
    230         log_daemon_msg "Waiting for $wait seconds for VM shutdown" 
     238        begin_msg "Waiting for $wait seconds for VM shutdown" 
    231239        sleep $wait 
    232         log_end_msg 
    233     fi 
    234 
    235  
    236 restart() { 
    237     stop && start 
    238     return 0 
    239 
    240  
    241 setup() { 
     240        succ_msg 
     241    fi 
     242
     243 
     244setup() 
     245
    242246    stop 
    243247    if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then 
    244       begin "Removing old VirtualBox kernel module
     248      begin_msg "Removing old VirtualBox kernel module
    245249      find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null 
    246250      succ_msg 
    247251    fi 
    248     begin "Recompiling VirtualBox kernel module
    249     if ! $INSTALL_DIR/src/build_in_tmp install > /var/log/vbox-install.log 2>&1; then 
    250         fail "Look at /var/log/vbox-install.log to find out what went wrong" 
     252    begin_msg "Recompiling VirtualBox kernel module
     253    if ! $BUILDINTMP install > $LOG 2>&1; then 
     254        failure "Look at $LOG to find out what went wrong" 
    251255    fi 
    252256    succ_msg 
     
    254258} 
    255259 
    256 dmnstatus() { 
     260dmnstatus() 
     261
    257262    if running; then 
    258263        echo "VirtualBox kernel module is loaded." 
     
    287292    ;; 
    288293restart) 
    289     restart 
     294    stop && start 
     295    ;; 
     296force-reload) 
     297    stop 
     298    start 
    290299    ;; 
    291300setup) 
     
    296305    ;; 
    297306*) 
    298     echo "Usage: $0 {start|stop|stop_vms|restart|status|setup}" 
     307    echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}" 
    299308    exit 1 
    300309esac 
    301310 
    302 exit 
     311exit 0 
  • trunk/src/VBox/Installer/linux/vboxnet.sh.in

    r7031 r7143  
    2828### END INIT INFO 
    2929 
    30 PATH=$PATH:/bin:/sbin:/usr/sbin 
     30PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH 
    3131CONFIG="/etc/vbox/interfaces" 
    3232VARDIR="/var/run/VirtualBox" 
    3333VARFILE="/var/run/VirtualBox/vboxnet" 
    3434TAPDEV="/dev/net/tun" 
    35  
    36 if [ -f /etc/redhat-release ]; then 
    37     system=redhat 
    38 elif [ -f /etc/SuSE-release ]; then 
    39     system=suse 
    40 elif [ -f /etc/gentoo-release ]; then 
    41     system=gentoo 
     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    } 
    4261else 
    43     system=other 
     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 
     98    else 
     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                return 
     113            fi 
     114            echo -n "$1: $2" 
     115        } 
     116    fi 
    44117fi 
    45118 
    46 if [ "$system" = "redhat" ]; then 
    47     . /etc/init.d/functions 
    48     fail_msg() { 
    49         echo_failure 
    50         echo 
    51     } 
    52  
    53     succ_msg() { 
    54         echo_success 
    55         echo 
    56     } 
    57  
    58     begin() { 
    59         echo -n "$1" 
    60     } 
    61 fi 
    62  
    63 if [ "$system" = "suse" ]; then 
    64     . /etc/rc.status 
    65     fail_msg() { 
    66         rc_failed 1 
    67         rc_status -v 
    68     } 
    69  
    70     succ_msg() { 
    71         rc_reset 
    72         rc_status -v 
    73     } 
    74  
    75     begin() { 
    76         echo -n "$1" 
    77     } 
    78 fi 
    79  
    80 if [ "$system" = "gentoo" ]; then 
    81     . /sbin/functions.sh 
    82     fail_msg() { 
    83         eend 1 
    84     } 
    85  
    86     succ_msg() { 
    87         eend $? 
    88     } 
    89  
    90     begin() { 
    91         ebegin $1 
    92     } 
    93  
    94     if [ "`which $0`" = "/sbin/rc" ]; then 
    95         shift 
    96     fi 
    97 fi 
    98  
    99 if [ "$system" = "other" ]; then 
    100     fail_msg() { 
    101         echo " ...fail!" 
    102     } 
    103  
    104     succ_msg() { 
    105         echo " ...done." 
    106     } 
    107  
    108     begin() { 
    109         echo -n $1 
    110     } 
    111 fi 
    112  
    113 fail() { 
    114     if [ "$system" = "gentoo" ]; then 
    115         eerror $1 
    116         exit 1 
    117     fi 
    118     fail_msg 
    119     echo "($1)" 
    120     exit 1 
    121 
    122  
    123 running() { 
     119failure() 
     120
     121    fail_msg $1 
     122    # never return with exit code != 0 
     123    exit 0 
     124
     125 
     126running() 
     127
    124128    test -f "$VARFILE" 
    125129} 
     
    129133# /var/run/VirtualBox/vboxnet.  If this file already exists, assume that the 
    130134# script has already been started and do nothing. 
    131 start_network() { 
    132     begin "Starting VirtualBox host networking" 
     135start_network() 
     136
     137    begin_msg "Starting VirtualBox host networking" 
    133138    # If the service is already running, return successfully. 
    134     if [ -f "$VARFILE" ] 
    135     then 
     139    if [ -f "$VARFILE" ]; then 
    136140      succ_msg 
    137141      return 0 
    138142    fi 
    139143    # Fail if we can't create our runtime record file 
    140     if [ ! -d "$VARDIR" ] 
    141     then 
    142       if ! mkdir "$VARDIR" 2> /dev/null 
    143       then 
    144         fail_msg 
    145         return 1 
    146       fi 
    147     fi 
    148     if ! touch "$VARFILE" 2> /dev/null 
    149     then 
    150       fail_msg 
    151       return 1 
     144    if [ ! -d "$VARDIR" ]; then 
     145      if ! mkdir "$VARDIR" 2> /dev/null; then 
     146        failure "Cannot create $VARDIR" 
     147      fi 
     148    fi 
     149    if ! touch "$VARFILE" 2> /dev/null; then 
     150      failure "Cannot create $VARFILE" 
    152151    fi 
    153152    # If there is no configuration file, report success 
    154     if [ ! -f "$CONFIG" ] 
    155     then 
     153    if [ ! -f "$CONFIG" ]; then 
    156154      succ_msg 
    157155      return 0 
    158156    fi 
    159157    # Fail if we can't read our configuration 
    160     if [ ! -r "$CONFIG" ] 
    161     then 
    162       fail_msg 
    163       return 1 
     158    if [ ! -r "$CONFIG" ]; then 
     159      failure "Cannot read $CONFIG" 
    164160    fi 
    165161    # Fail if we don't have tunctl 
    166     if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null 
    167     then 
    168       fail_msg 
    169       return 1 
     162    if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then 
     163      failure "VBoxTunctl not found" 
    170164    fi 
    171165    # Fail if we don't have the kernel tun device 
    172166    # Make sure that the tun module is loaded (Ubuntu 7.10 needs this) 
    173167    modprobe tun > /dev/null 2>&1 
    174     if ! cat /proc/misc 2>/dev/null | grep tun > /dev/null 
    175     then 
    176       fail_msg 
    177       return 1 
     168    if ! cat /proc/misc 2>/dev/null | grep tun > /dev/null; then 
     169      failure "Linux tun/tap subsystem not available" 
    178170    fi 
    179171    succ_msg 
    180172    # Read the configuration file entries line by line and create the 
    181173    # interfaces 
    182     while read line 
    183     do 
     174    while read line; do 
    184175      set ""$line 
    185176      # If the line is a comment then ignore it 
    186       if ((! expr match "$1" "#" > /dev/null) && (! test -z "$1")) 
    187       then 
     177      if ((! expr match "$1" "#" > /dev/null) && (! test -z "$1")); then 
    188178        # Check that the line is correctly formed (an interface name plus one 
    189179        # or two non-comment entries, possibly followed by a comment). 
    190180        if ((! expr match "$2" "#" > /dev/null) && 
    191             (test -z "$4" || expr match "$4" "#" > /dev/null)) 
    192         then 
     181            (test -z "$4" || expr match "$4" "#" > /dev/null)); then 
    193182          case $user in 
    194183            +*) 
     
    201190          esac 
    202191          # Try to create the interface 
    203           if $cmd > /dev/null 2>&1 
    204           then 
     192          if $cmd > /dev/null 2>&1; then 
    205193            # On SUSE Linux Enterprise Server, the interface does not 
    206194            # appear immediately, so we loop trying to bring it up. 
    207195            i=1 
    208             while [ $i -le 10 ] 
    209             do 
     196            while [ $i -le 10 ]; do 
    210197              ifconfig "$1" up 2> /dev/null 
    211               if ifconfig | grep "$1" > /dev/null 2>&1 
    212               then 
     198              if ifconfig | grep "$1" > /dev/null; then 
    213199                # Add the interface to a bridge if one was specified 
    214                 if [ ! -z "$3" ] 
    215                 then 
    216                   if brctl addif "$3" "$1" 2> /dev/null 
    217                   then 
     200                if [ -n "$3" ]; then 
     201                  if brctl addif "$3" "$1" 2> /dev/null; then 
    218202                    echo "$1 $2 $3" > "$VARFILE" 
    219203                  else 
     
    230214              fi 
    231215            done 
    232             if [ $i -ne 20 ] 
    233             then 
     216            if [ $i -ne 20 ]; then 
    234217              echo "Warning - failed to bring up the interface $1" 
    235218            fi 
     
    245228    # Set /dev/net/tun to belong to the group vboxusers if it exists and does 
    246229    # yet belong to a group. 
    247     if ls -g "$TAPDEV" 2>/dev/null | grep root 2>&1 > /dev/null 
    248     then 
     230    if ls -g "$TAPDEV" 2>/dev/null | grep root > /dev/null; then 
    249231      chgrp vboxusers "$TAPDEV" 
    250232      chmod 0660 "$TAPDEV" 
     
    255237# Shut down VirtualBox host networking and remove all permanent TAP 
    256238# interfaces.  This action will fail if some interfaces could not be removed. 
    257 stop_network() { 
    258     begin "Shutting down VirtualBox host networking" 
     239stop_network() 
     240
     241    begin_msg "Shutting down VirtualBox host networking" 
    259242    # If there is no runtime record file, assume that the service is not 
    260243    # running. 
    261     if [ ! -f "$VARFILE" ] 
    262     then 
     244    if [ ! -f "$VARFILE" ]; then 
    263245      succ_msg 
    264246      return 0 
     
    266248    # Fail if we can't read our runtime record file or write to the 
    267249    # folder it is located in 
    268     if [ ! -r "$VARFILE" -o ! -w "$VARDIR" ] 
    269     then 
    270       fail_msg 
    271       return 1 
     250    if [ ! -r "$VARFILE" -o ! -w "$VARDIR" ]; then 
     251      failure "Failed to read $VARFILE or to write $VARDIR" 
    272252    fi 
    273253    # Fail if we don't have tunctl 
    274     if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null 
    275     then 
    276       fail_msg 
    277       return 1 
     254    if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then 
     255      failure "VBoxTunctl not found" 
    278256    fi 
    279257    # Read the runtime record file entries line by line and delete the 
    280258    # interfaces.  The format of the runtime record file is not checked for 
    281259    # errors. 
    282     while read line 
    283     do 
     260    while read line; do 
    284261      set ""$line 
    285262      # Remove the interface from a bridge if it is part of one 
    286       if [ ! -z "$3" ] 
    287       then 
     263      if [ -n "$3" ]; then 
    288264        brctl delif "$3" "$1" 2> /dev/null 
    289265      fi 
     
    291267      # possible 
    292268      if (! ifconfig "$1" down 2> /dev/null || 
    293           ! VBoxTunctl -d "$1" > /dev/null 2>&1) 
    294       then 
    295         while read line 
    296         do 
     269          ! VBoxTunctl -d "$1" > /dev/null 2>&1); then 
     270        while read line; do 
    297271          set ""$line 
    298272          VBoxTunctl -t "$1" -u "$2" > /dev/null 2>&1 
    299273          ifconfig "$1" up 2> /dev/null 
    300           if [ ! -z "$3" ] 
    301           then 
     274          if [ -n "$3" ]; then 
    302275            brctl addif "$3" "$1" 
    303276          fi 
    304277        done < "$VARFILE" 
    305         fail_msg 
    306         return 1 
     278        failure "Removing of interface '$3' failed" 
    307279      fi 
    308280    done < "$VARFILE" 
     
    316288# removed.  It is only intended for exceptional circumstances such as 
    317289# uninstalling VirtualBox. 
    318 force_stop_network() { 
    319     begin "Shutting down VirtualBox host networking" 
     290force_stop_network() 
     291
     292    begin_msg "Shutting down VirtualBox host networking" 
    320293    # If there is no runtime record file, assume that the service is not 
    321294    # running. 
    322     if [ ! -f "$VARFILE" ] 
    323     then 
     295    if [ ! -f "$VARFILE" ]; then 
    324296      succ_msg 
    325297      return 0 
     
    327299    # Fail if we can't read our runtime record file or write to the 
    328300    # folder it is located in 
    329     if [ ! -r "$VARFILE" -o ! -w "$VARDIR" ] 
    330     then 
    331       fail_msg 
    332       return 1 
     301    if [ ! -r "$VARFILE" -o ! -w "$VARDIR" ]; then 
     302      failure "Failed to read $VARFILE or to write $VARDIR" 
    333303    fi 
    334304    # Fail if we don't have tunctl 
    335     if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null 
    336     then 
    337       fail_msg 
    338       return 1 
     305    if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then 
     306      failure "VBoxTunctl not found" 
    339307    fi 
    340308    # Read the runtime record file entries line by line and delete the 
    341309    # interfaces.  The format of the runtime record file is not checked for 
    342310    # errors. 
    343     while read line 
    344     do 
     311    while read line; do 
    345312      set ""$line 
    346313      # Remove the interface from a bridge if it is part of one 
    347       if [ ! -z "$3" ] 
    348       then 
     314      if [ -n "$3" ]; then 
    349315        brctl delif "$3" "$1" 2> /dev/null 
    350316      fi 
     
    358324} 
    359325 
    360 start() { 
     326case "$1" in 
     327start) 
    361328    start_network 
    362 
    363  
    364 stop() { 
     329    ;; 
     330stop) 
    365331    stop_network 
    366 
    367  
    368 force_stop() { 
     332    ;; 
     333restart|reload) 
     334    stop_network && start_network 
     335    ;; 
     336force-reload) 
     337    stop_network 
     338    start_network 
     339    ;; 
     340force-stop) 
    369341    force_stop_network 
    370 
    371  
    372 restart() { 
    373     stop_network && start_network 
    374 
    375  
    376 status() { 
     342    ;; 
     343status) 
    377344    if running; then 
    378345        echo "VirtualBox host networking is loaded." 
     
    380347        echo "VirtualBox host networking is not loaded." 
    381348    fi 
    382 } 
    383  
    384 case "$1" in 
    385 start) 
    386     start 
    387     ;; 
    388 stop) 
    389     stop 
    390     ;; 
    391 restart) 
    392     restart 
    393     ;; 
    394 force-reload) 
    395     restart 
    396     ;; 
    397 force-stop) 
    398     force_stop 
    399     ;; 
    400 status) 
    401     status 
    402349    ;; 
    403350*) 
    404     echo "Usage: `basename $0` {start|stop|restart|force-reload|status}" 
     351    echo "Usage: `basename $0` {start|stop|force-stop|restart|force-reload|status}" 
    405352    exit 1 
    406353esac 
    407354 
    408 exit 
     355exit 0 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy