#!/bin/sh

cp -f /etc/X11/xorg.conf1 /etc/X11/xorg.conf
echo '' >> /etc/X11/xorg.conf

ddcprobe >/tmp/ddcprobe.txt
#weird (ddcprobe is very weird), on some hardware, edid monitor probe fails
#every alternate run of ddcprobe...
case "`cat /tmp/ddcprobe.txt`" in *edidfail*)
 sleep 1
 ddcprobe >/tmp/ddcprobe.txt
 ;;
esac

PROFILECHIP="`grep -m1 '^oem: ' /tmp/ddcprobe.txt | cut -f 2-4 -d ' ' | tr ' ' '_' | sed -e 's/[^0-9a-zA-Z]/_/g'`"
PROFILEMONITOR="`grep '^monitorid: ' /tmp/ddcprobe.txt | head -n 1 | cut -f 2 -d ':' | tr -d ' ' | sed -e 's/[^0-9a-zA-Z]/_/g'`"
[ "$PROFILEMONITOR" = "" ] && PROFILEMONITOR="`grep '^monitorname: ' /tmp/ddcprobe.txt | head -n 1 | cut -f 2 -d ':' | tr -d ' ' | sed -e 's/[^0-9a-zA-Z]/_/g'`"
[ "$PROFILEMONITOR" = "" ] && PROFILEMONITOR="`grep '^monitorrange: ' /tmp/ddcprobe.txt | head -n 1 | cut -f 2 -d ':' | tr -d ' ' | sed -e 's/[^0-9a-zA-Z]/_/g'`"
[ "$PROFILEMONITOR" = "" ] && PROFILEMONITOR="`grep '^manufacture: ' /tmp/ddcprobe.txt | tail -n 1 | cut -f 2 -d ':' | tr -d ' ' | sed -e 's/[^0-9a-zA-Z]/_/g'`"

echo "#PuppyHardwareProfile=${PROFILECHIP}${PROFILEMONITOR}" >> /etc/X11/xorg.conf
#create a copy of xorg.conf with the profile in the filename...
cp -af /etc/X11/xorg.conf /etc/X11/xorg.conf.${PROFILECHIP}${PROFILEMONITOR}

mv /usr/sbin/xorg-setup /usr/sbin/xorgwizard
mv /usr/lib/xorg/modules/drivers/displaylink_drv.so /usr/lib/xorg/modules/drivers/displaylink_drv.so.not