#!/bin/bash
# ------------------------------------------------------------------
# AUTHOR: [LucidLink Support]
# NAME: lucidUpgradeCheck.sh
# VERSION: 1.0.0
# DESCRIPTION: Checks for Lucid installation and version and
# compares it to the latest release version from the web
#
# THE SCRIPT IS PROVIDED “AS IS” AND “AS AVAILABLE” AND IS WITHOUT
# WARRANTY OF ANY KIND. PLEASE REVIEW ALL TERMS AND CONDITIONS.
# https://www.lucidlink.com/legal-documents
# ------------------------------------------------------------------

lucidPath="/Applications/Lucid.app"
isInstalled=0

if test -d "$lucidPath"; then
    echo "Lucid is installed. Proceeding."
    isInstalled=1
else
	echo "Lucid is not installed."
	isInstalled=0
	exit 1
fi

webRaw=$(curl -s https://www.lucidlink.com/download#osList | grep Build)
webRelease=$(echo $webRaw | sed 's/<.*//')
webVersion=$(echo $webRelease | cut -d ' ' -f 2 | cut -d ',' -f 1)
webBuild=$(echo $webRelease | cut -d ' ' -f 4)

installedVersion=$(mdls -name kMDItemVersion /Applications/Lucid.app | cut -d '"' -f 2)
latestVersion="${webVersion}.${webBuild}"

echo "Installed Version:" $installedVersion
echo "Latest Version:" $latestVersion

if [ "$installedVersion" = "$latestVersion" ]
then
	echo "Already on the latest version!"
else
	echo "You need to upgrade Lucid."
fi

exit 0