vboxnet.sh revision c3cd0366348bcd10e42bd7be9ea05d194394f389
# innotek VirtualBox
# Linux static host networking interface initialization
#
#
# Copyright (C) 2007 innotek GmbH
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# General Public License as published by the Free Software Foundation,
# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
# distribution. VirtualBox OSE is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY of any kind.
#
# If you received this file as part of a commercial VirtualBox
# distribution, then only the terms of your commercial VirtualBox
# license agreement apply instead of the previous paragraph.
#
# chkconfig: 35 30 60
# description: VirtualBox permanent host networking setup
#
### BEGIN INIT INFO
# Provides: vboxnet
# Required-Start: $network
# Required-Stop:
# Default-Start: 3 5
# Default-Stop:
# Description: VirtualBox permanent host networking setup
### END INIT INFO
CONFIG="/etc/vbox/interfaces"
VARDIR="/var/run/VirtualBox"
if [ -f /etc/redhat-release ]; then
elif [ -f /etc/SuSE-release ]; then
elif [ -f /etc/gentoo-release ]; then
else
fi
if [ "$system" = "redhat" ]; then
echo
}
echo
}
echo -n "$1"
}
fi
if [ "$system" = "suse" ]; then
rc_status -v
}
rc_status -v
}
echo -n "$1"
}
fi
if [ "$system" = "gentoo" ]; then
. /sbin/functions.sh
eend 1
}
eend $?
}
ebegin $1
}
shift
fi
fi
if [ "$system" = "other" ]; then
echo " ...fail!"
}
echo " ...done."
}
echo -n $1
}
fi
eerror $1
exit 1
fi
echo "($1)"
exit 1
}
test -f "$VARFILE"
}
then
return 0
else
return 1
fi
}
# Create all permanent TAP devices registered on the system, add them to a
# bridge if required and keep a record of proceedings in the file
# /var/run/VirtualBox/vboxnet. If this file already exists, assume that the
# script has already been started and do nothing.
begin "Starting VirtualBox host networking"
# If the service is already running, return successfully.
then
return 0
fi
# Fail if we can't create our runtime record file
then
then
return 1
fi
fi
then
return 1
fi
# If there is no configuration file, report success
then
return 0
fi
# Fail if we can't read our configuration
then
return 1
fi
# Fail if we don't have tunctl
if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null
then
return 1
fi
# Read the configuration file entries line by line and create the
# interfaces
while read line
do
# If the line is a comment then ignore it
then
# Check that the line is correctly formed (an interface name plus one
# or two non-comment entries, possibly followed by a comment).
then
# Try to create the interface
then
# On SUSE Linux Enterprise Server, the interface does not
# appear immediately, so we loop trying to bring it up.
i=1
while [ $i -le 10 ]
do
then
# Add the interface to a bridge if one was specified
if [ ! -z "$3" ]
then
then
else
echo "Warning - failed to add interface $1 to the bridge $3"
fi
else
fi
i=20
else
i=`expr $i + 1`
sleep .1
fi
done
if [ $i -ne 20 ]
then
echo "Warning - failed to bring up the interface $1"
fi
else
echo "Warning - failed to create the interface $1 for the user $2"
fi
else
echo "Warning - invalid line in $CONFIG:"
echo " $line"
fi
fi
done < "$CONFIG"
# yet belong to a group.
then
fi
return 0
}
# Shut down VirtualBox host networking and remove all permanent TAP
# interfaces. This action will fail if some interfaces could not be removed.
begin "Shutting down VirtualBox host networking"
# If there is no runtime record file, assume that the service is not
# running.
then
return 0
fi
# Fail if we can't read our runtime record file or write to the
# folder it is located in
then
return 1
fi
# Fail if we don't have tunctl
if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null
then
return 1
fi
# Read the runtime record file entries line by line and delete the
# interfaces. The format of the runtime record file is not checked for
# errors.
while read line
do
# Remove the interface from a bridge if it is part of one
if [ ! -z "$3" ]
then
fi
# Remove the interface. Roll back everything and fail if this is not
# possible
then
while read line
do
if [ ! -z "$3" ]
then
fi
done < "$VARFILE"
return 1
fi
done < "$VARFILE"
return 0
}
# Shut down VirtualBox host networking and remove all permanent TAP
# interfaces. This action will succeed even if not all interfaces could be
# removed. It is only intended for exceptional circumstances such as
# uninstalling VirtualBox.
begin "Shutting down VirtualBox host networking"
# If there is no runtime record file, assume that the service is not
# running.
then
return 0
fi
# Fail if we can't read our runtime record file or write to the
# folder it is located in
then
return 1
fi
# Fail if we don't have tunctl
if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null
then
return 1
fi
# Read the runtime record file entries line by line and delete the
# interfaces. The format of the runtime record file is not checked for
# errors.
while read line
do
# Remove the interface from a bridge if it is part of one
if [ ! -z "$3" ]
then
fi
# Remove the interface.
done < "$VARFILE"
return 0
}
}
stop() {
}
}
}
if running; then
echo "VirtualBox host networking is loaded."
else
echo "VirtualBox host networking is not loaded."
fi
}
case "$1" in
;;
stop)
stop
;;
;;
;;
force-stop)
;;
;;
*)
exit 1
esac
exit