scripts/github/check.fusioninventory-agent.update

78 lines
2.8 KiB
Bash
Executable File
Raw Permalink 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.

#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for FusionInventory-Agent
## project on Github.
## It's based on .deb package installation to check the current version.
## It can also compare the current available version in a debian repository
## if "repo" is given as first argument.
## How-to use {{{
### 1. Needs releasetags script, in the same directory
### cf. https://git.101010.fr/gardouille-dotfiles/scripts/src/branch/master/github/releasetags
# wget https://git.101010.fr/gardouille-dotfiles/scripts/raw/branch/master/github/releasetags
### 2. Create a cron job, eg:
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_fusioninventory-agent_update
### 2-1 Create a cron job to compare the version available in a Debian repository:
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_fusioninventory-agent_update repo
### 3. Monitor the temp file: /tmp/.github.fusioninventory-agent.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect maximum 1 argument {{{
if [ $# -gt 1 ]
then
cat << HELP
check.fusioninventory-agent.update --
Compare current version of an installed FusionInventory-Agent and the last available.
EXAMPLE:
- Compare the current version installed from .deb file
check.fusioninventory-agent.update
- Compare the current version in Debian's repository
check.fusioninventory-agent.update repo
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
fi_repo_url="https://github.com/fusioninventory/fusioninventory-agent"
if [ $# -eq 1 ] && [ "${1}" = "repo" ] ## If repository's version should be compared
then
fi_current_version=$(apt-cache policy fusioninventory-agent | awk '/Candidate:/ {print $2}' | sed 's/.:\(.*\)-.*/\1/')
else
fi_current_version=$(dpkg -l fusioninventory-agent | awk '/^ii.*fusioninventory-agent/ {print $3}' | sed 's/.:\(.*\)-.*/\1/')
fi
fi_new_version=$("${script_wd}"/releasetags "${fi_repo_url}" | head -n1 | sed 's/v//g')
fi_new_version_file="/tmp/.github.fusioninventory-agent.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${fi_current_version}" != "${fi_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${fi_current_version}) and new one (${fi_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${fi_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for FusionInventory-Agent (current: ${fi_current_version}): ${fi_new_version}." >> "${fi_new_version_file}"
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
rm -f -- "${fi_new_version_file}"
fi
# }}}
exit 0