#!/bin/sh

user_vc_blank_path=/sbin/user_vc_blank
default_handler=radeon_vc_blank.sh

version=0.1

scripts=$(cd scripts; echo *.sh)

echo
echo "user_vc_blank-$version"
echo
echo "This module calls a userspace script for blanking and unblanking the console."
echo
echo "Provided scripts:"
for script in $scripts; do
  echo
  echo -n "$script: "
  grep '^#[[:blank:]]*@DESCRIPTION@[[:blank:]]*' scripts/$script | sed 's/^#[[:blank:]]*@DESCRIPTION@[[:blank:]]*//'
done
echo
echo "What script do you want to install as the default handler?"
read -e -p "($scripts) [$default_handler]: " answer
while true; do
  test ! "$answer" && answer=$default_handler
  test -f scripts/$answer && break
  if test -f scripts/$answer.sh; then
    answer=$answer.sh
    break
  fi
  echo "scripts/$answer doesn't exist. Choose from the following list."
  read -e -p "($scripts) [$default_handler]: "
done
user_vc_blank_handler=$answer
echo "Using scripts/$answer as the default handler."
echo

echo "Do you want to change the default path to the handler script"
read -e -p "($user_vc_blank_path) [no]? " answer
if test "$answer" = y -o "$answer" = yes -o "$answer" = Y -o "$answer" = YES; then
  read -e -p "Enter the new path: " answer
  user_vc_blank_path=$answer
fi
echo

echo "configure: creating Makefile"
user_vc_blank_handler=$(echo $user_vc_blank_handler | sed 's/\//\\\//g')
user_vc_blank_path=$(echo $user_vc_blank_path | sed 's/\//\\\//g')
sed -e "s/@USER_VC_BLANK_HANDLER@/$user_vc_blank_handler/g" \
    -e "s/@USER_VC_BLANK_PATH@/$user_vc_blank_path/g" Makefile.in >Makefile
