#!/bin/sh

# if rc.vboxadd is executable, run it on startup
run=`grep "sh /etc/rc.d/rc.vboxadd" etc/rc.d/rc.local`
if [[ "${run}" == "" ]]; then
cat << EOF >> etc/rc.d/rc.local

#VirtualBox bridge
# To enable VirtualBox network, chmod rc.vboxadd to 755
if [ -x /etc/rc.d/rc.vboxadd ]; then
        sh /etc/rc.d/rc.vboxadd start
fi
EOF
fi

# if rc.vboxadd-service is executable, run it on startup
run=`grep "sh /etc/rc.d/rc.vboxadd-service" etc/rc.d/rc.local`
if [[ "${run}" == "" ]]; then
cat << EOF >> etc/rc.d/rc.local

#VirtualBox bridge
# To enable VirtualBox network, chmod rc.vboxadd-service to 755
if [ -x /etc/rc.d/rc.vboxadd-service ]; then
        sh /etc/rc.d/rc.vboxadd-service start
fi
EOF
fi

# Chroot to insert the group in the possible --root target
chroot . << EOR 2>/dev/null
/usr/sbin/useradd -u 215 -g users -d /usr/lib/virtualbox vboxadd 2> /dev/null
EOR

echo "********************************************************************************"
echo "* Remember to run '/etc/rc.d/rc.vboxadd setup' after install and start the     *"
echo "* '/etc/rc.d/rc.vboxadd-service' daemon                                        *"
echo "********************************************************************************"
( cd usr/lib/dri ; rm -rf vboxvideo_dri.so )
( cd usr/lib/dri ; ln -sf /usr/lib/VBoxOGL.so vboxvideo_dri.so )
