#!/bin/bash

echo
echo "A check is being run to look for files that indicate mpd_oled has"
echo "installed more than once and to different system locations"
echo

found_usr="no";
if test -f "/usr/bin/mpd_oled"; then
  echo "note: mpd_oled found in /usr/bin"
  found_usr="yes"
fi

found="no";
if test -f "/usr/local/bin/mpd_oled"; then
  echo "note: mpd_oled found in /usr/local/bin"
  found="yes"
fi

sysd_file="/etc/systemd/system/mpd_oled.service"
if test -f "$sysd_file" && grep -q "/usr/local/" "$sysd_file"; then
  echo "note: mpd_oled service file includes /usr/local"
  found="yes"
fi

if test "$found_usr" == "yes"; then

  if test "$found" == "yes"; then
    echo
    echo "WARNING - ACTION MAY BE REQUIRED":
    echo "  Files were found that indicate mpd_oled has been installed"
    echo "  to both /usr/local and /usr. If you have just installed an"
    echo "  mpd_oled binary package you shoud run the following command,"
    echo "  which will remove the mpd_oled* files from /usr/local/bin,"
    echo "  and set the mpd_oled service file (if it exists) to use the"
    echo "  package version of mpd_oled:"
    echo
    echo "     sudo mpd_oled_usrlocal_uninstall"
  else
    echo "No conflicts found: mpd_oled is installed only in /usr"
  fi

else

  if test "$found" == "yes"; then
    echo
    echo "No conflicts found: mpd_oled is installed only in /usr/local"
  else
    echo "No installation found: mpd_oled is not installed in /usr or"
    echo "/usr/local"
  fi

fi

echo

