scripts/app/check.zoom.update

84 lines
3.3 KiB
Plaintext
Raw Normal View History

2021-06-09 16:33:01 +02:00
#!/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=1
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"
2021-06-09 16:50:43 +02:00
zoom_new_pkg_path="/tmp/zoom_${zoom_new_version_major}.${zoom_new_version_minor}_amd64.deb"
2021-06-09 16:33:01 +02:00
# }}}
# 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."
## 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}." >> "${zoom_new_version_file}"
2021-06-09 16:50:43 +02:00
## 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
2021-06-09 16:33:01 +02:00
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
2021-06-09 16:50:43 +02:00
## Ensure to remove any temp file and useless .deb file
rm --force -- "${zoom_new_version_file}" "${zoom_new_pkg_path}"
2021-06-09 16:33:01 +02:00
fi
# }}}
exit 0