#!/bin/bash

sourcedir="./configfiles"

while getopts :s: OPT; do
  case $OPT in
    s)
      sourcedir="$OPTARG"
      ;;
    *)
      echo "usage: ${0##*/} [-s <source_dir>] [--]"
      exit 2
  esac
done
shift $[ OPTIND - 1 ]

rpm="openoffice"
if ! rpm -q $rpm >/dev/null 2>&1; then
  rpm="openoffice.org"
  if ! rpm -q $rpm >/dev/null 2>&1; then
    echo "Could not find an installation of openoffice" 1>&2
    exit 1
  fi
fi
printer_config_dest=`rpm -ql $rpm | grep -e 'psprint\.conf'`
driver_dest=`dirname "${printer_config_dest}"`/driver

install -m 644 --backup=simple -S ".old" ${sourcedir}/psprint.conf \
`dirname "${printer_config_dest}"`/ || exit 2

install -m 644 ${sourcedir}/*.PS "${driver_dest}"/ || exit 2

exit 0
