#! /bin/bash
# vim: set tabstop=4 shiftwidth=4 noexpandtab filetype=sh:

# show_changes - show a2cloud version differences
#
# To the extent possible under law, T. Joseph Carter and Ivan Drucker have
# waived all copyright and related or neighboring rights to the a2cloud
# scripts themselves.  Software used or installed by these scripts is subject
# to other licenses.  This work is published from the United States.

# Find the path of our source directory
a2cSource="$( dirname "${BASH_SOURCE[0]}" )/.."
pushd $a2cSource >/dev/null
a2cSource="$PWD"
popd >/dev/null
if [[ ! -f "$a2cSource/.a2cloud_source" ]]; then
	printf "\na2cloud: cannot find a2cloud source directory in $a2cSource.\n\n"
	exit 1
fi

newVersion=$(grep '^a2cloudVersion' "$a2cSource/install.sh" | cut -d '"' -f 2)

if [[ -f /usr/local/etc/A2CLOUD-version ]]; then
	read installedVersion </usr/local/etc/A2CLOUD-version
	if [[ $installedVersion != *.*.* ]]; then
		installedVersion="${installedVersion:0:1}.${installedVersion:1:1}.${installedVersion:2}"
	fi
fi
echo "a2cloud version available: $newVersion"
echo "a2cloud version installed: ${installedVersion:-None}"

# FIXME: Do something useful with a changelog perhaps?
