vboxnet.sh.in revision dd770e74b6654ce0e5584dbd4ec72e90fd4cc58f
# 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 (GPL) 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.
#
# 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 [ -n "$NOLSB" ]; then
if [ -f /etc/redhat-release ]; then
elif [ -f /etc/SuSE-release ]; then
elif [ -f /etc/gentoo-release ]; then
fi
fi
if [ -z "$NOLSB" ]; then
echo ""
log_failure_msg "$1"
}
log_success_msg " done."
}
log_daemon_msg "$@"
}
else
if [ "$system" = "redhat" ]; then
echo
echo "($1)"
}
echo
}
elif [ "$system" = "suse" ]; then
rc_status -v
echo "($1)"
}
rc_status -v
}
elif [ "$system" = "gentoo" ]; then
. /sbin/functions.sh
eerror $1
}
eend $?
}
ebegin $1
}
shift
fi
else
echo " ...failed!"
echo "($1)"
}
echo " ...done."
}
fi
if [ "$system" != "gentoo" ]; then
[ -z "${1:-}" ] && return 1
if [ -z "${2:-}" ]; then
echo -n "$1:"
return
fi
echo -n "$1: $2"
}
fi
fi
failure()
{
fail_msg $1
# never return with exit code != 0
exit 0
}
running()
{
test -f "$VARFILE"
}
# 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_msg "Starting VirtualBox host networking"
# If the service is already running, return successfully.
return 0
fi
# Fail if we can't create our runtime record file
fi
fi
fi
# If there is no configuration file, report success
return 0
fi
# Fail if we can't read our configuration
fi
# Fail if we don't have tunctl
if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then
failure "VBoxTunctl not found"
fi
# Fail if we don't have the kernel tun device
# Make sure that the tun module is loaded (Ubuntu 7.10 needs this)
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
# Check that the line is correctly formed (an interface name plus one
# or two non-comment entries, possibly followed by a comment).
+*)
;;
*)
cmd="VBoxTunctl -t $1 -u $2"
;;
esac
# Try to create the interface
# 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
# Add the interface to a bridge if one was specified
if [ -n "$3" ]; 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.
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_msg "Shutting down VirtualBox host networking"
# If there is no runtime record file, assume that the service is not
# running.
return 0
fi
# Fail if we can't read our runtime record file or write to the
# folder it is located in
fi
# Fail if we don't have tunctl
if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then
failure "VBoxTunctl not found"
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 [ -n "$3" ]; then
fi
# Remove the interface. Roll back everything and fail if this is not
# possible
while read line; do
if [ -n "$3" ]; then
fi
done < "$VARFILE"
failure "Removing of interface '$3' failed"
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_msg "Shutting down VirtualBox host networking"
# If there is no runtime record file, assume that the service is not
# running.
return 0
fi
# Fail if we can't read our runtime record file or write to the
# folder it is located in
fi
# Fail if we don't have tunctl
if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then
failure "VBoxTunctl not found"
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 [ -n "$3" ]; then
fi
# Remove the interface.
done < "$VARFILE"
return 0
}
case "$1" in
;;
stop)
;;
;;
;;
force-stop)
;;
if running; then
echo "VirtualBox host networking is loaded."
else
echo "VirtualBox host networking is not loaded."
fi
;;
*)
exit 1
esac
exit 0