#!/bin/sh -efu

if [ "$#" != 1 -a "$#" != 2 ]; then
  echo "Usage $0 <driver> [<conf file>]" >&2
  exit 1
fi

xorg_conf="${2:-/etc/X11/xorg.conf}"
xorg_conf_new=$xorg_conf
[ -f "$xorg_conf" ] || {
  echo "xorg.conf is not exist, falling back to /usr/share/alterator-x11/xorg.conf"
  xorg_conf='/usr/share/alterator-x11/xorg.conf'
}

video_drv "$1" | xconf -D "Card0" "$xorg_conf" "$xorg_conf_new"

xconf -C "$(video_drv -s depth "$1")" "$xorg_conf_new" "$xorg_conf_new"
