#!/bin/sh

# Install the appropriate proprietary graphics driver.
#
# Take advantage of language-installer's 'Please wait'
# dialog

# Clobber xorg.conf so we start with a clean slate.
# Allows X to load an appropriate open-source driver
# if jockey doesn't find a proprietary driver.
rm -f /etc/X11/xorg.conf

# Jockey is hard-coded to read from /etc/apt/;
# it does not seem to be interested in the values
# in APT_OPTIONS that we inherit from the caller.
# So, set up our own dummy sources.list for now
SOURCES=/etc/apt/sources.list.d/jockey.list
cat > $SOURCES << EOF
deb file:/archive /
EOF
apt-get update > /dev/null 2>&1

# Restart to pick up new apt cache
pkill jockey-backend
/usr/share/jockey/jockey-backend &

# Just in case jockey-backend is pokey
sleep 2

# Install nvidia proprietary driver if necessary.
# We don't want the ATI driver, which could be installed
# if the system has network access.
# Assumes only 1 card is visible to the system.
DETECT="$(jockey-text -l | cut -f 1 -d ' ')"
COUNT=$(echo "$DETECT" | grep -c nvidia)
if [ $COUNT -ne 0 ]; then
    jockey-text -e $DETECT
fi

# Cleanup
rm "${SOURCES}"
apt-get update > /dev/null 2>&1
