vboxguest.sh revision 4b9d6701570cb98fd36e209314239d104ec584d3
45e9809aff7304721fddb95654901b32195c9c7avboxsync#!/bin/sh
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync# VirtualBox Guest Additions kernel module control script for Solaris.
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync# Copyright (C) 2008-2010 Oracle Corporation
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
45e9809aff7304721fddb95654901b32195c9c7avboxsync# available from http://www.virtualbox.org. This file is free software;
45e9809aff7304721fddb95654901b32195c9c7avboxsync# you can redistribute it and/or modify it under the terms of the GNU
45e9809aff7304721fddb95654901b32195c9c7avboxsync# General Public License (GPL) as published by the Free Software
45e9809aff7304721fddb95654901b32195c9c7avboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
45e9809aff7304721fddb95654901b32195c9c7avboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
45e9809aff7304721fddb95654901b32195c9c7avboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync# The contents of this file may alternatively be used under the terms
45e9809aff7304721fddb95654901b32195c9c7avboxsync# of the Common Development and Distribution License Version 1.0
45e9809aff7304721fddb95654901b32195c9c7avboxsync# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
45e9809aff7304721fddb95654901b32195c9c7avboxsync# VirtualBox OSE distribution, in which case the provisions of the
45e9809aff7304721fddb95654901b32195c9c7avboxsync# CDDL are applicable instead of those of the GPL.
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync# You may elect to license modified versions of this file under the
45e9809aff7304721fddb95654901b32195c9c7avboxsync# terms and conditions of either the GPL or the CDDL or both.
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncSILENTUNLOAD=""
45e9809aff7304721fddb95654901b32195c9c7avboxsyncMODNAME="vboxguest"
45e9809aff7304721fddb95654901b32195c9c7avboxsyncVFSMODNAME="vboxfs"
45e9809aff7304721fddb95654901b32195c9c7avboxsyncMODDIR32="/usr/kernel/drv"
45e9809aff7304721fddb95654901b32195c9c7avboxsyncMODDIR64=$MODDIR32/amd64
45e9809aff7304721fddb95654901b32195c9c7avboxsyncVFSDIR32="/usr/kernel/fs"
45e9809aff7304721fddb95654901b32195c9c7avboxsyncVFSDIR64="/usr/kernel/fs/amd64"
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncabort()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync echo 1>&2 "## $1"
45e9809aff7304721fddb95654901b32195c9c7avboxsync exit 1
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncinfo()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync echo 1>&2 "$1"
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsynccheck_if_installed()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync cputype=`isainfo -k`
45e9809aff7304721fddb95654901b32195c9c7avboxsync modulepath="$MODDIR32/$MODNAME"
45e9809aff7304721fddb95654901b32195c9c7avboxsync if test "$cputype" = "amd64"; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync modulepath="$MODDIR64/$MODNAME"
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync if test -f "$modulepath"; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync return 0
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync abort "VirtualBox kernel module ($MODNAME) NOT installed."
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncmodule_loaded()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync if test -f "/etc/name_to_major"; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync loadentry=`cat /etc/name_to_major | grep "$1 "`
45e9809aff7304721fddb95654901b32195c9c7avboxsync else
45e9809aff7304721fddb95654901b32195c9c7avboxsync loadentry=`/usr/sbin/modinfo | grep "$1 "`
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync if test -z "$loadentry"; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync return 1
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync return 0
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvboxguest_loaded()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync module_loaded $MODNAME
45e9809aff7304721fddb95654901b32195c9c7avboxsync return $?
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvboxfs_loaded()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync module_loaded $VFSMODNAME
45e9809aff7304721fddb95654901b32195c9c7avboxsync return $?
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsynccheck_root()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync # the reason we don't use "-u" is that some versions of id are old and do not
45e9809aff7304721fddb95654901b32195c9c7avboxsync # support this option (eg. Solaris 10) and do not have a "--version" to check it either
45e9809aff7304721fddb95654901b32195c9c7avboxsync # so go with the uglier but more generic approach
45e9809aff7304721fddb95654901b32195c9c7avboxsync idbin=`which id`
45e9809aff7304721fddb95654901b32195c9c7avboxsync isroot=`$idbin | grep "uid=0"`
45e9809aff7304721fddb95654901b32195c9c7avboxsync if test -z "$isroot"; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync abort "This program must be run with administrator privileges. Aborting"
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstart_module()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync if vboxguest_loaded; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync info "VirtualBox guest kernel module already loaded."
45e9809aff7304721fddb95654901b32195c9c7avboxsync else
45e9809aff7304721fddb95654901b32195c9c7avboxsync /usr/sbin/add_drv -i'pci80ee,cafe' -m'* 0666 root sys' $MODNAME
45e9809aff7304721fddb95654901b32195c9c7avboxsync sync
45e9809aff7304721fddb95654901b32195c9c7avboxsync if test ! vboxguest_loaded; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync abort "Failed to load VirtualBox guest kernel module."
45e9809aff7304721fddb95654901b32195c9c7avboxsync elif test -c "/devices/pci@0,0/pci80ee,cafe@4:$MODNAME"; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync info "VirtualBox guest kernel module loaded."
45e9809aff7304721fddb95654901b32195c9c7avboxsync else
45e9809aff7304721fddb95654901b32195c9c7avboxsync abort "Aborting due to attach failure."
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstop_module()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync if vboxguest_loaded; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync /usr/sbin/rem_drv $MODNAME || abort "## Failed to unload VirtualBox guest kernel module."
45e9809aff7304721fddb95654901b32195c9c7avboxsync info "VirtualBox guest kernel module unloaded."
45e9809aff7304721fddb95654901b32195c9c7avboxsync elif test -z "$SILENTUNLOAD"; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync info "VirtualBox guest kernel module not loaded."
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstart_vboxfs()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync if vboxfs_loaded; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync info "VirtualBox FileSystem kernel module already loaded."
45e9809aff7304721fddb95654901b32195c9c7avboxsync else
45e9809aff7304721fddb95654901b32195c9c7avboxsync /usr/sbin/modload -p fs/$VFSMODNAME || abort "Failed to load VirtualBox FileSystem kernel module."
45e9809aff7304721fddb95654901b32195c9c7avboxsync if test ! vboxfs_loaded; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync abort "Failed to load VirtualBox FileSystem kernel module."
45e9809aff7304721fddb95654901b32195c9c7avboxsync else
45e9809aff7304721fddb95654901b32195c9c7avboxsync info "VirtualBox FileSystem kernel module loaded."
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstop_vboxfs()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync if vboxfs_loaded; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync vboxfs_mod_id=`/usr/sbin/modinfo | grep $VFSMODNAME | cut -f 1 -d ' ' `
45e9809aff7304721fddb95654901b32195c9c7avboxsync if test -n "$vboxfs_mod_id"; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync /usr/sbin/modunload -i $vboxfs_mod_id || abort "Failed to unload VirtualBox FileSystem module."
45e9809aff7304721fddb95654901b32195c9c7avboxsync info "VirtualBox FileSystem kernel module unloaded."
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync elif test -z "$SILENTUNLOAD"; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync info "VirtualBox FileSystem kernel module not loaded."
45e9809aff7304721fddb95654901b32195c9c7avboxsync fi
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncrestart_module()
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync stop_module
45e9809aff7304721fddb95654901b32195c9c7avboxsync sync
45e9809aff7304721fddb95654901b32195c9c7avboxsync start_module
45e9809aff7304721fddb95654901b32195c9c7avboxsync return 0
}
restart_all()
{
stop_module
sync
start_module
return 0
}
status_module()
{
if vboxguest_loaded; then
info "Running."
else
info "Stopped."
fi
}
stop_all()
{
stop_vboxfs
stop_module
return 0
}
check_root
check_if_installed
if test "$2" = "silentunload"; then
SILENTUNLOAD="$2"
fi
case "$1" in
stopall)
stop_all
;;
restartall)
restart_all
;;
start)
start_module
;;
stop)
stop_module
;;
restart)
restart_module
;;
status)
status_module
;;
vfsstart)
start_vboxfs
;;
vfsstop)
stop_vboxfs
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0