#!/bin/sh
#
# Perform necessary removal steps
# after package is uninstalled.
#

INSTALLER_DIR=/opt/cinc-workstation

is_darwin()
{
  uname -a | grep "^Darwin" 2>&1 >/dev/null
}

# Remove only links that point into this package, including dangling ones from
# older versions; links other packages own stay.
cleanup_symlinks() {
  find "$PREFIX/bin" -maxdepth 1 -type l -lname "$INSTALLER_DIR/*" -exec rm -f {} +
}

if is_darwin; then
    PREFIX="/usr/local"
    mkdir -p "$PREFIX/bin"
else
    PREFIX="/usr"
fi

# rpm passes the number of installs left, so 1+ is an upgrade whose new links
# are already in place (CHEF-3022); dpkg passes a word such as remove or purge.
case "$1" in
  [1-9]*) ;;
  *) cleanup_symlinks ;;
esac

exit 0
