#!/bin/sh

REGEXP='\(last update: 20..-..-..\)\|\(letzte &Auml;nderung: 20..-..-..\)'

if test $1 = "-n" -a  $# = 3; then
  DIR=$2
  NAME=$3
  SINK=$DIR$NAME
#  if diff -q -b -I "$REGEXP" $NAME $SINK &>/dev/null; then
  if diff -q -b -I "$REGEXP" $NAME $SINK; then
    echo unchanged: $SINK
  else
    echo installation recommended: $SINK
  fi
elif test $1 != "-n" -a  $# = 2; then
  DIR=$1
  NAME=$2
  SINK=$DIR$NAME
#  if diff -q -b -I "$REGEXP" $NAME $SINK &>/dev/null; then
  if diff -q -b -I "$REGEXP" $NAME $SINK; then
    echo unchanged: $SINK
  else
    if test ! -e $DIR; then
      mkdir $DIR
    fi
    if cp -fp $NAME $SINK; then
      chmod 0644 $SINK
      echo installed: $SINK
    else
      echo ERROR: cannot move $NAME to $SINK
    fi
  fi
elif test $1 = "-f" -a  $# = 3; then
  DIR=$2
  NAME=$3
  SINK=$DIR$NAME
  if test ! -e $DIR; then
    mkdir $DIR
  fi
  if cp -fp $NAME $SINK; then
    chmod 0644 $SINK
    echo forced installation: $SINK
  else
    echo ERROR: cannot move $NAME to $SINK
  fi
else
  echo ERROR: usage: $0 [-n] dir name
fi
