#!/bin/sh

set -e

if [ 0 -ne "`id -u`" ]; then
  echo "You have to be root to run this."
  exit 2
fi

case "$1" in
  -r)
    cfg=/etc/oo2c/$2.ooc
    if [ -f $cfg ]; then
      cat $cfg | grep -e --remove-line | sed 's;.*\(--remove-line *[^ ]*\).*;\1;' | \
        xargs /usr/lib/oo2c/ooconfig /etc/oo2c/oo2crc
    fi
    ;;
  -i)
    cfg=/etc/oo2c/$2.ooc
    if [ -f $cfg ]; then
      cat $cfg | \
        xargs /usr/lib/oo2c/ooconfig /etc/oo2c/oo2crc
    fi
    ;;
  *)
    for cfg in /etc/oo2c/*.ooc; do if [ -f $cfg ]; then
      cat $cfg | \
        xargs /usr/lib/oo2c/ooconfig /etc/oo2c/oo2crc
    fi; done
    ;;
esac
