#!/bin/bash

# Make sure there is no zoom .deb around
touch /tmp/zoom_amd64.deb
rm /tmp/zoom_amd64.deb

# Grab the current one
wget -O /tmp/zoom_amd64.deb https://zoom.us/client/latest/zoom_amd64.deb

ISINSTALLED=`dpkg -l | grep "ii  zoom" | wc -l`
KNOWN=`dpkg-query -W zoom | cut -f2 -d'	'`
CURRENT=`dpkg -f /tmp/zoom_amd64.deb | grep Version | cut -f2 -d' '`
echo -n "Known: $KNOWN ("
if [ "$ISINSTALLED" == "0" ]; then
    echo -n "not "
fi
echo "installed)"
echo "Current: $CURRENT"

if [[ "$KNOWN" == "$CURRENT" && "$ISINSTALLED" == "1" ]]; then
    echo "The current version is installed."
else
    echo "Need super user privileges to install.."
    sudo dpkg -i /tmp/zoom_amd64.deb
    echo -n "Zoom has been "
    if [ "$ISINSTALLED" == "0" ]; then
        echo "installed."
    else
        echo "upgraded."
    fi
fi