#!/bin/bash

LIST=slash-bin.txt
if [ -n "$1" -a -e "$1" ]; then
  LIST="$1"
fi

echo "Using file: $LIST" >&2

IFS='
'

OP=""
for pkg in $(cat $LIST | cut -d':' -f1 | sort -u); do
  regexp="^/usr($(cat $LIST | grep "^$pkg:" | cut -d':' -f2 | xargs | sed 's/ /|/g'))\$"
  file=$(echo $line | cut -d':' -f2)

  echo -n "Checking for conflicts for package $pkg..." >&2
  conflicts="$(urpmf "$regexp")"
  if [ -n "$conflicts" ]; then
    otherconflicts="$(echo "$conflicts" | grep -v "^$pkg:")"
    if [ -z "$otherconflicts" ]; then
      echo " self" >&2
      OP="${OP}$pkg:self\n"
    else
      otherpkgs=$(echo "$otherconflicts" | cut -d':' -f1 | sort -u | xargs)
      echo " $otherpkgs" >&2
      OP="${OP}$pkg:$otherpkgs\n"
    fi
  else
    echo " none" >&2
  fi
done

echo -e "$OP"