#!/bin/sh

if [ "$1" = -v ]; then
    opt_v="$1"
    shift
fi

if [ "$1" = -h -o "$1" = --help ]; then
    opt_h="$1"
    shift
fi

if [ $# != 1 ]; then
    echo "usage: monitor-probe [-v] <X driver>"
    echo "(X driver is one of: i810, nv, radeon...)"
    exit 1
fi

X_driver="$1"

if [ $EUID != 0 ]; then
    echo "you must be root to run this program"
    exit 1
fi

[ -n "$opt_v" ] && echo "probing EDID" 1>&2
monitor-edid --try-in-console $opt_v && exit 0

[ -n "$opt_v" ] && echo "probing DMI" 1>&2
lspcidrake | sed -n 's/^\(Resolution\|Diagonal_size\):\([^:]*\):.*/\1: \2/p' | grep . && exit 0

[ -n "$opt_v" ] && echo "probing using X" 1>&2
monitor-probe-using-X $X_driver && exit 0
