scripts/app/check.zoom.update

109 lines
4.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Zoom client
## from official website https://zoom.us/download
## It's based on .deb package installation to check the current version.
## It can also compare the current available version in APT repositories
## if "repo" is given as first argument.
## How-to use {{{
### 1. Create a cron job, eg:
#00 20 * * * root /opt/repos/ipr.scripts/app/check.zoom.update
### 2-1 Create a cron job to compare the version available in an APT repository:
#00 20 * * * root /opt/repos/ipr.scripts/app/check.zoom.update repo
### 2. Monitor the temp file: /tmp/.zoom.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
## Inspired by https://github.com/pazepaze/zoom-autoupdater/blob/master/autoupdate-zoom.sh
# }}}
# Expect maximum 1 argument {{{
if [ $# -gt 1 ]
then
cat << HELP
check.zoom.update --
Compare current version of an installed Zoom client and the last available.
EXAMPLE:
- Compare the current version installed from .deb file
check.zoom.update
- Compare the current version from apt's repository
check.zoom.update repo
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=0
if [ $# -eq 1 ] && [ "${1}" = "repo" ] ## If repository's version should be compared
then
zoom_current_version=$(apt-cache policy -- zoom | awk '/Candidate:/ {print $2}' | sed 's/.:\(.*\)-.*/\1/')
else
zoom_current_version=$(dpkg --list -- zoom | awk '/^ii *zoom/ {print $3}' | sed 's/.:\(.*\)-.*/\1/')
fi
zoom_new_version=$(curl --silent 'https://zoom.us/support/download' --header 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36' | grep "class=\"linux-ver-text\"" | sed -e 's/.*Version \(.*\)<.*/\1/')
zoom_new_version_major=$(echo "${zoom_new_version}" | sed -e 's/\([^\.]\+\.[^\.]\+\).*/\1/')
zoom_new_version_minor=$(echo "${zoom_new_version}" | sed -e 's/[^\(]\+(\(.*\)).*/\1/')
zoom_new_version_file="/tmp/.zoom.upgrade"
zoom_new_pkg_path="/tmp/zoom_${zoom_new_version_major}.${zoom_new_version_minor}_amd64.deb"
zoom_tmp_pkg_path="/tmp/.zoom_${zoom_new_version_major}.${zoom_new_version_minor}_amd64.deb"
# }}}
# Check if the current version is the last one {{{
if [ "${zoom_current_version}" != "${zoom_new_version_major}.${zoom_new_version_minor}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${zoom_current_version}) and new one (${zoom_new_version_major}.${zoom_new_version_minor}) seems to be different."
## If it doesn't already exists, download this new package
if [ ! -f "${zoom_new_pkg_path}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Download .deb file from zoom.us to ${zoom_new_pkg_path} ."
wget --quiet https://zoom.us/client/latest/zoom_amd64.deb --output-document="${zoom_new_pkg_path}"
fi
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
## Ensure to remove any temp file and useless .deb file
rm --force -- "${zoom_new_version_file}" "${zoom_new_pkg_path}" "${zoom_tmp_pkg_path}"
fi
# }}}
# Verify downloaded package {{{
# Check the version from dpkg info {{{
zoom_dpkg_version=$(dpkg --info -- "${zoom_new_pkg_path}" | awk '/ Version/ { print $2 }')
if [ "${zoom_dpkg_version}" = "${zoom_new_version_major}.${zoom_new_version_minor}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Check dpkg version — \
New version and .deb file informations are correct."
## Create a temp file to monitor
touch -- "${zoom_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Zoom client (current: ${zoom_current_version}): ${zoom_new_version_major}.${zoom_new_version_minor}." >> "${zoom_new_version_file}"
### Exit
exit 0
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Check dpkg version — \
New version and .deb file informations mismatch, don't need to go further."
### Ensure to remove the file to monitor
rm --force -- "${zoom_new_version_file}"
### Keep a record of the downloaded package because as a new release might come soon
mv --force -- "${zoom_new_pkg_path}" "${zoom_tmp_pkg_path}"
fi
# }}}
# }}}
exit 255