Changeset 7143 in vbox for trunk/src/VBox/Installer
- Timestamp:
- Feb 26, 2008 11:26:29 AM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 28411
- Location:
- trunk/src/VBox/Installer/linux
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/linux/Makefile.kmk
r6933 r7143 33 33 VBoxAddIF.sh vboxdrv.sh vboxnet.sh \ 34 34 VirtualBox.tar.bz2 LICENSE) \ 35 $(wildcard $(PATH_TARGET)/VirtualBox-*) 35 $(wildcard $(PATH_TARGET)/VirtualBox-*) \ 36 $(PATH_TARGET)/vboxdrv.sh $(PATH_TARGET)/vboxnet.sh 36 37 INSTALLS = linux-bin linux-doc 37 38 … … 178 179 routines.sh \ 179 180 deffiles \ 180 vboxnet.sh \181 vboxdrv.sh \181 $(PATH_TARGET)/vboxnet.sh \ 182 $(PATH_TARGET)/vboxdrv.sh \ 182 183 $(if $(VBOX_OSE),,$(PATH_ROOT)/doc/License.txt) 183 184 $(call MSG_TOOL,makeself,,,$@) … … 190 191 $(QUIET)$(INSTALL) -m 0755 deffiles $(PATH_TARGET)/install 191 192 $(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)/install193 $(QUIET)$(INSTALL) -m 0755 vboxdrv.sh $(PATH_TARGET)/install193 $(QUIET)$(INSTALL) -m 0755 $(PATH_TARGET)/vboxnet.sh $(PATH_TARGET)/install 194 $(QUIET)$(INSTALL) -m 0755 $(PATH_TARGET)/vboxdrv.sh $(PATH_TARGET)/install 194 195 $(QUIET)$(RM) -f $@ 195 196 $(QUIET)$(VBOX_MAKESELF) --follow $(PATH_TARGET)/install $@ \ … … 201 202 $(QUIET)tar --owner 0 --group 0 -cjRhf $@ -C $(PATH_TARGET)/archive-dbg \ 202 203 $(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" $< > $@ 203 210 204 211 # .tar.bz2 for converting into .run -
trunk/src/VBox/Installer/linux/vboxdrv.sh.in
r7141 r7143 24 24 # Default-Start: 3 5 25 25 # Default-Stop: 26 # Description:VirtualBox Linux kernel module26 # Short-Description: VirtualBox Linux kernel module 27 27 ### END INIT INFO 28 28 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 29 PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH 30 DEVICE=/dev/vboxdrv 31 MODNAME=vboxdrv 32 GROUPNAME=vboxusers 33 LOG="/var/log/vbox-install.log" 34 NOLSB=%NOLSB% 35 36 [ -f /lib/lsb/init-functions ] || NOLSB=yes 37 [ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg 38 39 if [ -n "$INSTALL_DIR" ]; then 40 VBOXMANAGE="$INSTALL_DIR/VBoxManage" 41 BUILDINTMP="$INSTALL_DIR/src/build_in_tmp" 40 42 else 41 system=other 43 VBOXMANAGE="/usr/share/virtualbox/VBoxManage" 44 BUILDINTMP="/usr/share/virtualbox/src/build_in_tmp" 42 45 fi 43 46 44 if [ -r /etc/default/virtualbox ]; then 45 . /etc/default/virtualbox 47 if [ -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 46 55 fi 47 56 48 if [ "$system" = "redhat" ]; then 49 . /etc/init.d/functions 57 [ -r /etc/default/virtualbox ] && . /etc/default/virtualbox 58 59 if [ -z "$NOLSB" ]; then 60 . /lib/lsb/init-functions 50 61 fail_msg() { 51 echo _failure52 echo62 echo "" 63 log_failure_msg "$1" 53 64 } 54 55 65 succ_msg() { 56 echo_success 57 echo 66 log_success_msg " done." 58 67 } 59 60 begin() { 61 echo -n "$1" 68 begin_msg() { 69 log_daemon_msg "$@" 62 70 } 71 else 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 63 127 fi 64 128 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 129 failure() 130 { 131 fail_msg "$1" 132 exit 0 133 } 134 135 running() 136 { 137 lsmod | grep -q "$MODNAME[^_-]" 138 } 139 140 start() 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 154 160 else 155 min=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`156 if [ ! -z "$ min" ]; then157 maj=10161 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc` 162 if [ ! -z "$MINOR" ]; then 163 MAJOR=10 158 164 fi 159 165 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 176 180 succ_msg 177 return 0 178 } 179 180 stop(){181 begin "Stopping VirtualBox kernel module"181 } 182 183 stop() 184 { 185 begin_msg "Stopping VirtualBox kernel module" 182 186 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 185 193 fi 186 194 succ_msg 187 return 0188 195 } 189 196 … … 195 202 # SHUTDOWN=savestate 196 203 # select one of these shutdown methods for running VMs 197 stop_vms() { 204 stop_vms() 205 { 198 206 wait=0 199 207 for i in $SHUTDOWN_USERS; do … … 204 212 if [ -n "$VMS" ]; then 205 213 if [ "$SHUTDOWN" = "poweroff" ]; then 206 begin "Powering off remaining VMs"214 begin_msg "Powering off remaining VMs" 207 215 for v in $VMS; do 208 216 $VBOXMANAGE -nologo controlvm $v poweroff … … 210 218 succ_msg 211 219 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" 213 221 for v in $VMS; do 214 222 $VBOXMANAGE -nologo controlvm $v acpipowerbutton … … 217 225 succ_msg 218 226 elif [ "$SHUTDOWN" = "savestate" ]; then 219 begin "Saving state of remaining VMs"227 begin_msg "Saving state of remaining VMs" 220 228 for v in $VMS; do 221 229 $VBOXMANAGE -nologo controlvm $v savestate … … 228 236 # wait for some seconds when doing ACPI shutdown 229 237 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" 231 239 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 244 setup() 245 { 242 246 stop 243 247 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" 245 249 find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null 246 250 succ_msg 247 251 fi 248 begin "Recompiling VirtualBox kernel module"249 if ! $ INSTALL_DIR/src/build_in_tmp install > /var/log/vbox-install.log2>&1; then250 fail "Look at /var/log/vbox-install.logto 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" 251 255 fi 252 256 succ_msg … … 254 258 } 255 259 256 dmnstatus() { 260 dmnstatus() 261 { 257 262 if running; then 258 263 echo "VirtualBox kernel module is loaded." … … 287 292 ;; 288 293 restart) 289 restart 294 stop && start 295 ;; 296 force-reload) 297 stop 298 start 290 299 ;; 291 300 setup) … … 296 305 ;; 297 306 *) 298 echo "Usage: $0 {start|stop|stop_vms|restart| status|setup}"307 echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}" 299 308 exit 1 300 309 esac 301 310 302 exit 311 exit 0 -
trunk/src/VBox/Installer/linux/vboxnet.sh.in
r7141 r7143 28 28 ### END INIT INFO 29 29 30 PATH= $PATH:/bin:/sbin:/usr/sbin30 PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH 31 31 CONFIG="/etc/vbox/interfaces" 32 32 VARDIR="/var/run/VirtualBox" 33 33 VARFILE="/var/run/VirtualBox/vboxnet" 34 34 TAPDEV="/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 35 NOLSB=%NOLSB% 36 37 [ -f /lib/lsb/init-functions ] || NOLSB=yes 38 39 if [ -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 47 fi 48 49 if [ -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 } 42 61 else 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 44 117 fi 45 118 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() { 119 failure() 120 { 121 fail_msg $1 122 # never return with exit code != 0 123 exit 0 124 } 125 126 running() 127 { 124 128 test -f "$VARFILE" 125 129 } … … 129 133 # /var/run/VirtualBox/vboxnet. If this file already exists, assume that the 130 134 # script has already been started and do nothing. 131 start_network() { 132 begin "Starting VirtualBox host networking" 135 start_network() 136 { 137 begin_msg "Starting VirtualBox host networking" 133 138 # If the service is already running, return successfully. 134 if [ -f "$VARFILE" ] 135 then 139 if [ -f "$VARFILE" ]; then 136 140 succ_msg 137 141 return 0 138 142 fi 139 143 # 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" 152 151 fi 153 152 # If there is no configuration file, report success 154 if [ ! -f "$CONFIG" ] 155 then 153 if [ ! -f "$CONFIG" ]; then 156 154 succ_msg 157 155 return 0 158 156 fi 159 157 # 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" 164 160 fi 165 161 # 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" 170 164 fi 171 165 # Fail if we don't have the kernel tun device 172 166 # Make sure that the tun module is loaded (Ubuntu 7.10 needs this) 173 167 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" 178 170 fi 179 171 succ_msg 180 172 # Read the configuration file entries line by line and create the 181 173 # interfaces 182 while read line 183 do 174 while read line; do 184 175 set ""$line 185 176 # 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 188 178 # Check that the line is correctly formed (an interface name plus one 189 179 # or two non-comment entries, possibly followed by a comment). 190 180 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 193 182 case $user in 194 183 +*) … … 201 190 esac 202 191 # Try to create the interface 203 if $cmd > /dev/null 2>&1 204 then 192 if $cmd > /dev/null 2>&1; then 205 193 # On SUSE Linux Enterprise Server, the interface does not 206 194 # appear immediately, so we loop trying to bring it up. 207 195 i=1 208 while [ $i -le 10 ] 209 do 196 while [ $i -le 10 ]; do 210 197 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 213 199 # 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 218 202 echo "$1 $2 $3" > "$VARFILE" 219 203 else … … 230 214 fi 231 215 done 232 if [ $i -ne 20 ] 233 then 216 if [ $i -ne 20 ]; then 234 217 echo "Warning - failed to bring up the interface $1" 235 218 fi … … 245 228 # Set /dev/net/tun to belong to the group vboxusers if it exists and does 246 229 # 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 249 231 chgrp vboxusers "$TAPDEV" 250 232 chmod 0660 "$TAPDEV" … … 255 237 # Shut down VirtualBox host networking and remove all permanent TAP 256 238 # interfaces. This action will fail if some interfaces could not be removed. 257 stop_network() { 258 begin "Shutting down VirtualBox host networking" 239 stop_network() 240 { 241 begin_msg "Shutting down VirtualBox host networking" 259 242 # If there is no runtime record file, assume that the service is not 260 243 # running. 261 if [ ! -f "$VARFILE" ] 262 then 244 if [ ! -f "$VARFILE" ]; then 263 245 succ_msg 264 246 return 0 … … 266 248 # Fail if we can't read our runtime record file or write to the 267 249 # 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" 272 252 fi 273 253 # 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" 278 256 fi 279 257 # Read the runtime record file entries line by line and delete the 280 258 # interfaces. The format of the runtime record file is not checked for 281 259 # errors. 282 while read line 283 do 260 while read line; do 284 261 set ""$line 285 262 # Remove the interface from a bridge if it is part of one 286 if [ ! -z "$3" ] 287 then 263 if [ -n "$3" ]; then 288 264 brctl delif "$3" "$1" 2> /dev/null 289 265 fi … … 291 267 # possible 292 268 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 297 271 set ""$line 298 272 VBoxTunctl -t "$1" -u "$2" > /dev/null 2>&1 299 273 ifconfig "$1" up 2> /dev/null 300 if [ ! -z "$3" ] 301 then 274 if [ -n "$3" ]; then 302 275 brctl addif "$3" "$1" 303 276 fi 304 277 done < "$VARFILE" 305 fail_msg 306 return 1 278 failure "Removing of interface '$3' failed" 307 279 fi 308 280 done < "$VARFILE" … … 316 288 # removed. It is only intended for exceptional circumstances such as 317 289 # uninstalling VirtualBox. 318 force_stop_network() { 319 begin "Shutting down VirtualBox host networking" 290 force_stop_network() 291 { 292 begin_msg "Shutting down VirtualBox host networking" 320 293 # If there is no runtime record file, assume that the service is not 321 294 # running. 322 if [ ! -f "$VARFILE" ] 323 then 295 if [ ! -f "$VARFILE" ]; then 324 296 succ_msg 325 297 return 0 … … 327 299 # Fail if we can't read our runtime record file or write to the 328 300 # 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" 333 303 fi 334 304 # 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" 339 307 fi 340 308 # Read the runtime record file entries line by line and delete the 341 309 # interfaces. The format of the runtime record file is not checked for 342 310 # errors. 343 while read line 344 do 311 while read line; do 345 312 set ""$line 346 313 # Remove the interface from a bridge if it is part of one 347 if [ ! -z "$3" ] 348 then 314 if [ -n "$3" ]; then 349 315 brctl delif "$3" "$1" 2> /dev/null 350 316 fi … … 358 324 } 359 325 360 start() { 326 case "$1" in 327 start) 361 328 start_network 362 } 363 364 stop() { 329 ;; 330 stop) 365 331 stop_network 366 } 367 368 force_stop() { 332 ;; 333 restart|reload) 334 stop_network && start_network 335 ;; 336 force-reload) 337 stop_network 338 start_network 339 ;; 340 force-stop) 369 341 force_stop_network 370 } 371 372 restart() { 373 stop_network && start_network 374 } 375 376 status() { 342 ;; 343 status) 377 344 if running; then 378 345 echo "VirtualBox host networking is loaded." … … 380 347 echo "VirtualBox host networking is not loaded." 381 348 fi 382 }383 384 case "$1" in385 start)386 start387 ;;388 stop)389 stop390 ;;391 restart)392 restart393 ;;394 force-reload)395 restart396 ;;397 force-stop)398 force_stop399 ;;400 status)401 status402 349 ;; 403 350 *) 404 echo "Usage: `basename $0` {start|stop| restart|force-reload|status}"351 echo "Usage: `basename $0` {start|stop|force-stop|restart|force-reload|status}" 405 352 exit 1 406 353 esac 407 354 408 exit 355 exit 0
Note:
See TracChangeset
for help on using the changeset viewer.