#
# Automatically generated by blueprint(7).  Edit at your own risk.
#

set -x

cd "$(dirname "$0")"

MD5SUM="$(md5sum "/etc/aliases" 2>/dev/null)"
mkdir -p "/etc"
cat >"/etc/aliases" <<EOF
# See man 5 aliases for format
postmaster:    root
EOF
[ "$MD5SUM" != "$(md5sum "/etc/aliases")" ] && SERVICE_sysvinit_postfix=1
mkdir -p "/etc"
base64 --decode >"/etc/aliases.db" <<EOF
 
EOF
mkdir -p "/etc/apt/apt.conf.d"
cat >"/etc/apt/apt.conf.d/00CDMountPoint" <<EOF
Acquire::cdrom {
  mount "/media/cdrom";
};
Dir::Media::MountPath "/media/cdrom";
EOF
mkdir -p "/etc/apt/apt.conf.d"
cat >"/etc/apt/apt.conf.d/00aptitude" <<EOF
Aptitude::Get-Root-Command "sudo:/usr/bin/sudo";
EOF
mkdir -p "/etc/apt"
cat >"/etc/apt/sources.list" <<EOF
# 

# deb cdrom:[Ubuntu-Server 12.04 LTS _Precise Pangolin_ - Release i386 (20120424.1)]/ precise main restricted

#deb cdrom:[Ubuntu-Server 12.04 LTS _Precise Pangolin_ - Release i386 (20120424.1)]/ precise main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu/ precise main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ precise main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu/ precise universe
deb-src http://us.archive.ubuntu.com/ubuntu/ precise universe
deb http://us.archive.ubuntu.com/ubuntu/ precise-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://us.archive.ubuntu.com/ubuntu/ precise multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ precise multiverse
deb http://us.archive.ubuntu.com/ubuntu/ precise-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu precise-security main restricted
deb-src http://security.ubuntu.com/ubuntu precise-security main restricted
deb http://security.ubuntu.com/ubuntu precise-security universe
deb-src http://security.ubuntu.com/ubuntu precise-security universe
deb http://security.ubuntu.com/ubuntu precise-security multiverse
deb-src http://security.ubuntu.com/ubuntu precise-security multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu precise partner
# deb-src http://archive.canonical.com/ubuntu precise partner

## Uncomment the following two lines to add software from Ubuntu's
## 'extras' repository.
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
# deb http://extras.ubuntu.com/ubuntu precise main
# deb-src http://extras.ubuntu.com/ubuntu precise main
EOF
MD5SUM="$(md5sum "/etc/default/console-setup" 2>/dev/null)"
mkdir -p "/etc/default"
cat >"/etc/default/console-setup" <<EOF
# Change to "yes" and setupcon will explain what is being doing
VERBOSE_OUTPUT="no"

# Setup these consoles.  Most people do not need to change this.
ACTIVE_CONSOLES="/dev/tty[1-6]"

# Put here your encoding.  Valid charmaps are: UTF-8 ARMSCII-8 CP1251
# CP1255 CP1256 GEORGIAN-ACADEMY GEORGIAN-PS IBM1133 ISIRI-3342
# ISO-8859-1 ISO-8859-2 ISO-8859-3 ISO-8859-4 ISO-8859-5 ISO-8859-6
# ISO-8859-7 ISO-8859-8 ISO-8859-9 ISO-8859-10 ISO-8859-11 ISO-8859-13
# ISO-8859-14 ISO-8859-15 ISO-8859-16 KOI8-R KOI8-U TIS-620 VISCII
CHARMAP="UTF-8"

# The codeset determines which symbols are supported by the font.
# Valid codesets are: Arabic Armenian CyrAsia CyrKoi CyrSlav Ethiopian
# Georgian Greek Hebrew Lao Lat15 Lat2 Lat38 Lat7 Thai Uni1 Uni2 Uni3
# Vietnamese.  Read README.fonts for explanation.
CODESET="Uni2"

# Valid font faces are: VGA (sizes 8, 14 and 16), Terminus (sizes
# 12x6, 14, 16, 20x10, 24x12, 28x14 and 32x16), TerminusBold (sizes
# 14, 16, 20x10, 24x12, 28x14 and 32x16), TerminusBoldVGA (sizes 14
# and 16) and Fixed (sizes 13, 14, 15, 16 and 18).  Only when
# CODESET=Ethiopian: Goha (sizes 12, 14 and 16) and 
# GohaClassic (sizes 12, 14 and 16).
# Set FONTFACE and FONTSIZE to empty strings if you want setupcon to
# set up the keyboard but to leave the console font unchanged.
FONTFACE="Fixed"
FONTSIZE="16"

# You can also directly specify nonstandard font or console map to load.
# Use space as separator if you want to load more than one font.
# You can use FONT_MAP in order to specify the Unicode map of the font
# in case the font doesn't have it embedded.

# FONT='lat9w-08.psf.gz brl-8x8.psf'
# FONT_MAP=/usr/share/consoletrans/lat9u.uni
# CONSOLE_MAP=/usr/local/share/consoletrans/my_special_encoding.acm

# You can also specify a screen size that setupcon will enforce.  This can not
# exceed what the current screen resolution can display according to the size of
# the loaded font.
#
# SCREEN_WIDTH=80
# SCREEN_HEIGHT=25

if [ -f /etc/default/keyboard ]; then
    . /etc/default/keyboard
fi
EOF
[ "$MD5SUM" != "$(md5sum "/etc/default/console-setup")" ] && SERVICE_sysvinit_ssh=1
[ "$MD5SUM" != "$(md5sum "/etc/default/console-setup")" ] && SERVICE_sysvinit_ntp=1
MD5SUM="$(md5sum "/etc/default/keyboard" 2>/dev/null)"
mkdir -p "/etc/default"
cat >"/etc/default/keyboard" <<EOF
# Check /usr/share/doc/keyboard-configuration/README.Debian for
# documentation on what to do after having modified this file.

# The following variables describe your keyboard and can have the same
# values as the XkbModel, XkbLayout, XkbVariant and XkbOptions options
# in /etc/X11/xorg.conf.

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""

# If you don't want to use the XKB layout on the console, you can
# specify an alternative keymap.  Make sure it will be accessible
# before /usr is mounted.
# KMAP=/etc/console-setup/defkeymap.kmap.gz
EOF
[ "$MD5SUM" != "$(md5sum "/etc/default/keyboard")" ] && SERVICE_sysvinit_ssh=1
[ "$MD5SUM" != "$(md5sum "/etc/default/keyboard")" ] && SERVICE_sysvinit_ntp=1
MD5SUM="$(md5sum "/etc/default/locale" 2>/dev/null)"
mkdir -p "/etc/default"
cat >"/etc/default/locale" <<EOF
LC_ALL="en_US"
LANG=en_US
EOF
[ "$MD5SUM" != "$(md5sum "/etc/default/locale")" ] && SERVICE_sysvinit_ssh=1
[ "$MD5SUM" != "$(md5sum "/etc/default/locale")" ] && SERVICE_sysvinit_ntp=1
MD5SUM="$(md5sum "/etc/default/nfs-common" 2>/dev/null)"
mkdir -p "/etc/default"
cat >"/etc/default/nfs-common" <<EOF
# If you do not set values for the NEED_ options, they will be attempted
# autodetected; this should be sufficient for most people. Valid alternatives
# for the NEED_ options are "yes" and "no".

# Do you want to start the statd daemon? It is not needed for NFSv4.
NEED_STATD=

# Options for rpc.statd.
#   Should rpc.statd listen on a specific port? This is especially useful
#   when you have a port-based firewall. To use a fixed port, set this
#   this variable to a statd argument like: "--port 4000 --outgoing-port 4001".
#   For more information, see rpc.statd(8) or http://wiki.debian.org/SecuringNFS
STATDOPTS=

# Do you want to start the gssd daemon? It is required for Kerberos mounts.
NEED_GSSD=
EOF
[ "$MD5SUM" != "$(md5sum "/etc/default/nfs-common")" ] && SERVICE_sysvinit_ssh=1
[ "$MD5SUM" != "$(md5sum "/etc/default/nfs-common")" ] && SERVICE_sysvinit_ntp=1
MD5SUM="$(md5sum "/etc/default/ntfs-3g" 2>/dev/null)"
mkdir -p "/etc/default"
cat >"/etc/default/ntfs-3g" <<EOF
# /etc/default/ntfs-3g

NTFS3G_INITRAMFS="true"
EOF
[ "$MD5SUM" != "$(md5sum "/etc/default/ntfs-3g")" ] && SERVICE_sysvinit_ssh=1
[ "$MD5SUM" != "$(md5sum "/etc/default/ntfs-3g")" ] && SERVICE_sysvinit_ntp=1
mkdir -p "/etc"
cat >"/etc/hosts" <<EOF
127.0.0.1	localhost
127.0.1.1	wowf.localdomain wowf precise32

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
mkdir -p "/etc"
cat >"/etc/idmapd.conf" <<EOF
[General]

