run-inst.sh revision 320484435d67c1fb90dca3e8836d81bf939c8ba2
575N/A#!/bin/sh
575N/A#
575N/A# Oracle VM VirtualBox
575N/A# VirtualBox Makeself installation starter script for Linux
575N/A
575N/A#
575N/A# Copyright (C) 2006-2009 Oracle Corporation
575N/A#
575N/A# Oracle Corporation confidential
575N/A# All rights reserved
575N/A#
575N/A
575N/A# This is a stub installation script to be included in VirtualBox Makeself
575N/A# installers which removes any previous installations of the package, unpacks
575N/A# the package into the filesystem (by default under /opt) and starts the real
575N/A# installation script.
575N/A#
575N/A
575N/APATH=$PATH:/bin:/sbin:/usr/sbin
575N/A
575N/A# Note: These variable names must *not* clash with variables in $CONFIG_DIR/$CONFIG!
575N/APACKAGE="_PACKAGE_"
3256N/APACKAGE_NAME="_PACKAGE_NAME_"
575N/AUNINSTALL="uninstall.sh"
575N/AROUTINES="routines.sh"
575N/AARCH="_ARCH_"
575N/AINSTALLATION_VER="_VERSION_"
575N/AUNINSTALL_SCRIPTS="_UNINSTALL_SCRIPTS_"
575N/A
575N/AINSTALLATION_DIR="/opt/$PACKAGE-$INSTALLATION_VER"
575N/ACONFIG_DIR="/var/lib/$PACKAGE"
575N/ACONFIG="config"
575N/ACONFIG_FILES="filelist"
1158N/ASELF=$1
575N/ALOGFILE="/var/log/$PACKAGE.log"
1158N/A
575N/A. "./$ROUTINES"
1158N/A
1158N/Acheck_root
575N/A
575N/Acreate_log "$LOGFILE"
575N/A
575N/Ausage()
575N/A{
575N/A info ""
575N/A info "Usage: install [<installation directory>] | uninstall [force] [no_setup]"
575N/A info ""
575N/A info "Example:"
575N/A info "$SELF install"
575N/A exit 1
575N/A}
575N/A
575N/A# Create a symlink in the filesystem and add it to the list of package files
575N/Aadd_symlink()
575N/A{
575N/A self=add_symlink
575N/A ## Parameters:
575N/A # The file the link should point to
575N/A target="$1"
575N/A # The name of the actual symlink file. Must be an absolute path to a
575N/A # non-existing file in an existing directory.
575N/A link="$2"
575N/A link_dir="`dirname "$link"`"
575N/A test -n "$target" ||
575N/A { echo 1>&2 "$self: no target specified"; return 1; }
575N/A test -d "$link_dir" ||
575N/A { echo 1>&2 "$self: link directory $link_dir does not exist"; return 1; }
575N/A test ! -e "$link" ||
575N/A { echo 1>&2 "$self: link file "$link" already exists"; return 1; }
575N/A expr "$link" : "/.*" > /dev/null ||
575N/A { echo 1>&2 "$self: link file name is not absolute"; return 1; }
575N/A rm -f "$link"
575N/A ln -s "$target" "$link"
575N/A echo "$link" >> "$CONFIG_DIR/$CONFIG_FILES"
575N/A}
575N/A
575N/A# Create symbolic links targeting all files in a directory in another
575N/A# directory in the filesystem
575N/Alink_into_fs()
575N/A{
575N/A ## Parameters:
575N/A # Directory containing the link target files
575N/A target_branch="$1"
575N/A # Directory to create the link files in
575N/A directory="$2"
575N/A for i in "$INSTALLATION_DIR/$target_branch"/*; do
575N/A test -e "$i" &&
575N/A add_symlink "$i" "$directory/`basename $i`"
575N/A done
575N/A}
575N/A
575N/A# Look for broken installations or installations without a known uninstaller
575N/A# and try to clean them up, asking the user first.
575N/Adef_uninstall()
575N/A{
575N/A ## Parameters:
575N/A # Whether to force cleanup without asking the user
575N/A force="$1"
1346N/A
1346N/A . ./deffiles
1346N/A found=0
575N/A for i in $DEFAULT_FILE_NAMES; do
575N/A test "$found" = 0 -a -e "$i" && found=1
575N/A done
575N/A test "$found" = 0 &&
575N/A for i in $DEFAULT_VERSIONED_FILE_NAMES-*; do
575N/A test "$found" = 0 -a -e "$i" && found=1
575N/A done
575N/A test "$found" = 0 && return 0
575N/A if ! test "$1" = "force" ; then
575N/A cat 1>&2 << EOF
575N/AYou appear to have a version of the _PACKAGE_ software
575N/Aon your system which was installed from a different source or using a
575N/Adifferent type of installer. If you installed it from a package from your
575N/ALinux distribution or if it is a default part of the system then we strongly
1214N/Arecommend that you cancel this installation and remove it properly before
575N/Ainstalling this version. If this is simply an older or a damaged
575N/Ainstallation you may safely proceed.
575N/A
575N/ADo you wish to continue anyway? [yes or no]
575N/AEOF
575N/A read reply dummy
575N/A if ! expr "$reply" : [yY] > /dev/null &&
929N/A ! expr "$reply" : [yY][eE][sS] > /dev/null
575N/A then
575N/A info
575N/A info "Cancelling installation."
575N/A return 1
575N/A fi
575N/A fi
575N/A # Stop what we can in the way of services and remove them from the
575N/A # system
575N/A for i in vboxvfs vboxadd-timesync vboxadd-service vboxadd; do
575N/A stop_init_script "$i"
575N/A cleanup_init "$i" 1>&2 2>> "$LOGFILE"
575N/A test -x "./$i" && "./$i" cleanup 1>&2 2>> "$LOGFILE"
575N/A remove_init_script "$i"
575N/A done
575N/A
575N/A # Get rid of any remaining files
575N/A for i in $DEFAULT_FILE_NAMES; do
575N/A rm -f "$i" 2> /dev/null
575N/A done
1158N/A for i in $DEFAULT_VERSIONED_FILE_NAMES; do
1158N/A rm -f "$i-"* 2> /dev/null
575N/A done
1158N/A rm -f "/usr/lib/$PACKAGE" "/usr/lib64/$PACKAGE" "/usr/share/$PACKAGE"
575N/A
1365N/A # And any packages left under /opt
953N/A for i in "/opt/$PACKAGE-"*; do
1158N/A test -d "$i" && rm -rf "$i"
575N/A done
1365N/A return 0
575N/A}
575N/A
1365N/Ainfo "$PACKAGE_NAME installer"
575N/A
575N/Acheck_bzip2
575N/A
575N/A# Check architecture
575N/Acpu=`uname -m`;
575N/Acase "$cpu" in
575N/A i[3456789]86|x86)
575N/A cpu="x86"
575N/A lib_path="/usr/lib"
575N/A ;;
575N/A x86_64|amd64)
575N/A cpu="amd64"
575N/A if test -d "/usr/lib64"; then
575N/A lib_path="/usr/lib64"
929N/A else
575N/A lib_path="/usr/lib"
575N/A fi
2152N/A ;;
929N/A *)
575N/A cpu="unknown"
575N/Aesac
579N/AARCH_PACKAGE="$PACKAGE-$cpu.tar.bz2"
579N/Aif [ ! -r "$ARCH_PACKAGE" ]; then
579N/A info "Detected unsupported $cpu machine type."
579N/A exit 1
579N/Afi
575N/A
575N/A# Sensible default actions
1158N/AACTION="install"
1158N/ADO_SETUP="true"
575N/ANO_CLEANUP=""
575N/AFORCE_UPGRADE=""
575N/Awhile true
575N/Ado
575N/A if [ "$2" = "" ]; then
break
fi
shift
case "$1" in
install)
ACTION="install"
;;
uninstall)
ACTION="uninstall"
;;
force)
FORCE_UPGRADE="force"
;;
no_setup)
DO_SETUP=""
;;
no_cleanup)
# Do not do cleanup of old modules when removing them. For
# testing purposes only.
DO_SETUP=""
NO_CLEANUP="no_cleanup"
;;
*)
if [ "`echo $1|cut -c1`" != "/" ]; then
info "Please specify an absolute path"
usage
fi
INSTALLATION_DIR="$1"
;;
esac
done
# uninstall any previous installation
INSTALL_DIR=""
uninstalled=0
test -r "$CONFIG_DIR/$CONFIG" && . "$CONFIG_DIR/$CONFIG"
if test -n "$INSTALL_DIR" -a -x "$INSTALL_DIR/$UNINSTALLER"; then
"$INSTALL_DIR/$UNINSTALLER" $NO_CLEANUP 1>&2 ||
abort "Failed to remove existing installation. Aborting..."
uninstalled=1
fi
test "$uninstalled" = 0 && def_uninstall "$FORCE_UPGRADE" && uninstalled=1
test "$uninstalled" = 0 && exit 1
rm -f "$CONFIG_DIR/$CONFIG"
rm -f "$CONFIG_DIR/$CONFIG_FILES"
rmdir "$CONFIG_DIR" 2>/dev/null
test "$ACTION" = "install" || exit 0
# install the new version
mkdir -p "$CONFIG_DIR"
test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
mkdir -p "$INSTALLATION_DIR"
# Create a list of the files in the archive, skipping any directories which
# already exist in the filesystem.
bzip2 -d -c "$ARCH_PACKAGE" | tar -tf - |
while read name; do
fullname="$INSTALLATION_DIR/$name"
case "$fullname" in
*/)
test ! -d "$fullname" &&
echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
;;
*)
echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
;;
esac
done
bzip2 -d -c "$ARCH_PACKAGE" | tar -xf - -C "$INSTALLATION_DIR" || exit 1
# Set symlinks into /usr and /sbin
link_into_fs "bin" "/usr/bin"
link_into_fs "sbin" "/usr/sbin"
link_into_fs "lib" "$lib_path"
link_into_fs "share" "/usr/share"
link_into_fs "src" "/usr/src"
# Install, set up and start init scripts
for i in "$INSTALLATION_DIR/init/"*; do
if test -r "$i"; then
install_init_script "$i" "`basename "$i"`"
test -n "$DO_SETUP" && setup_init_script "`basename "$i"`" 1>&2
start_init_script "`basename "$i"`"
fi
done
# Remember our installation configuration
cat > "$CONFIG_DIR/$CONFIG" << EOF
# $PACKAGE installation record.
# Package installation directory
INSTALL_DIR=$INSTALLATION_DIR
# Package uninstaller. If you repackage this software, please make sure
# that this prints a message and returns an error so that the default
# uninstaller does not attempt to delete the files installed by your
# package.
UNINSTALLER=$UNINSTALL
# Package version
INSTALL_VER=$INSTALLATION_VER
EOF
cp $ROUTINES $INSTALLATION_DIR
echo $INSTALLATION_DIR/$ROUTINES >> "$CONFIG_DIR/$CONFIG_FILES"
cat > $INSTALLATION_DIR/$UNINSTALL << EOF
#!/bin/sh
# Auto-generated uninstallation file
PATH=\$PATH:/bin:/sbin:/usr/sbin
LOGFILE="/var/log/$PACKAGE-uninstall.log"
# Read routines.sh
if ! test -r "$INSTALLATION_DIR/$ROUTINES"; then
echo 1>&2 "Required file $ROUTINES not found. Aborting..."
return 1
fi
. "$INSTALLATION_DIR/$ROUTINES"
# We need to be run as root
check_root
create_log "\$LOGFILE"
echo 1>&2 "Removing installed version $INSTALLATION_VER of $PACKAGE_NAME..."
NO_CLEANUP=""
if test "\$1" = "no_cleanup"; then
shift
NO_CLEANUP="no_cleanup"
fi
test -r "$CONFIG_DIR/$CONFIG_FILES" || abort "Required file $CONFIG_FILES not found. Aborting..."
# Stop and clean up all services
for i in "$INSTALLATION_DIR/init/"*; do
if test -r "\$i"; then
stop_init_script "\`basename "\$i"\`"
test -z "\$NO_CLEANUP" && cleanup_init "\`basename "\$i"\`" 2>> "\$LOGFILE"
remove_init_script "\`basename "\$i"\`"
fi
done
# And remove all files and empty installation directories
# Remove any non-directory entries
cat "$CONFIG_DIR/$CONFIG_FILES" | xargs rm 2>/dev/null
# Remove any empty (of files) directories in the file list
cat "$CONFIG_DIR/$CONFIG_FILES" |
while read file; do
case "\$file" in
*/)
test -d "\$file" &&
find "\$file" -depth -type d -exec rmdir '{}' ';' 2>/dev/null
;;
esac
done
rm "$CONFIG_DIR/$CONFIG_FILES" 2>/dev/null
rm "$CONFIG_DIR/$CONFIG" 2>/dev/null
rmdir "$CONFIG_DIR" 2>/dev/null
exit 0
EOF
chmod 0755 $INSTALLATION_DIR/$UNINSTALL
echo $INSTALLATION_DIR/$UNINSTALL >> "$CONFIG_DIR/$CONFIG_FILES"
test -n "$REMOVE_INSTALLATION_DIR" &&
echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"