routines.sh revision 320484435d67c1fb90dca3e8836d81bf939c8ba2
# Oracle VM VirtualBox
# VirtualBox installer shell routines
#
# Copyright (C) 2007-2010 Oracle Corporation
#
# Oracle Corporation confidential
# All rights reserved
#
ro_LOG_FILE=""
# Aborts the script and prints an error message to stderr.
#
# syntax: abort message
echo 1>&2 "$1"
exit 1
}
# Creates an empty log file and remembers the name for future logging
# operations
#
# syntax: create_log logfile
ro_LOG_FILE="$1"
abort "create_log called without an argument! Aborting..."
fi
# Create an empty file
abort "Error creating log file! Aborting..."
fi
}
# Writes text to standard error
#
# Syntax: info text
echo 1>&2 "$1"
}
# Writes text to the log file
#
# Syntax: log text
abort "Error! Logging has not been set up yet! Aborting..."
fi
return 0
}
# Writes test to standard output and to the log file
#
# Syntax: infolog text
info "$1"
log "$1"
}
# Checks whether a module is loaded with a given string in its name.
#
# syntax: module_loaded string
if [ "$1" = "" ]; then
log "module_loaded called without an argument. Aborting..."
abort "Error in installer. Aborting..."
fi
}
# Abort if we are not running as root
abort "This program must be run with administrator privileges. Aborting"
fi
}
# Abort if a copy of VirtualBox is already running
echo 1>&2 "A copy of VirtualBox is currently running. Please close it and try again."
abort "Please note that it can take up to ten seconds for VirtualBox to finish running."
fi
}
# Do we have bzip2?
echo 1>&2 "Please install the bzip2 utility."
log "Please install bzip2."
return 1
fi
return 0
}
# Do we have GNU make?
if [ ! $? = 0 ]; then
echo 1>&2 "Please install GNU make."
log "Please install GNU make."
return 1
fi
return 0
}
# Can we find the kernel source?
if [ ! -d $ro_KBUILD_DIR/include ]; then
if [ ! -d $ro_KBUILD_DIR/include ]; then
echo 1>&2 "Please install the build and header files for your current Linux kernel."
log "Could not find the Linux kernel header files - the directories"
log " do not exist."
return 1
fi
fi
return 0
}
# Is GCC installed?
echo 1>&2 "Please install the GNU compiler."
log "Please install the GNU compiler."
return 1
fi # GCC installed
return 0
}
# Is bash installed? You never know...
echo 1>&2 "Please install GNU bash."
log "Please install GNU bash."
return 1
fi
return 0
}
# Is perl installed?
echo 1>&2 "Please install perl."
echo "Please install perl."
return 1
fi
return 0
}
# What type of system are we running on?
return 0
elif [ -f /etc/debian_version ]; then
elif [ -f /etc/gentoo-release ]; then
elif [ -f /etc/lfs-release -a -d /etc/rc.d/init.d ]; then
elif [ -f /etc/pardus-release ]; then
else # Perhaps we can determine what we need to know anyway though?
echo 1>&2 "Unable to determine your Linux distribution"
log "Unable to determine the Linux distribution"
return 1
fi
return 0
}
# Hack to handle Mandriva's speedboot runlevel
else
fi
}
# Installs a file containing a shell script as an init script
#
# syntax: install_init_script file name
#
# where file is the file to be installed and
# name is the name of the new init script
self="install_init_script"
script=$1
name=$2
test $? -ne 1 || return 1
fi
else
log "install_init_script: error: unknown init type"
return 1
fi
return 0
}
# Remove the init script "name"
#
# syntax: remove_init_script name
self="remove_init_script"
name=$1
test $? -ne 1 || return 1
else
log "remove_init_script: error: unknown init type"
return 1
fi
return 0
}
# Start the init script "name"
#
# syntax: start_init_script name
self="start_init_script"
name=$1
test $? -ne 1 || return 1
else
return 1
fi
}
# Stop the init script "name"
#
# syntax: start_init_script name
name=$1
test $? -ne 1 || return 1
else
return 1
fi
return 0
}
# Add a service to a runlevel
#
# syntax: addrunlevel name start_order stop_order
test ! -z "$1" || \
# Redhat based systems
then
}
else
}
fi
# SUSE-base systems
then
}
# Debian/Ubuntu-based systems
test ! -z "$2" || \
test ! -z "$3" || \
# Debian does not support dependencies currently -- use argument $2
# for start sequence number and argument $3 for stop sequence number
update-rc.d -f $1 remove > /dev/null 2>&1
update-rc.d $1 defaults $2 $3 > /dev/null 2>&1
# Gentoo Linux
# Linux from scratch, by the book
P2=$2
P3=$3
# add leading zero
fi
fi
# BSD-based systems require changing the rc.local file to start a new service.
if ! grep -q $1 $ro_RC_LOCAL
then
fi
# Probably most unknown Linux systems will be sysv type ones. These can theoretically
# be handled automatically if people give us information about them.
echo 1>&2 "As our installer does not recognize your Linux distribution, we were unable to"
echo 1>&2 "set up the initialization script $1 correctly. The script has been copied"
echo 1>&2 "it at system start, or start it manually before using VirtualBox."
echo 1>&2 ""
echo 1>&2 "If you would like to help us add support for your distribution, please open a"
echo 1>&2 "new ticket on http://www.virtualbox.org/wiki/Bugtracker."
fi
return 0
}
# Delete a service from a runlevel
#
# syntax: delrunlevel name
test ! -z "$1" || \
# Redhat-based systems
then
}
fi
# SUSE-based systems
then
}
# Debian/Ubuntu-based systems
update-rc.d -f $1 remove > /dev/null 2>&1
# Gentoo Linux
# Linux from scratch, by the book
# Unknown sysv-type system
echo 1>&2 "Please remove remove references to the initialization script"
fi
# BSD-type systems will just not start the script if it is not there.
# Assume that BSD users understand their system.
return 0
}
# Do initial setup of an installed service
#
# syntax: setup_init_script name
{
name=$1
test $? -ne 1 || return 1
scriptname="/etc/init.d/$name"
scriptname="/etc/rc.d/rc.$name"
scriptname="/etc/rc.d/init.d/$name"
scriptname="/usr/sbin/$name"
else
return 1
fi
# Add the init script to the default runlevel
# This is complicated by the fact that we need to pass older Debian-based
# systems the start and stop order numbers, which we extract from the
# Redhat chkconfig information.
{
log "$self: bad or missing chkconfig line in init script $scriptname"
return 1
}
# $orders is deliberately not quoted here
else
fi
return 0
}
# Do pre-removal cleanup of an installed service
#
# syntax: cleanup_init_script name
{
name=$1
test $? -ne 1 || return 1
scriptname="/etc/init.d/$name"
scriptname="/etc/rc.d/rc.$name"
scriptname="/etc/rc.d/init.d/$name"
scriptname="/usr/sbin/$name"
else
return 1
fi
return 0
}
PROC_NAME=$1
SERVER_PID=`pidof $PROC_NAME 2> /dev/null`
killall -TERM $PROC_NAME > /dev/null 2>&1
sleep 2
fi
}
echo 1>&2 "Python not available, skipping bindings installation."
return 1
fi
echo 1>&2 "Python found: $PYTHON, installing bindings..."
# Pass install path via environment
export VBOX_INSTALL_PATH
$SHELL -c "cd $VBOX_INSTALL_PATH/sdk/installer && $PYTHON vboxapisetup.py install"
# remove files created during build
return 0
}