#!/bin/bash
#
# Perform necessary Manage setup steps after package is installed.
#

ADDON="chef-manage"
PROGNAME=$(basename $0)

function error_exit
{
	echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
	exit 1
}

ln -sf /opt/$ADDON/bin/$ADDON-ctl /usr/bin || error_exit "Cannot link $ADDON-ctl in /usr/bin"

# The versions of omnibus that generated packages used in $ADDON ensure all
# files and directories in /opt/$ADDON are owned by root. This does not need to
# be done on new installs (since 1.6.2) but upgrades from old Ubuntu
# installs need to ensure this directory has the correct ownership.
chown -Rh 0:0 /opt/$ADDON

echo
if [ -e /etc/$ADDON/$ADDON-running.json ]; then
  echo -e "\033[1mYou have upgraded the Chef Management Console!\033[0m"
else
  echo -e "\033[1mThank you for installing the Chef Management Console add-on!\033[0m"
fi

echo
echo "The next step in the process is to run:"
echo
echo -e "\033[1;32m$ADDON-ctl reconfigure\033[0m\n"

exit 0