Verbosity = 0
Pipefs-Directory = /run/rpc_pipefs
# set your own domain here, if id differs from FQDN minus hostname
# Domain = localdomain

[Mapping]

Nobody-User = nobody
Nobody-Group = nogroup
EOF
mkdir -p "/etc/init.d"
cat >"/etc/init.d/vboxadd" <<EOF
#! /bin/sh
#
# Linux Additions kernel module init script (\$Revision: 75649 \$)
#

#
# Copyright (C) 2006-2010 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# 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 70
# description: VirtualBox Linux Additions kernel modules
#
### BEGIN INIT INFO
# Provides:       vboxadd
# Required-Start:
# Required-Stop:
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Description:    VirtualBox Linux Additions kernel modules
### END INIT INFO

PATH=\$PATH:/bin:/sbin:/usr/sbin
PACKAGE=VBoxGuestAdditions
LOG="/var/log/vboxadd-install.log"
MODPROBE=/sbin/modprobe
OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"

if \$MODPROBE -c | grep -q '^allow_unsupported_modules  *0'; then
  MODPROBE="\$MODPROBE --allow-unsupported-modules"
fi

# Check architecture
cpu=\`uname -m\`;
case "\$cpu" in
  i[3456789]86|x86)
    cpu="x86"
    lib_path="/usr/lib"
    ;;
  x86_64|amd64)
    cpu="amd64"
    if test -d "/usr/lib64"; then
      lib_path="/usr/lib64"
    else
      lib_path="/usr/lib"
    fi
    ;;
esac

if [ -f /etc/arch-release ]; then
    system=arch
elif [ -f /etc/redhat-release ]; then
    system=redhat
elif [ -f /etc/SuSE-release ]; then
    system=suse
elif [ -f /etc/gentoo-release ]; then
    system=gentoo
elif [ -f /etc/lfs-release -a -d /etc/rc.d/init.d ]; then
    system=lfs
else
    system=other
fi

if [ "\$system" = "arch" ]; then
    USECOLOR=yes
    . /etc/rc.d/functions
    fail_msg() {
        stat_fail
    }

    succ_msg() {
        stat_done
    }

    begin() {
        stat_busy "\$1"
    }
fi

if [ "\$system" = "redhat" ]; then
    . /etc/init.d/functions
    fail_msg() {
        echo_failure
        echo
    }
    succ_msg() {
        echo_success
        echo
    }
    begin() {
        echo -n "\$1"
    }
fi

if [ "\$system" = "suse" ]; then
    . /etc/rc.status
    fail_msg() {
        rc_failed 1
        rc_status -v
    }
    succ_msg() {
        rc_reset
        rc_status -v
    }
    begin() {
        echo -n "\$1"
    }
fi

if [ "\$system" = "gentoo" ]; then
    if [ -f /sbin/functions.sh ]; then
        . /sbin/functions.sh
    elif [ -f /etc/init.d/functions.sh ]; then
        . /etc/init.d/functions.sh
    fi
    fail_msg() {
        eend 1
    }
    succ_msg() {
        eend \$?
    }
    begin() {
        ebegin \$1
    }
    if [ "\`which \$0\`" = "/sbin/rc" ]; then
        shift
    fi
fi

if [ "\$system" = "lfs" ]; then
    . /etc/rc.d/init.d/functions
    fail_msg() {
        echo_failure
    }
    succ_msg() {
        echo_ok
    }
    begin() {
        echo \$1
    }
fi

if [ "\$system" = "other" ]; then
    fail_msg() {
        echo " ...fail!"
    }
    succ_msg() {
        echo " ...done."
    }
    begin() {
        echo -n \$1
    }
fi

show_error()
{
    if [ "\$system" = "gentoo" ]; then
        eerror \$1
    fi
    fail_msg
    echo "(\$1)"
}

fail()
{
    show_error "\$1"
    exit 1
}

dev=/dev/vboxguest
userdev=/dev/vboxuser
config=/var/lib/VBoxGuestAdditions/config
owner=vboxadd
group=1

test_for_gcc_and_make()
{
    which make > /dev/null 2>&1 || printf "\\nThe make utility was not found. If the following module compilation fails then\\nthis could be the reason and you should try installing it.\\n"
    which gcc > /dev/null 2>&1 || printf "\\nThe gcc utility was not found. If the following module compilation fails then\\nthis could be the reason and you should try installing it.\\n"
}

test_sane_kernel_dir()
{
    KERN_VER=\`uname -r\`
    KERN_DIR="/lib/modules/\$KERN_VER/build"
    if [ -d "\$KERN_DIR" ]; then
        KERN_REL=\`make -sC \$KERN_DIR --no-print-directory kernelrelease 2>/dev/null || true\`
        if [ -z "\$KERN_REL" -o "x\$KERN_REL" = "x\$KERN_VER" ]; then
            return 0
        fi
    fi
    printf "\\nThe headers for the current running kernel were not found. If the following\\nmodule compilation fails then this could be the reason.\\n"
    if [ "\$system" = "redhat" ]; then
        if echo "\$KERN_VER" | grep -q "uek"; then
            printf "The missing package can be probably installed with\\nyum install kernel-uek-devel-\$KERN_VER\\n"
        else
            printf "The missing package can be probably installed with\\nyum install kernel-devel-\$KERN_VER\\n"
        fi
    elif [ "\$system" = "suse" ]; then
        KERN_VER_SUSE=\`echo "\$KERN_VER" | sed 's/.*-\\([^-]*\\)/\\1/g'\`
        KERN_VER_BASE=\`echo "\$KERN_VER" | sed 's/\\(.*\\)-[^-]*/\\1/g'\`
        printf "The missing package can be probably installed with\\nzypper install kernel-\$KERN_VER_SUSE-devel-\$KERN_VER_BASE\\n"
    elif [ "\$system" = "debian" ]; then
        printf "The missing package can be probably installed with\\napt-get install linux-headers-\$KERN_VER\\n"
    fi
}

running_vboxguest()
{
    lsmod | grep -q "vboxguest[^_-]"
}

running_vboxadd()
{
    lsmod | grep -q "vboxadd[^_-]"
}

running_vboxsf()
{
    lsmod | grep -q "vboxsf[^_-]"
}

do_vboxguest_non_udev()
{
    if [ ! -c \$dev ]; then
        maj=\`sed -n 's;\\([0-9]\\+\\) vboxguest;\\1;p' /proc/devices\`
        if [ ! -z "\$maj" ]; then
            min=0
        else
            min=\`sed -n 's;\\([0-9]\\+\\) vboxguest;\\1;p' /proc/misc\`
            if [ ! -z "\$min" ]; then
                maj=10
            fi
        fi
        test -z "\$maj" && {
            rmmod vboxguest 2>/dev/null
            fail "Cannot locate the VirtualBox device"
        }

        mknod -m 0664 \$dev c \$maj \$min || {
            rmmod vboxguest 2>/dev/null
            fail "Cannot create device \$dev with major \$maj and minor \$min"
        }
    fi
    chown \$owner:\$group \$dev 2>/dev/null || {
        rm -f \$dev 2>/dev/null
        rm -f \$userdev 2>/dev/null
        rmmod vboxguest 2>/dev/null
        fail "Cannot change owner \$owner:\$group for device \$dev"
    }

    if [ ! -c \$userdev ]; then
        maj=10
        min=\`sed -n 's;\\([0-9]\\+\\) vboxuser;\\1;p' /proc/misc\`
        if [ ! -z "\$min" ]; then
            mknod -m 0666 \$userdev c \$maj \$min || {
                rm -f \$dev 2>/dev/null
                rmmod vboxguest 2>/dev/null
                fail "Cannot create device \$userdev with major \$maj and minor \$min"
            }
            chown \$owner:\$group \$userdev 2>/dev/null || {
                rm -f \$dev 2>/dev/null
                rm -f \$userdev 2>/dev/null
                rmmod vboxguest 2>/dev/null
                fail "Cannot change owner \$owner:\$group for device \$userdev"
            }
        fi
    fi
}

start()
{
    begin "Starting the VirtualBox Guest Additions ";
    uname -r | grep -q '^2\\.6' 2>/dev/null &&
        ps -A -o comm | grep -q '/*udevd\$' 2>/dev/null ||
        no_udev=1
    running_vboxguest || {
        rm -f \$dev || {
            fail "Cannot remove \$dev"
        }

        rm -f \$userdev || {
            fail "Cannot remove \$userdev"
        }

        \$MODPROBE vboxguest >/dev/null 2>&1 || {
            fail "modprobe vboxguest failed"
        }
        case "\$no_udev" in 1)
            sleep .5;;
        esac
    }
    case "\$no_udev" in 1)
        do_vboxguest_non_udev;;
    esac

    running_vboxsf || {
        \$MODPROBE vboxsf > /dev/null 2>&1 || {
            if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
                fail_msg
                echo "Unable to start shared folders support.  Make sure that your VirtualBox build"
                echo "supports this feature."
                exit 1
            fi
            fail "modprobe vboxsf failed"
        }
    }

    # Mount all shared folders from /etc/fstab. Normally this is done by some
    # other startup script but this requires the vboxdrv kernel module loaded.
    # This isn't necessary anymore as the vboxsf module is autoloaded.
    # mount -a -t vboxsf

    succ_msg
    return 0
}

stop()
{
    begin "Stopping VirtualBox Additions ";
    if ! umount -a -t vboxsf 2>/dev/null; then
        fail "Cannot unmount vboxsf folders"
    fi
    if running_vboxsf; then
        rmmod vboxsf 2>/dev/null || fail "Cannot unload module vboxsf"
    fi
    if running_vboxguest; then
        rmmod vboxguest 2>/dev/null || fail "Cannot unload module vboxguest"
        rm -f \$userdev || fail "Cannot unlink \$userdev"
        rm -f \$dev || fail "Cannot unlink \$dev"
    fi
    succ_msg
    return 0
}

restart()
{
    stop && start
    return 0
}

# Remove any existing VirtualBox guest kernel modules from the disk, but not
# from the kernel as they may still be in use
cleanup_modules()
{
    begin "Removing existing VirtualBox DKMS kernel modules"
    \$DODKMS uninstall \$OLDMODULES > \$LOG
    succ_msg
    begin "Removing existing VirtualBox non-DKMS kernel modules"
    for i in \$OLDMODULES; do
        find /lib/modules -name \$i\\* | xargs rm 2>/dev/null
    done
    succ_msg
}

# Build and install the VirtualBox guest kernel modules
setup_modules()
{
    # don't stop the old modules here -- they might be in use
    cleanup_modules
    begin "Building the VirtualBox Guest Additions kernel modules"

    # Short cut out if a dkms build succeeds
    if \$DODKMS install vboxguest \$INSTALL_VER >> \$LOG 2>&1; then
        succ_msg
        return 0
    fi

    test_for_gcc_and_make
    test_sane_kernel_dir

    echo
    begin "Building the main Guest Additions module"
    if ! \$BUILDINTMP \\
        --save-module-symvers /tmp/vboxguest-Module.symvers \\
        --module-source \$MODULE_SRC/vboxguest \\
        --no-print-directory install >> \$LOG 2>&1; then
        show_error "Look at \$LOG to find out what went wrong"
        return 1
    fi
    succ_msg
    begin "Building the shared folder support module"
    if ! \$BUILDINTMP \\
        --use-module-symvers /tmp/vboxguest-Module.symvers \\
        --module-source \$MODULE_SRC/vboxsf \\
        --no-print-directory install >> \$LOG 2>&1; then
        show_error  "Look at \$LOG to find out what went wrong"
        return 1
    fi
    succ_msg
    if expr \`uname -r\` '<' '2.6.27' > /dev/null; then
        echo "Not building the VirtualBox advanced graphics driver as this Linux version is"
        echo "too old to use it."
    else
        begin "Building the OpenGL support module"
        if ! \$BUILDINTMP \\
            --use-module-symvers /tmp/vboxguest-Module.symvers \\
            --module-source \$MODULE_SRC/vboxvideo \\
            --no-print-directory install >> \$LOG 2>&1; then
            show_error "Look at \$LOG to find out what went wrong"
            return 1
        fi
        succ_msg
    fi
    depmod
    return 0
}

# Do non-kernel bits needed for the kernel modules to work properly (user
# creation, udev, mount helper...)
extra_setup()
{
    begin "Doing non-kernel setup of the Guest Additions"
    echo "Creating user for the Guest Additions." >> \$LOG
    # This is the LSB version of useradd and should work on recent
    # distributions
    useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
    # And for the others, we choose a UID ourselves
    useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1

    # Add a group "vboxsf" for Shared Folders access
    # All users which want to access the auto-mounted Shared Folders have to
    # be added to this group.
    groupadd -f vboxsf >/dev/null 2>&1

    # Create udev description file
    if [ -d /etc/udev/rules.d ]; then
        echo "Creating udev rule for the Guest Additions kernel module." >> \$LOG
        udev_call=""
        udev_app=\`which udevadm 2> /dev/null\`
        if [ \$? -eq 0 ]; then
            udev_call="\${udev_app} version 2> /dev/null"
        else
            udev_app=\`which udevinfo 2> /dev/null\`
            if [ \$? -eq 0 ]; then
                udev_call="\${udev_app} -V 2> /dev/null"
            fi
        fi
        udev_fix="="
        if [ "\${udev_call}" != "" ]; then
            udev_out=\`\${udev_call}\`
            udev_ver=\`expr "\$udev_out" : '[^0-9]*\\([0-9]*\\)'\`
            if [ "\$udev_ver" = "" -o "\$udev_ver" -lt 55 ]; then
               udev_fix=""
            fi
        fi
        ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
        echo "KERNEL=\${udev_fix}\\"vboxguest\\", NAME=\\"vboxguest\\", OWNER=\\"vboxadd\\", MODE=\\"0660\\"" > /etc/udev/rules.d/60-vboxadd.rules
        echo "KERNEL=\${udev_fix}\\"vboxuser\\", NAME=\\"vboxuser\\", OWNER=\\"vboxadd\\", MODE=\\"0666\\"" >> /etc/udev/rules.d/60-vboxadd.rules
    fi

    # Put mount.vboxsf in the right place
    ln -sf "\$lib_path/\$PACKAGE/mount.vboxsf" /sbin
    # At least Fedora 11 and Fedora 12 require the correct security context when
    # executing this command from service scripts. Shouldn't hurt for other
    # distributions.
    chcon -u system_u -t mount_exec_t "\$lib_path/\$PACKAGE/mount.vboxsf" > /dev/null 2>&1
    # And at least Fedora 15 needs this for the acceleration support check to
    # work
    redhat_release=\`cat /etc/redhat-release 2> /dev/null\`
    case "\$redhat_release" in Fedora\\ release\\ 15* )
        for i in "\$lib_path"/*.so
        do
            restorecon "\$i" >/dev/null
        done
        ;;
    esac

    succ_msg
}

# setup_script
setup()
{
    if test -r \$config; then
      . \$config
    else
      fail "Configuration file \$config not found"
    fi
    test -n "\$INSTALL_DIR" -a -n "\$INSTALL_VER" ||
      fail "Configuration file \$config not complete"
    export BUILD_TYPE
    export USERNAME

    MODULE_SRC="\$INSTALL_DIR/src/vboxguest-\$INSTALL_VER"
    BUILDINTMP="\$MODULE_SRC/build_in_tmp"
    DODKMS="\$MODULE_SRC/do_dkms"
    chcon -t bin_t "\$BUILDINTMP" > /dev/null 2>&1
    chcon -t bin_t "\$DODKMS"     > /dev/null 2>&1

    setup_modules
    mod_succ="\$?"
    extra_setup
    if [ "\$mod_succ" -eq "0" ]; then
        if running_vboxguest || running_vboxadd; then
            printf "You should restart your guest to make sure the new modules are actually used\\n\\n"
        else
            start
        fi
    fi
}

# cleanup_script
cleanup()
{
    if test -r \$config; then
      . \$config
      test -n "\$INSTALL_DIR" -a -n "\$INSTALL_VER" ||
        fail "Configuration file \$config not complete"
      DODKMS="\$INSTALL_DIR/src/vboxguest-\$INSTALL_VER/do_dkms"
    elif test -x ./do_dkms; then  # Executing as part of the installer...
      DODKMS=./do_dkms
    else
      fail "Configuration file \$config not found"
    fi

    # Delete old versions of VBox modules.
    cleanup_modules
    depmod

    # Remove old module sources
    for i in \$OLDMODULES; do
      rm -rf /usr/src/\$i-*
    done

    # Remove other files
    rm /sbin/mount.vboxsf 2>/dev/null
    rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
}

dmnstatus()
{
    if running_vboxguest; then
        echo "The VirtualBox Additions are currently running."
    else
        echo "The VirtualBox Additions are not currently running."
    fi
}

case "\$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    restart
    ;;
setup)
    setup
    ;;
cleanup)
    cleanup
    ;;
status)
    dmnstatus
    ;;
*)
    echo "Usage: \$0 {start|stop|restart|status|setup}"
    exit 1
esac

exit
EOF
chmod 0755 "/etc/init.d/vboxadd"
mkdir -p "/etc/init.d"
cat >"/etc/init.d/vboxadd-service" <<EOF
#!/bin/sh
#
# Linux Additions Guest Additions service daemon init script.
#
# Copyright (C) 2006-2010 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# 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 35 65
# description: VirtualBox Additions service
#
### BEGIN INIT INFO
# Provides:       vboxadd-service
# Required-Start: vboxadd
# Required-Stop:  vboxadd
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Description:    VirtualBox Additions Service
### END INIT INFO

PATH=\$PATH:/bin:/sbin:/usr/sbin

system=unknown
if [ -f /etc/redhat-release ]; then
    system=redhat
    PIDFILE="/var/lock/subsys/vboxadd-service"
elif [ -f /etc/SuSE-release ]; then
    system=suse
    PIDFILE="/var/run/vboxadd-service"
elif [ -f /etc/debian_version ]; then
    system=debian
    PIDFILE="/var/run/vboxadd-service"
elif [ -f /etc/gentoo-release ]; then
    system=gentoo
    PIDFILE="/var/run/vboxadd-service"
elif [ -f /etc/arch-release ]; then
     system=arch
     PIDFILE="/var/run/vboxadd-service"
elif [ -f /etc/slackware-version ]; then
    system=slackware
    PIDFILE="/var/run/vboxadd-service"
elif [ -f /etc/lfs-release ]; then
    system=lfs
    PIDFILE="/var/run/vboxadd-service.pid"
else
    system=other
    if [ -d /var/run -a -w /var/run ]; then
        PIDFILE="/var/run/vboxadd-service"
    fi
fi

if [ "\$system" = "redhat" ]; then
    . /etc/init.d/functions
    fail_msg() {
        echo_failure
        echo
    }

    succ_msg() {
        echo_success
        echo
    }

    begin() {
        echo -n "\$1"
    }
fi

if [ "\$system" = "suse" ]; then
    . /etc/rc.status
    daemon() {
        startproc \${1+"\$@"}
    }

    fail_msg() {
        rc_failed 1
        rc_status -v
    }

    succ_msg() {
        rc_reset
        rc_status -v
    }

    begin() {
        echo -n "\$1"
    }
fi

if [ "\$system" = "debian" ]; then
    daemon() {
        start-stop-daemon --start --exec \$1 -- \$2
    }

    killproc() {
        start-stop-daemon --stop --retry 2 --exec \$@
    }

    fail_msg() {
        echo " ...fail!"
    }

    succ_msg() {
        echo " ...done."
    }

    begin() {
        echo -n "\$1"
    }
fi

if [ "\$system" = "gentoo" ]; then
    if [ -f /sbin/functions.sh ]; then
        . /sbin/functions.sh
    elif [ -f /etc/init.d/functions.sh ]; then
        . /etc/init.d/functions.sh
    fi
    daemon() {
        start-stop-daemon --start --exec \$1 -- \$2
    }

    killproc() {
        start-stop-daemon --stop --retry 2 --exec \$@
    }

    fail_msg() {
        echo " ...fail!"
    }

    succ_msg() {
        echo " ...done."
    }

    begin() {
        echo -n "\$1"
    }

    if [ "\`which \$0\`" = "/sbin/rc" ]; then
        shift
    fi
fi

if [ "\$system" = "arch" ]; then
    USECOLOR=yes
    . /etc/rc.d/functions
    daemon() {
        \$@
        test \$? -eq 0 && add_daemon rc.\`basename \$1\`
    }

    killproc() {
        killall \$@
        rm_daemon \`basename \$@\`
    }

    fail_msg() {
        stat_fail
    }

    succ_msg() {
        stat_done
    }

    begin() {
        stat_busy "\$1"
    }

fi

if [ "\$system" = "slackware" -o "\$system" = "other" ]; then
    daemon() {
        \$1 \$2
    }

    killproc() {
        killall \$1
        rm -f \$PIDFILE
    }

    fail_msg() {
        echo " ...fail!"
    }

    succ_msg() {
        echo " ...done."
    }

    begin() {
        echo -n "\$1"
    }

fi

if [ "\$system" = "lfs" ]; then
    . /etc/rc.d/init.d/functions
    daemon() {
        loadproc \$1 \$2
    }

    fail_msg() {
        echo_failure
    }

    succ_msg() {
        echo_ok
    }

    begin() {
        echo \$1
    }

    status() {
        statusproc \$1
    }
fi

binary=/usr/sbin/VBoxService

testbinary() {
    test -x "\$binary" || {
        echo "Cannot run \$binary"
        exit 1
    }
}

vboxaddrunning() {
    lsmod | grep -q "vboxguest[^_-]"
}

start() {
    if ! test -f \$PIDFILE; then
        begin "Starting VirtualBox Guest Addition service ";
        vboxaddrunning || {
            echo "VirtualBox Additions module not loaded!"
            exit 1
        }
        testbinary
        daemon \$binary > /dev/null
        RETVAL=\$?
        test \$RETVAL -eq 0 && echo \`pidof VBoxService\` > \$PIDFILE
        succ_msg
    fi
    return \$RETVAL
}

stop() {
    if test -f \$PIDFILE; then
        begin "Stopping VirtualBox Guest Addition service ";
        killproc \$binary
        RETVAL=\$?
        if ! pidof VBoxService > /dev/null 2>&1; then
            rm -f \$PIDFILE
            succ_msg
        else
            fail_msg
        fi
    fi
    return \$RETVAL
}

restart() {
    stop && start
}

status() {
    echo -n "Checking for VBoxService"
    if [ -f \$PIDFILE ]; then
        echo " ...running"
    else
        echo " ...not running"
    fi
}

case "\$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    restart
    ;;
status)
    status
    ;;
setup)
    ;;
cleanup)
    ;;
*)
    echo "Usage: \$0 {start|stop|restart|status}"
    exit 1
esac

exit \$RETVAL
EOF
chmod 0755 "/etc/init.d/vboxadd-service"
mkdir -p "/etc/init.d"
cat >"/etc/init.d/vboxadd-x11" <<EOFEOF
#! /bin/sh
#
# Linux Additions X11 setup init script (\$Revision: 77056 \$)
#

#
# Copyright (C) 2006-2010 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# 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 70
# description: VirtualBox Linux Additions kernel modules
#
### BEGIN INIT INFO
# Provides:       vboxadd-x11
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Description:    VirtualBox Linux Additions X11 setup
### END INIT INFO

PATH=\$PATH:/bin:/sbin:/usr/sbin
LOG="/var/log/vboxadd-install-x11.log"
CONFIG_DIR="/var/lib/VBoxGuestAdditions"
CONFIG="config"

# Check architecture
cpu=\`uname -m\`;
case "\$cpu" in
  i[3456789]86|x86)
    cpu="x86"
    LIB="/usr/lib"
    ;;
  x86_64|amd64)
    cpu="amd64"
    if test -d "/usr/lib64"; then
      LIB="/usr/lib64"
    else
      LIB="/usr/lib"
    fi
    ;;
esac

# Find the version of X installed
# The last of the three is for the X.org 6.7 included in Fedora Core 2
xver=\`X -version 2>&1\`
x_version=\`echo "\$xver" | sed -n 's/^X Window System Version \\([0-9.]\\+\\)/\\1/p'\`\`echo "\$xver" | sed -n 's/^XFree86 Version \\([0-9.]\\+\\)/\\1/p'\`\`echo "\$xver" | sed -n 's/^X Protocol Version 11, Revision 0, Release \\([0-9.]\\+\\)/\\1/p'\`\`echo "\$xver" | sed -n 's/^X.Org X Server \\([0-9.]\\+\\)/\\1/p'\`
# Version of Redhat or Fedora installed.  Needed for setting up selinux policy.
redhat_release=\`cat /etc/redhat-release 2> /dev/null\`
# All the different possible locations for XFree86/X.Org configuration files
# - how many of these have ever been used?
x11conf_files="/etc/X11/xorg.conf /etc/X11/xorg.conf-4 /etc/X11/.xorg.conf \\
    /etc/xorg.conf /usr/etc/X11/xorg.conf-4 /usr/etc/X11/xorg.conf \\
    /usr/lib/X11/xorg.conf-4 /usr/lib/X11/xorg.conf /etc/X11/XF86Config-4 \\
    /etc/X11/XF86Config /etc/XF86Config /usr/X11R6/etc/X11/XF86Config-4 \\
    /usr/X11R6/etc/X11/XF86Config /usr/X11R6/lib/X11/XF86Config-4 \\
    /usr/X11R6/lib/X11/XF86Config"

if [ -f /etc/arch-release ]; then
    system=arch
elif [ -f /etc/redhat-release ]; then
    system=redhat
elif [ -f /etc/debian_version ]; then
    system=debian
elif [ -f /etc/SuSE-release ]; then
    system=suse
elif [ -f /etc/gentoo-release ]; then
    system=gentoo
elif [ -f /etc/lfs-release -a -d /etc/rc.d/init.d ]; then
    system=lfs
else
    system=other
fi

if [ "\$system" = "arch" ]; then
    USECOLOR=yes
    . /etc/rc.d/functions
    fail_msg() {
        stat_fail
    }

    succ_msg() {
        stat_done
    }

    begin() {
        stat_busy "\$1"
    }
fi

if [ "\$system" = "redhat" ]; then
    . /etc/init.d/functions
    fail_msg() {
        echo_failure
        echo
    }
    succ_msg() {
        echo_success
        echo
    }
    begin() {
        echo -n "\$1"
    }
fi

if [ "\$system" = "suse" ]; then
    . /etc/rc.status
    fail_msg() {
        rc_failed 1
        rc_status -v
    }
    succ_msg() {
        rc_reset
        rc_status -v
    }
    begin() {
        echo -n "\$1"
    }
fi

if [ "\$system" = "gentoo" ]; then
    if [ -f /sbin/functions.sh ]; then
        . /sbin/functions.sh
    elif [ -f /etc/init.d/functions.sh ]; then
        . /etc/init.d/functions.sh
    fi
    fail_msg() {
        eend 1
    }
    succ_msg() {
        eend \$?
    }
    begin() {
        ebegin \$1
    }
    if [ "\`which \$0\`" = "/sbin/rc" ]; then
        shift
    fi
fi

if [ "\$system" = "lfs" ]; then
    . /etc/rc.d/init.d/functions
    fail_msg() {
        echo_failure
    }
    succ_msg() {
        echo_ok
    }
    begin() {
        echo \$1
    }
fi

if [ "\$system" = "debian" -o "\$system" = "other" ]; then
    fail_msg() {
        echo " ...fail!"
    }
    succ_msg() {
        echo " ...done."
    }
    begin() {
        echo -n \$1
    }
fi

dev=/dev/vboxguest
userdev=/dev/vboxuser
owner=vboxadd
group=1

fail()
{
    if [ "\$system" = "gentoo" ]; then
        eerror \$1
        exit 1
    fi
    fail_msg
    echo "(\$1)"
    exit 1
}

# Install an X11 desktop startup application.  The application should be a shell script.
# Its name should be purely alphanumeric and should start with a two digit number (preferably
# 98 or thereabouts) to indicate its place in the Debian Xsession startup order.
#
# syntax: install_x11_startup_app app desktop service_name
install_x11_startup_app() {
    self="install_x11_startup_app"
    app_src=\$1
    desktop_src=\$2
    service_name=\$3
    alt_command=\$4
    test -r "\$app_src" ||
        { echo >> \$LOG "\$self: no script given"; return 1; }
    test -r "\$desktop_src" ||
        { echo >> \$LOG "\$self: no desktop file given"; return 1; }
    test -n "\$service_name" ||
        { echo >> \$LOG "\$self: no service given"; return 1; }
    test -n "\$alt_command" ||
        { echo >> \$LOG "\$self: no service given"; return 1; }
    app_dest=\`basename \$app_src sh\`
    app_dest_sh=\`basename \$app_src sh\`.sh
    desktop_dest=\`basename \$desktop_src\`
    found=0
    x11_autostart="/etc/xdg/autostart"
    kde_autostart="/usr/share/autostart"
    redhat_dir=/etc/X11/Xsession.d
    mandriva_dir=/etc/X11/xinit.d
    debian_dir=/etc/X11/xinit/xinitrc.d
    if [ -d "\$mandriva_dir" -a -w "\$mandriva_dir" -a -x "\$mandriva_dir" ]
    then
        install -m 0644 \$app_src "\$mandriva_dir/\$app_dest"
        found=1
    fi
    if [ -d "\$x11_autostart" -a -w "\$x11_autostart" -a -x "\$x11_autostart" ]
    then
        install -m 0644 \$desktop_src "\$x11_autostart/\$desktop_dest"
        found=1
    fi
    if [ -d "\$kde_autostart" -a -w "\$kde_autostart" -a -x "\$kde_autostart" ]
    then
        install -m 0644 \$desktop_src "\$kde_autostart/\$desktop_dest"
        found=1
    fi
    if [ -d "\$redhat_dir" -a -w "\$redhat_dir" -a -x "\$redhat_dir" ]
    then
        install -m 0644 \$app_src "\$redhat_dir/\$app_dest"
        found=1
    fi
    if [ -d "\$debian_dir" -a -w "\$debian_dir" -a -x "\$debian_dir" ]
    then
        install -m 0755 \$app_src "\$debian_dir/\$app_dest_sh"
        found=1
    fi
    if [ \$found -eq 1 ]; then
        return 0
    fi
    cat >> \$LOG << EOF
Could not set up the \$service_name desktop service.
To start it at log-in for a given user, add the command \$alt_command
to the file .xinitrc in their home directory.
EOF
    return 1
}


start()
{
    # Todo: check configuration and correct it if necessary
    return 0
}

stop()
{
    return 0
}

restart()
{
    stop && start
    return 0
}

# setup_script
setup()
{
    echo "VirtualBox Guest Additions installation, Window System and desktop setup" > \$LOG
    begin "Installing the Window System drivers"
    lib_dir="\$LIB/VBoxGuestAdditions"
    share_dir="/usr/share/VBoxGuestAdditions"
    test -x "\$lib_dir" -a -x "\$share_dir" ||
        fail "Invalid Guest Additions configuration found"
    # By default we want to configure X
    dox11config="true"
    # By default, we want to run our xorg.conf setup script
    setupxorgconf="true"
    # On all but the oldest X servers we want to use our new mouse
    # driver.
    newmouse="--newMouse"
    # On more recent servers our kernel mouse driver will be used
    # automatically
    automouse="--autoMouse"
    # We need to tell our xorg.conf hacking script whether /dev/psaux exists
    nopsaux="--nopsaux"
    case "\`uname -r\`" in 2.4.*)
        test -c /dev/psaux && nopsaux="";;
    esac
    # The video driver to install for X.Org 6.9+
    vboxvideo_src=
    # The mouse driver to install for X.Org 6.9+
    vboxmouse_src=
    # The driver extension
    driver_ext=".so"

    modules_dir=\`X -showDefaultModulePath 2>&1\` || modules_dir=
    if [ -z "\$modules_dir" ]; then
        for dir in /usr/lib64/xorg/modules /usr/lib/xorg/modules /usr/X11R6/lib64/modules /usr/X11R6/lib/modules /usr/X11R6/lib/X11/modules; do
            if [ -d \$dir ]; then
                modules_dir=\$dir
                break
            fi
        done
    fi

    test -z "\$x_version" -o -z "\$modules_dir" &&
        fail "Could not find the X.Org or XFree86 Window System."

    echo
    # openSUSE 10.3 shipped X.Org 7.2 with X.Org Server 1.3, but didn't
    # advertise the fact.
    if grep -q '10\\.3' /etc/SuSE-release 2>/dev/null; then
        case \$x_version in 7.2.*)
            x_version=1.3.0;;
        esac
    fi
    case \$x_version in
        1.*.99.* )
            echo "Warning: unsupported pre-release version of X.Org Server installed.  Not"
            echo "installing the X.Org drivers."
            dox11config=""
            ;;
        1.12.* )
            xserver_version="X.Org Server 1.12"
            vboxvideo_src=vboxvideo_drv_112.so
            test "\$system" = "redhat" || setupxorgconf=""
            ;;
        1.11.* )
            xserver_version="X.Org Server 1.11"
            vboxvideo_src=vboxvideo_drv_111.so
            test "\$system" = "redhat" || setupxorgconf=""
            ;;
        1.10.* )
            xserver_version="X.Org Server 1.10"
            vboxvideo_src=vboxvideo_drv_110.so
            test "\$system" = "redhat" || setupxorgconf=""
            ;;
        1.9.* )
            xserver_version="X.Org Server 1.9"
            vboxvideo_src=vboxvideo_drv_19.so
            # Fedora 14 and later patched out vboxvideo detection
            test "\$system" = "redhat" || setupxorgconf=""
            ;;
        1.8.* )
            xserver_version="X.Org Server 1.8"
            vboxvideo_src=vboxvideo_drv_18.so
            # Fedora 13 shipped without vboxvideo detection
            test "\$system" = "redhat" || setupxorgconf=""
            ;;
        1.7.* )
            xserver_version="X.Org Server 1.7"
            vboxvideo_src=vboxvideo_drv_17.so
            setupxorgconf=""
            ;;
        1.6.* )
            xserver_version="X.Org Server 1.6"
            vboxvideo_src=vboxvideo_drv_16.so
            vboxmouse_src=vboxmouse_drv_16.so
            # SUSE SLE* with X.Org 1.6 does not do input autodetection;
            # openSUSE does.
            if grep -q -E '^SLE[^ ]' /etc/SuSE-brand 2>/dev/null; then
                automouse=""
            else
                test "\$system" = "suse" && setupxorgconf=""
            fi
            ;;
        1.5.* )
            xserver_version="X.Org Server 1.5"
            vboxvideo_src=vboxvideo_drv_15.so
            vboxmouse_src=vboxmouse_drv_15.so
            # SUSE with X.Org 1.5 is another special case, and is also
            # handled specially
            test "\$system" = "suse" && automouse=""
            ;;
        1.4.* )
            xserver_version="X.Org Server 1.4"
            vboxvideo_src=vboxvideo_drv_14.so
            vboxmouse_src=vboxmouse_drv_14.so
            automouse=""
            ;;
        1.3.* )
            # This was the first release which gave the server version number
            # rather than the X11 release version when you did 'X -version'.
            xserver_version="X.Org Server 1.3"
            vboxvideo_src=vboxvideo_drv_13.so
            vboxmouse_src=vboxmouse_drv_13.so
            automouse=""
            ;;
        7.1.* | 7.2.* )
            xserver_version="X.Org 7.1"
            vboxvideo_src=vboxvideo_drv_71.so
            vboxmouse_src=vboxmouse_drv_71.so
            automouse=""
            ;;
        6.9.* | 7.0.* )
            xserver_version="X.Org 6.9/7.0"
            vboxvideo_src=vboxvideo_drv_70.so
            vboxmouse_src=vboxmouse_drv_70.so
            automouse=""
            ;;
        6.7* | 6.8.* | 4.2.* | 4.3.* )
            # Assume X.Org post-fork or XFree86
            xserver_version="XFree86 4.2/4.3 and X.Org 6.7/6.8"
            driver_ext=.o
            vboxvideo_src=vboxvideo_drv.o
            vboxmouse_src=vboxmouse_drv.o
            automouse=""
            ;;
        * )
            echo "Warning: unknown version of the X Window System installed.  Not installing"
            echo "X Window System drivers."
            dox11config=""
            ;;
    esac
    begin "Installing \$xserver_version modules"
    rm "\$modules_dir/drivers/vboxvideo_drv\$driver_ext" 2>/dev/null
    rm "\$modules_dir/input/vboxmouse_drv\$driver_ext" 2>/dev/null
    case "\$vboxvideo_src" in ?*)
        ln -s "\$lib_dir/\$vboxvideo_src" "\$modules_dir/drivers/vboxvideo_drv\$driver_ext";;
    esac
    case "\$vboxmouse_src" in ?*)
        ln -s "\$lib_dir/\$vboxmouse_src" "\$modules_dir/input/vboxmouse_drv\$driver_ext";;
    esac
    succ_msg

    if test -n "\$dox11config"; then
        begin "Setting up the Window System to use the Guest Additions"
        # Certain Ubuntu/Debian versions use a special PCI-id file to identify
        # video drivers.  Some versions have the directory and don't use it.
        # Those versions can autoload vboxvideo though, so we don't need to
        # hack the configuration file for them.
        test "\$system" = "debian" -a -d /usr/share/xserver-xorg/pci &&
        {
            rm -f "/usr/share/xserver-xorg/pci/vboxvideo.ids"
            ln -s "\$share_dir/vboxvideo.ids" /usr/share/xserver-xorg/pci 2>/dev/null
            test -n "\$automouse" && setupxorgconf=""
        }

        # Do the XF86Config/xorg.conf hack for those versions that require it
        configured=""
        generated=""
        if test -n "\$setupxorgconf"; then
            for i in \$x11conf_files; do
                if test -r "\$i"; then
                    if grep -q "VirtualBox generated" "\$i"; then
                        generated="\$generated  \`printf "\$i\\n"\`"
                    else
                        "\$lib_dir/x11config.sh" \$newmouse \$automouse \$nopsaux "\$i"
                    fi
                    configured="true"
                fi
                # Timestamp, so that we can see if the config file is changed
                # by someone else later
                test -r "\$i.vbox" && touch "\$i.vbox"
            done
            # X.Org Server 1.5 and 1.6 can detect hardware they know, but they
            # need a configuration file for VBoxVideo.
            main_cfg="/etc/X11/xorg.conf"
            nobak="/etc/X11/xorg.vbox.nobak"
            if test -z "\$configured"; then
                touch "\$main_cfg"
                "\$lib_dir/x11config.sh" \$newmouse \$automouse \$nopsaux --noBak "\$main_cfg"
                touch "\$nobak"
            fi
        fi
        succ_msg
        test -n "\$generated" &&
            cat << EOF
The following X.Org/XFree86 configuration files were originally generated by
the VirtualBox Guest Additions and were not modified:

\$generated

EOF
        cat << EOF
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.

EOF
    fi

    begin "Installing graphics libraries and desktop services components"
    case "\$redhat_release" in
        # Install selinux policy for Fedora 7 and 8 to allow the X server to
        # open device files
        Fedora\\ release\\ 7* | Fedora\\ release\\ 8* )
            semodule -i "\$share_dir/vbox_x11.pp" > /dev/null 2>&1
            ;;
        # Similar for the accelerated graphics check on Fedora 15
        Fedora\\ release\\ 15* )
            semodule -i "\$share_dir/vbox_accel.pp" > /dev/null 2>&1
            ;;
    esac

    # Install selinux policy for Fedora 8 to allow the X server to
    # open our drivers
    case "\$redhat_release" in
        Fedora\\ release\\ 8* )
            chcon -u system_u -t lib_t "\$lib_dir"/*.so
            ;;
    esac

    # Our logging code generates some glue code on 32-bit systems.  At least F10
    # needs a rule to allow this.  Send all output to /dev/null in case this is
    # completely irrelevant on the target system.
    chcon -t unconfined_execmem_exec_t '/usr/bin/VBoxClient' > /dev/null 2>&1
    semanage fcontext -a -t unconfined_execmem_exec_t '/usr/bin/VBoxClient' > /dev/null 2>&1
    # Install the guest OpenGL drivers.  For now we don't support
    # multi-architecture installations
    for dir in /usr/lib/dri /usr/lib32/dri /usr/lib64/dri \\
        /usr/lib/xorg/modules/dri /usr/lib32/xorg/modules/dri \\
        /usr/lib64/xorg/modules/dri /usr/lib/i386-linux-gnu/dri \\
        /usr/lib/x86_64-linux-gnu/dri; do
        if [ -d \$dir ]; then
            rm -f "\$dir/vboxvideo_dri.so"
            ln -s "\$LIB/VBoxOGL.so" "\$dir/vboxvideo_dri.so"
        fi
    done

    # And set up VBoxClient to start when the X session does
    install_x11_startup_app "\$lib_dir/98vboxadd-xclient" "\$share_dir/vboxclient.desktop" VBoxClient VBoxClient-all ||
        fail "See the log file \$LOG for more information."
    succ_msg
}

# cleanup_script
cleanup()
{
    # Restore xorg.conf files as far as possible
    ## List of generated files which have been changed since we generated them
    newer=""
    ## Are we dealing with a legacy information which didn't support
    # uninstallation?
    legacy=""
    ## Do any of the restored configuration files still reference our drivers?
    failed=""
    test -r "\$CONFIG_DIR/\$CONFIG" || legacy="true"
    main_cfg="/etc/X11/xorg.conf"
    nobak="/etc/X11/xorg.vbox.nobak"
    if test -r "\$nobak"; then
        test -r "\$main_cfg" &&
            if test -n "\$legacy" -o ! "\$nobak" -ot "\$main_cfg"; then
                rm -f "\$nobak" "\$main_cfg"
            else
                newer="\$newer\`printf "  \$main_cfg (no original)\\n"\`"
            fi
    else
        for i in \$x11conf_files; do
            if test -r "\$i.vbox"; then
                if test ! "\$i" -nt "\$i.vbox" -o -n "\$legacy"; then
                    mv -f "\$i.vbox" "\$i"
                    grep -q -E 'vboxvideo|vboxmouse' "\$i" &&
                        failed="\$failed\`printf "  \$i\\n"\`"
                else
                    newer="\$newer\`printf "  \$i (\$i.vbox)\\n"\`"
                fi
            fi
        done
    fi
    test -n "\$newer" && cat << EOF

The following X.Org/XFree86 configuration files were not restored, as they may
have been changed since they were generated by the VirtualBox Guest Additions.
You may wish to restore these manually.  The file name in brackets is the
original version.

\$newer

EOF
    test -n "\$failed" && cat << EOF

The following X.Org/XFree86 configuration files were restored, but still
contain references to the Guest Additions drivers.  You may wish to check and
possibly correct the restored configuration files to be sure that the server
will continue to work after it is restarted.

\$failed

EOF

    # Remove X.Org drivers
    find "\$x11_modules_dir" /usr/lib64/xorg/modules /usr/lib/xorg/modules \\
        /usr/X11R6/lib64/modules /usr/X11R6/lib/modules \\
        /usr/X11R6/lib/X11/modules \\
        '(' -name 'vboxvideo_drv*' -o -name 'vboxmouse_drv*' ')' \\
        -exec rm -f '{}' ';' 2>/dev/null

    # Remove the link to vboxvideo_dri.so
    rm -f /usr/lib/dri/vboxvideo_dri.so /usr/lib64/dri/vboxvideo_dri.so 2>/dev/null

    # Remove VBoxClient autostart files
    rm /etc/X11/Xsession.d/98vboxadd-xclient 2>/dev/null
    rm /etc/X11/xinit.d/98vboxadd-xclient 2>/dev/null
    rm /etc/X11/xinit/xinitrc.d/98vboxadd-xclient.sh 2>/dev/null
    rm /etc/xdg/autostart/vboxclient.desktop 2>/dev/null
    rm /usr/share/autostart/vboxclient.desktop 2>/dev/null

    # Remove other files
    rm /usr/share/xserver-xorg/pci/vboxvideo.ids 2>/dev/null
}

dmnstatus()
{
    /bin/true
}

case "\$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    restart
    ;;
setup)
    setup
    ;;
cleanup)
    cleanup
    ;;
status)
    dmnstatus
    ;;
*)
    echo "Usage: \$0 {start|stop|restart|status}"
    exit 1
esac

exit
EOFEOF
chmod 0755 "/etc/init.d/vboxadd-x11"
MD5SUM="$(md5sum "/etc/mailname" 2>/dev/null)"
mkdir -p "/etc"
cat >"/etc/mailname" <<EOF
wowf.localdomain
EOF
[ "$MD5SUM" != "$(md5sum "/etc/mailname")" ] && SERVICE_sysvinit_postfix=1
mkdir -p "/etc/mercurial/hgrc.d"
cat >"/etc/mercurial/hgrc.d/hgext.rc" <<EOF
# mercurial configuration file for bundled hg extensions
# See hgrc(5) for more information

# Extensions included in Mercurial listed in alphabetical order
[extensions]

# changeset access control
# hgext.acl =

# allow user-defined command aliases
# hgext.alias =

# provides the 'bookmarks' command
# hgext.bookmarks =

# bugzilla integration
# requires python-mysqldb
# hgext.bugzilla =

# show the children of the given or working dir revision
# provides the 'children' command
# hgext.children =

# graph count of revisions grouped by template
# provides the 'churn' command
# hgext.churn =

# add color output to status, qseries, and diff-related commands
# hgext.color =

# converts a foreign SCM to a Mercurial one
# provides the 'convert' and 'debugsvnlog' commands
# requires:
# - bzr to convert from Bazaar
# - cvs to convert from CVS
# - python-celementtree or python-elementtree to convert from Darcs
# - git-core to convert from Git
# - tla to convert from GNU Arch
# - monotone to convert from Monotone
# - python-subversion to convert from Subversion
# hgext.convert =

# external diff program support
# hgext.extdiff =

# pull and merge remote changes
# provides the 'fetch' command
# hgext.fetch =

# GnuPG signing
# provides the 'sign', 'sigcheck' and 'sigs' commands
# requires gnupg
# hgext.gpg =

# show revision graphs in terminal windows
# provides the 'glog' command
# hgext.graphlog =

# CIA notification hook
# hgext.hgcia =

# allows browsing the history of a repository in a graphical way
# provides the 'view' command
# requires wish
# hgext.hgk =

# syntax highlighting in hgweb
# requires python-pygments
# hgext.highlight =

# lets you split a merge into pieces
# provides the 'imerge' command
# hgext.imerge =

# inotify-based status acceleration for Linux systems
# provides the 'inserve' command
# hgext.inotify =

# allows you to change changelog and summary text
# hgext.interhg =

# CVS/RCS-like keyword expansion
# hgext.keyword =

# quilt-like patch queues
# provides the 'q*' commands
# hgext.mq =

# email notifications
# hgext.notify =

# display output using a pager
# hgext.pager =

# make it easy to refer to the parent of a revision
# hgext.parentrevspec =

# send changes as series of email patches
# provides the 'email' command
# hgext.patchbomb =

# removes files not known to mercurial
# provides the 'purge' command
# hgext.purge =

# moves sets of revisions to a different ancestor
# provides the 'rebase' command
# hgext.rebase =

# interactive change selection during commit
# provides the 'record' command
# hgext.record =

# patch transplanting tool
# provides the 'transplant' command
# hgext.transplant =

# non-Unicode MBCS filename support
# hgext.win32mbcs =

# Unix/Mac/DOS line ending conversion utilities
# hgext.win32text =

# mDNS/DNS-SD (Zeroconf) support for 'hg serve'
# hgext.zeroconf =
EOF
mkdir -p "/etc"
cat >"/etc/motd.tail" <<EOF
Welcome to your Vagrant-built virtual machine.
EOF
MD5SUM="$(md5sum "/etc/postfix/main.cf" 2>/dev/null)"
mkdir -p "/etc/postfix"
cat >"/etc/postfix/main.cf" <<EOF
# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = \$myhostname ESMTP \$mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:\${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:\${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = wowf.localdomain
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = wowf.localdomain, localhost.localdomain, , localhost
relayhost = 
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
EOF
[ "$MD5SUM" != "$(md5sum "/etc/postfix/main.cf")" ] && SERVICE_sysvinit_postfix=1
mkdir -p "/etc/profile.d"
cat >"/etc/profile.d/vagrant_ruby.sh" <<EOF
PATH=\$PATH:/opt/vagrant_ruby/bin
EOF
mkdir -p "/etc/resolvconf/resolv.conf.d"
cat >"/etc/resolvconf/resolv.conf.d/original" <<EOF
nameserver 10.0.1.1
EOF
mkdir -p "/etc"
cat >"/etc/shells" <<EOF
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
EOF
mkdir -p "/etc/ssh"
cat >"/etc/ssh/sshd_config" <<EOF
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile	%h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
UseDNS no
EOF
mkdir -p "/etc/systemd/system/multi-user.target.wants"
ln -s "/lib/systemd/system/rsyslog.service" "/etc/systemd/system/multi-user.target.wants/rsyslog.service"
MD5SUM="$(md5sum "/etc/udev/rules.d/60-vboxadd.rules" 2>/dev/null)"
mkdir -p "/etc/udev/rules.d"
cat >"/etc/udev/rules.d/60-vboxadd.rules" <<EOF
KERNEL=="vboxguest", NAME="vboxguest", OWNER="vboxadd", MODE="0660"
KERNEL=="vboxuser", NAME="vboxuser", OWNER="vboxadd", MODE="0666"
EOF
[ "$MD5SUM" != "$(md5sum "/etc/udev/rules.d/60-vboxadd.rules")" ] && SERVICE_sysvinit_vboxadd=1
export APT_LISTBUGS_FRONTEND="none"
export APT_LISTCHANGES_FRONTEND="none"
export DEBIAN_FRONTEND="noninteractive"
apt-get -q update
[ "$(dpkg-query -f'${Version}\n' -W binutils)" = "2.22-6ubuntu1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install binutils=2.22-6ubuntu1
[ "$(dpkg-query -f'${Version}\n' -W cpp)" = "4:4.6.3-1ubuntu5" ] || apt-get -y -q -o DPkg::Options::=--force-confold install cpp=4:4.6.3-1ubuntu5
[ "$(dpkg-query -f'${Version}\n' -W cpp-4.6)" = "4.6.3-1ubuntu5" ] || apt-get -y -q -o DPkg::Options::=--force-confold install cpp-4.6=4.6.3-1ubuntu5
[ "$(dpkg-query -f'${Version}\n' -W gcc)" = "4:4.6.3-1ubuntu5" ] || apt-get -y -q -o DPkg::Options::=--force-confold install gcc=4:4.6.3-1ubuntu5
[ "$(dpkg-query -f'${Version}\n' -W gcc-4.6)" = "4.6.3-1ubuntu5" ] || apt-get -y -q -o DPkg::Options::=--force-confold install gcc-4.6=4.6.3-1ubuntu5
[ "$(dpkg-query -f'${Version}\n' -W git)" = "1:1.7.9.5-1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install git=1:1.7.9.5-1
[ "$(dpkg-query -f'${Version}\n' -W git-man)" = "1:1.7.9.5-1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install git-man=1:1.7.9.5-1
[ "$(dpkg-query -f'${Version}\n' -W libc-dev-bin)" = "2.15-0ubuntu10" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libc-dev-bin=2.15-0ubuntu10
[ "$(dpkg-query -f'${Version}\n' -W libc6-dev)" = "2.15-0ubuntu10" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libc6-dev=2.15-0ubuntu10
[ "$(dpkg-query -f'${Version}\n' -W libdevmapper-event1.02.1)" = "2:1.02.48-4ubuntu7" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libdevmapper-event1.02.1=2:1.02.48-4ubuntu7
[ "$(dpkg-query -f'${Version}\n' -W liberror-perl)" = "0.17-1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install liberror-perl=0.17-1
[ "$(dpkg-query -f'${Version}\n' -W libexpat1-dev)" = "2.0.1-7.2ubuntu1.1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libexpat1-dev=2.0.1-7.2ubuntu1.1
[ "$(dpkg-query -f'${Version}\n' -W libgmp10)" = "2:5.0.2+dfsg-2ubuntu1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libgmp10=2:5.0.2+dfsg-2ubuntu1
[ "$(dpkg-query -f'${Version}\n' -W libgomp1)" = "4.6.3-1ubuntu5" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libgomp1=4.6.3-1ubuntu5
[ "$(dpkg-query -f'${Version}\n' -W libjpeg-dev)" = "8c-2ubuntu7" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libjpeg-dev=8c-2ubuntu7
[ "$(dpkg-query -f'${Version}\n' -W libjpeg-turbo8)" = "1.1.90+svn733-0ubuntu4.1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libjpeg-turbo8=1.1.90+svn733-0ubuntu4.1
[ "$(dpkg-query -f'${Version}\n' -W libjpeg-turbo8-dev)" = "1.1.90+svn733-0ubuntu4.1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libjpeg-turbo8-dev=1.1.90+svn733-0ubuntu4.1
[ "$(dpkg-query -f'${Version}\n' -W libjpeg8)" = "8c-2ubuntu7" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libjpeg8=8c-2ubuntu7
[ "$(dpkg-query -f'${Version}\n' -W libjpeg8-dev)" = "8c-2ubuntu7" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libjpeg8-dev=8c-2ubuntu7
[ "$(dpkg-query -f'${Version}\n' -W libmpc2)" = "0.9-4" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libmpc2=0.9-4
[ "$(dpkg-query -f'${Version}\n' -W libmpfr4)" = "3.1.0-3ubuntu2" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libmpfr4=3.1.0-3ubuntu2
[ "$(dpkg-query -f'${Version}\n' -W libopts25)" = "1:5.12-0.1ubuntu1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libopts25=1:5.12-0.1ubuntu1
[ "$(dpkg-query -f'${Version}\n' -W libpython2.7)" = "2.7.3-0ubuntu3.1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libpython2.7=2.7.3-0ubuntu3.1
[ "$(dpkg-query -f'${Version}\n' -W libquadmath0)" = "4.6.3-1ubuntu5" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libquadmath0=4.6.3-1ubuntu5
[ "$(dpkg-query -f'${Version}\n' -W libreadline-dev)" = "6.2-8" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libreadline-dev=6.2-8
[ "$(dpkg-query -f'${Version}\n' -W libreadline6-dev)" = "6.2-8" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libreadline6-dev=6.2-8
[ "$(dpkg-query -f'${Version}\n' -W libssl-dev)" = "1.0.1-4ubuntu5.5" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libssl-dev=1.0.1-4ubuntu5.5
[ "$(dpkg-query -f'${Version}\n' -W libssl-doc)" = "1.0.1-4ubuntu5.5" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libssl-doc=1.0.1-4ubuntu5.5
[ "$(dpkg-query -f'${Version}\n' -W libtinfo-dev)" = "5.9-4" ] || apt-get -y -q -o DPkg::Options::=--force-confold install libtinfo-dev=5.9-4
[ "$(dpkg-query -f'${Version}\n' -W linux-libc-dev)" = "3.2.0-30.48" ] || apt-get -y -q -o DPkg::Options::=--force-confold install linux-libc-dev=3.2.0-30.48
[ "$(dpkg-query -f'${Version}\n' -W lvm2)" = "2.02.66-4ubuntu7" ] || apt-get -y -q -o DPkg::Options::=--force-confold install lvm2=2.02.66-4ubuntu7
[ "$(dpkg-query -f'${Version}\n' -W manpages-dev)" = "3.35-0.1ubuntu1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install manpages-dev=3.35-0.1ubuntu1
[ "$(dpkg-query -f'${Version}\n' -W mercurial)" = "2.0.2-1ubuntu1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install mercurial=2.0.2-1ubuntu1
[ "$(dpkg-query -f'${Version}\n' -W mercurial-common)" = "2.0.2-1ubuntu1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install mercurial-common=2.0.2-1ubuntu1
[ "$(dpkg-query -f'${Version}\n' -W ntp)" = "1:4.2.6.p3+dfsg-1ubuntu3.1" ] || { apt-get -y -q -o DPkg::Options::=--force-confold install ntp=1:4.2.6.p3+dfsg-1ubuntu3.1; SERVICE_sysvinit_ntp=1; }
[ "$(dpkg-query -f'${Version}\n' -W openssh-server)" = "1:5.9p1-5ubuntu1" ] || { apt-get -y -q -o DPkg::Options::=--force-confold install openssh-server=1:5.9p1-5ubuntu1; SERVICE_sysvinit_ssh=1; }
[ "$(dpkg-query -f'${Version}\n' -W postfix)" = "2.9.3-2~12.04.4" ] || { apt-get -y -q -o DPkg::Options::=--force-confold install postfix=2.9.3-2~12.04.4; SERVICE_sysvinit_postfix=1; }
[ "$(dpkg-query -f'${Version}\n' -W python-dev)" = "2.7.3-0ubuntu2" ] || apt-get -y -q -o DPkg::Options::=--force-confold install python-dev=2.7.3-0ubuntu2
[ "$(dpkg-query -f'${Version}\n' -W python-pip)" = "1.0-1build1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install python-pip=1.0-1build1
[ "$(dpkg-query -f'${Version}\n' -W python-pkg-resources)" = "0.6.24-1ubuntu1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install python-pkg-resources=0.6.24-1ubuntu1
[ "$(dpkg-query -f'${Version}\n' -W python-setuptools)" = "0.6.24-1ubuntu1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install python-setuptools=0.6.24-1ubuntu1
[ "$(dpkg-query -f'${Version}\n' -W python2.7-dev)" = "2.7.3-0ubuntu3.1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install python2.7-dev=2.7.3-0ubuntu3.1
[ "$(dpkg-query -f'${Version}\n' -W ssh-import-id)" = "2.10-0ubuntu1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install ssh-import-id=2.10-0ubuntu1
[ "$(dpkg-query -f'${Version}\n' -W ssl-cert)" = "1.0.28ubuntu0.1" ] || apt-get -y -q -o DPkg::Options::=--force-confold install ssl-cert=1.0.28ubuntu0.1
[ "$(dpkg-query -f'${Version}\n' -W watershed)" = "6" ] || apt-get -y -q -o DPkg::Options::=--force-confold install watershed=6
[ "$(dpkg-query -f'${Version}\n' -W zlib1g-dev)" = "1:1.2.3.4.dfsg-3ubuntu4" ] || apt-get -y -q -o DPkg::Options::=--force-confold install zlib1g-dev=1:1.2.3.4.dfsg-3ubuntu4
pip install Beaker==1.6.4
pip install Chameleon==2.10
pip install Jinja2==2.6
pip install Mako==0.7.2
pip install MarkupSafe==0.15
pip install PasteDeploy==1.5.0
pip install Pillow==1.7.8
pip install Pygments==1.5
pip install SQLAlchemy==0.7.9
pip install WTForms==1.0.2
pip install WebHelpers==1.3
pip install WebOb==1.2.3
pip install WebTest==1.4.0
pip install Whoosh==2.4.1
pip install blueprint==3.4.0
pip install distribute==0.6.24
pip install py_bcrypt==0.2
pip install py_pretty==1
pip install pyramid==1.4a2
pip install pyramid_beaker==0.7
pip install pyramid_debugtoolbar==1.0.3
pip install pyramid_exclog==0.6
pip install pyramid_jinja2==1.4.2
pip install pyramid_mailer==0.9
pip install pyramid_rewrite==0.2
pip install pyramid_tm==0.5
pip install python_dateutil==2.1
pip install pytz==2012h
pip install repoze.lru==0.6
pip install repoze.sendmail==3.2
pip install six==1.2.0
pip install times==0.6
pip install timezones==1.5
pip install transaction==1.3.0
pip install translationstring==1.1
pip install venusian==1.0a7
pip install waitress==0.8.1
pip install zope.deprecation==4.0.0
pip install zope.interface==4.0.1
pip install zope.sqlalchemy==0.7.1
[ -n "$SERVICE_sysvinit_ntp" ] && /etc/init.d/ntp restart
[ -n "$SERVICE_sysvinit_postfix" ] && /etc/init.d/postfix restart
[ -n "$SERVICE_sysvinit_ssh" ] && /etc/init.d/ssh restart
[ -n "$SERVICE_sysvinit_vboxadd" ] && /etc/init.d/vboxadd restart
[ -n "$SERVICE_sysvinit_vboxaddservice" ] && /etc/init.d/vboxadd-service restart
[ -n "$SERVICE_sysvinit_vboxaddx11" ] && /etc/init.d/vboxadd-x11 restart
