Get scripts from IPR's git

https://git.ipr.univ-rennes.fr/cellinfo/scripts/src/branch/master/github
This commit is contained in:
gardouille 2024-05-29 08:25:36 +02:00
parent 428c56362d
commit 7d2e20ed02
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
21 changed files with 2972 additions and 3 deletions

View File

@ -8,7 +8,7 @@
### cf. https://git.101010.fr/gardouille-dotfiles/scripts/github/releasetags
# wget https://git.101010.fr/gardouille-dotfiles/scripts/raw/branch/master/github/releasetags
### 2. Create a cron job with AdGuard Home binary's path as first argument, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check_adguard_update --bin /opt/adguard/AdGuardHome/AdGuardHome
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_adguard_update --bin /opt/adguard/AdGuardHome/AdGuardHome
### 3. Monitor the temp file: /tmp/.adguard.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.

354
github/check.alacritty.update.sh Executable file
View File

@ -0,0 +1,354 @@
#!/bin/sh
#
# Purpose {{{
# This script will try to get last version of alacritty .deb file
# https://github.com/gardouille/alacritty-debian
# 1. Get current version from APT repo (by default).
# 1.b Or use version from manually installed package (with --file option).
# 2. Get latest version from github repository.
# 3. Compare current and new versions.
# 4. Download the .deb file for this new version.
# 5. Create a temp file (to monitor) if an upgrade is available.
#
# 2023-03-04
# }}}
# 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.alacritty.update
## 2-1 Create a cron job to compare the version of manually installed package
#00 20 * * * root /opt/repos/gardouille.scripts/github/check.alacritty.update --file
## 3. Monitor the temp file: /tmp/.github.alacritty.upgrade
# }}}
# Flags {{{
## Exit on error
set -o errexit
## Exit on unset var
### Use "${VARNAME-}" to test a var that may not have been set
set -o nounset
## Pipeline command is treated as failed
### Not available in POSIX sh https://github.com/koalaman/shellcheck/wiki/SC3040
#set -o pipefail
## Help with debugging
### Call the script by prefixing it with "TRACE=1 ./script.sh"
if [ "${TRACE-0}" -eq 1 ]; then set -o xtrace; fi
# }}}
# Vars {{{
PROGNAME=$(basename "${0}"); readonly PROGNAME
PROGDIR=$(readlink --canonicalize-missing $(dirname "${0}")); readonly PROGDIR
ARGS="${*}"; readonly ARGS
readonly NBARGS="${#}"
[ -z "${DEBUG-}" ] && DEBUG=1
## Export DEBUG for sub-script
export DEBUG
## Default values for some vars
readonly PACKAGE_NAME_DEFAULT="alacritty"
readonly CHECK_MODE_DEFAULT="repository"
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
cat <<- HELP
usage: $PROGNAME [-d|-h]
Try to get last version of ${PACKAGE_NAME_DEFAULT} .deb file.
EXAMPLES:
- Check ${PACKAGE_NAME_DEFAULT} version (from APT repository or manually installed file).
${PROGNAME}
OPTIONS:
-d,--debug
Enable debug messages.
-h,--help
Print this help message.
HELP
}
# }}}
debug_message() { # {{{
local_debug_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_debug_message}"
unset local_debug_message
return 0
}
# }}}
error_message() { # {{{
local_error_message="${1}"
local_error_code="${2}"
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}" >&2
unset local_error_message
exit "${local_error_code:=66}"
}
# }}}
is_var_empty() { # {{{
local_var_empty="${1}"
debug_prefix="${2:-}"
## Return False by default
return_var_empty="1"
debug_message "${debug_prefix}is_var_empty Test var value (${1})."
[ -z "${local_var_empty}" ] && return_var_empty="0"
unset debug_prefix
unset local_var_empty
return "${return_var_empty}"
}
# }}}
define_vars() { # {{{
debug_message "-- define_vars BEGIN"
## If repo_url wasn't defined {{{
is_var_empty "${repo_url-}" "|| " \
&& repo_url="https://github.com/gardouille/alacritty-debian" \
&& debug_message "| define_vars Use value (${RED}${repo_url}${COLOR_DEBUG}) for repo_url variable."
## }}}
## If package_name wasn't defined (argument) {{{
## Use default value
is_var_empty "${package_name-}" "|| " \
&& debug_message "| define_vars Use default value (${RED}${PACKAGE_NAME_DEFAULT}${COLOR_DEBUG}) for package_name variable." \
&& package_name="${PACKAGE_NAME_DEFAULT}"
## }}}
## Get new_version from application repository {{{
new_version=$("${PROGDIR}"/releasetags "${repo_url}" | grep -vE -- '(dev|rc)' | head -n1 | sed 's/v//g')
if is_var_empty "${new_version-}" "|| "; then
error_message "define_vars Invalid value for ${package_name} new version (${new_version})." 1
else
debug_message "| define_vars Get value (${RED}${new_version}${COLOR_DEBUG}) for new_version variable."
fi
## }}}
## If new_package_filename wasn't defined {{{
is_var_empty "${new_package_filename-}" "|| " \
&& new_package_filename="${package_name}_${new_version}_amd64.deb" \
&& debug_message "| define_vars Use value (${RED}${new_package_filename}${COLOR_DEBUG}) for new_package_filename variable."
## }}}
## If new_package_url wasn't defined {{{
is_var_empty "${new_package_url-}" "|| " \
&& new_package_url="${repo_url}/releases/download/v${new_version}/${new_package_filename}" \
&& debug_message "| define_vars Use value (${RED}${new_package_url}${COLOR_DEBUG}) for new_package_url variable."
## }}}
## If new_version_file wasn't defined {{{
is_var_empty "${new_version_file-}" "|| " \
&& new_version_file="/tmp/.github.${package_name}.upgrade" \
&& debug_message "| define_vars Use value (${RED}${new_version_file}${COLOR_DEBUG}) for new_version_file variable."
## }}}
## If tmp_package_path wasn't defined {{{
is_var_empty "${tmp_package_path-}" "|| " \
&& tmp_package_path="/tmp/.${new_package_filename}" \
&& debug_message "| define_vars Use value (${RED}${tmp_package_path}${COLOR_DEBUG}) for tmp_package_path variable."
## }}}
## If new_package_path wasn't defined {{{
is_var_empty "${new_package_path-}" "|| " \
&& new_package_path="/tmp/${new_package_filename}" \
&& debug_message "| define_vars Use value (${RED}${new_package_path}${COLOR_DEBUG}) for new_package_path variable."
## }}}
## If check_mode wasn't defined (argument) {{{
## Use default value
is_var_empty "${check_mode-}" "|| " \
&& debug_message "| define_vars Use default value (${RED}${CHECK_MODE_DEFAULT}${COLOR_DEBUG}) for check_mode variable." \
&& check_mode="${CHECK_MODE_DEFAULT}"
## }}}
## Get current_version according to the check_mode {{{
case "${check_mode}" in
"repo"|"repository" ) ## Check current version from repository
current_version=$(apt-cache policy -- "${package_name}" | awk '/Candidate:/ {print $2}' | sed 's/.:\(.*\)-.*/\1/')
;;
"file" ) ## Check current version from installed .deb file
current_version=$(dpkg --list -- "${package_name}" | awk -v pattern="${package_name}" '$0~pattern {print $3}' | sed 's/.:\(.*\)-.*/\1/')
;;
* ) ## unknow mode
error_message "define_vars Invalid check mode: ${check_mode}. See help message with -h." 2
;;
esac
## If current_version is empty
is_var_empty "${current_version}" "|| " \
&& error_message "define_vars Error with current_version variable (${current_version}) for package (${package_name})." 2
## }}}
debug_message "-- define_vars END"
}
# }}}
is_version_greater_than() { # {{{
first_value="${1}"
value_to_compare="${2}"
debug_prefix="${3:-}"
## Return False by default
return_is_version_greater_than="1"
debug_message "${debug_prefix}is_version_greater_than \
Is first value (${first_value}) greater than the second value (${value_to_compare})."
if printf '%s\n' "${first_value}" "${value_to_compare}" | sort --check=quiet --version-sort; then
debug_message "${debug_prefix}is_version_greater_than ${first_value} <= ${value_to_compare} ."
return_is_version_greater_than="1"
else
debug_message "${debug_prefix}is_version_greater_than ${first_value} > ${value_to_compare} ."
return_is_version_greater_than="0"
fi
unset first_value
unset value_to_compare
unset debug_prefix
return "${return_is_version_greater_than}"
}
# }}}
main() { # {{{
debug_message "--- MAIN BEGIN"
## Define all vars
define_vars
## Uncomment variable(s) to simulate different behaviour
#current_version="1.0.2"
#new_version="42.3.1"
debug_message "-- Test version BEGIN"
## If new_version is greater than current_version {{{
if is_version_greater_than "${new_version}" "${current_version}" "|| "; then
debug_message "| Current version (${current_version}) is older than new one \
(${new_version})."
### If it doesn't already exists, download the new package {{{
if [ ! -f "${new_package_path}" ]; then
debug_message "| Download .deb file from ${package_name} repository on Github to: ${new_package_path} ."
wget --quiet "${new_package_url}" --output-document="${new_package_path}"
fi
### }}}
## }}}
## If current version is uptodate {{{
else
debug_message "| Current version (${current_version}) seems uptodate \
or newer than available version (${new_version})."
### Ensure to remove any temp file and useless .deb files
rm --force -- "${new_version_file}" "${new_package_path}" "${tmp_package_path}"
### Exit
debug_message "-- Test version END"
debug_message "--- MAIN END"
exit 0
fi
## }}}
debug_message "-- Test version END"
## Verify downloaded package {{{
debug_message "-- Verify downloaded package BEGIN"
## If the downloaded package has a size greater than zero {{{
if [ -s "${new_package_path}" ]; then
debug_message "| Downloaded package looks good."
### Create a temp file to monitor
touch -- "${new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for ${package_name} terminal (current: ${current_version}): ${new_version}." >> "${new_version_file}"
## }}}
## If the size is null {{{
else
debug_message "| Empty file, don't need to go further."
### Ensure to remove the file to monitor
rm --force -- "${new_version_file}"
### Keep a record of the downloaded package because as a new release might come soon
mv --force -- "${new_package_path}" "${tmp_package_path}"
fi
## }}}
debug_message "-- Verify downloaded package END"
# }}}
debug_message "--- MAIN END"
# Exit
exit 0
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to argument management
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument ask for help (h|help|-h|-help|-*h|-*help) {{{
if printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-*h(elp)?$"; then
usage
exit 0
fi
## }}}
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep --quiet --extended-regexp -- "^-+";
then
## Print help message and exit
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-+"; do
case "${1}" in
-d|--debug ) ## debug
DEBUG=0
debug_message "--- Manage argument BEGIN"
;;
-f|--file|--files|-p|--package ) ## Define check_mode to file mode
## Define var
readonly check_mode="file"
;;
--repo|--repository ) ## Define check_mode to repo mode
## Define var
readonly check_mode="repo"
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "| ${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "| ${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "| No arguments/options to manage."
fi
debug_message "--- Manage argument END"
# }}}
main
# This should never be reach
exit 255

67
github/check.cachet.update Executable file
View File

@ -0,0 +1,67 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Cachet
## project on Github.
## It based on the cachet's root directory to get the current version and
## supposed to be install from source (github) or at least get a VERSION file.
## 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 with Cachet directory as first argument, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_cachet_update /var/www/cachet
### 3. Monitor the temp file: /tmp/.github.cachet.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect 1 argument {{{
if [ $# -ne 1 ]
then
cat << HELP
check.cachet.update --
Compare current version of an installed Cachet and the last available.
EXAMPLE:
- Compare the current version installed in /var/www/cachet.domain.tld
check.cachet.update /var/www/cachet.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
cachet_install_dir="${1}"
cachet_current_version=$(cd "${cachet_install_dir}" || exit 1 ; grep . -m1 VERSION | sed 's/\(.*\)-.*/\1/g' ; cd - > /dev/null || exit 1)
cachet_repo_url="https://github.com/CachetHQ/Cachet"
cachet_new_version=$("${script_wd}"/releasetags "${cachet_repo_url}" | head -n1 | sed 's/v//')
cachet_new_version_file="/tmp/.github.cachet.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${cachet_current_version}" != "${cachet_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${cachet_current_version}) and new one (${cachet_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${cachet_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Cachet (current: ${cachet_current_version}): ${cachet_new_version}." >> "${cachet_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 -- "${cachet_new_version_file}"
fi
# }}}
exit 0

70
github/check.ceph.update Executable file
View File

@ -0,0 +1,70 @@
#!/bin/sh
# Purpose {{{
## Create a file (to monitor) if an upgrade is available for Ceph
## project on Github.
## It's based on .deb package (or repository) installation to check the
## current version.
## 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_ceph_update
### 3. Monitor the file: /srv/.github.ceph.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Don't expect any argument {{{
if [ $# -gt 0 ]
then
cat << HELP
check.ceph.update --
Compare current version of an installed Ceph and the last available (filtered according to current major version).
EXAMPLE:
- Compare the current version installed from .deb file or repository
check.ceph.update
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
ceph_repo_url="https://github.com/ceph/ceph"
ceph_current_version=$(dpkg -l ceph | awk '/^ii.*ceph/ { print $3}' | sed 's/\(.*\)-.*/\1/')
ceph_current_major_version=$(printf -- '%s' "${ceph_current_version}" | cut -d"." -f1)
## Filter new versions to get only same major releases
ceph_new_version=$("${script_wd}"/releasetags "${ceph_repo_url}" | \
grep "v${ceph_current_major_version}" | \
head -n1 | \
sed 's/v//g')
ceph_new_version_file="/srv/.github.ceph.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${ceph_current_version}" != "${ceph_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${ceph_current_version}) and new one (${ceph_new_version}) seems to be different."
## Create a file to monitor
touch -- "${ceph_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Ceph (current: ${ceph_current_version}): ${ceph_new_version}." >> "${ceph_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 -- "${ceph_new_version_file}"
fi
# }}}
exit 0

66
github/check.cstate.update Executable file
View File

@ -0,0 +1,66 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for cState
## project on Github.
## It's based on the cState URL site to get the current version.
## 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 with cState URL as first argument, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_cstate_update https://vmstatus.domain.tld
### 3. Monitor the temp file: /tmp/.github.cstate.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect 1 argument {{{
if [ $# -ne 1 ]
then
cat << HELP
check.cstate.update --
Compare current version of an installed cState site and the last available.
EXAMPLE:
- Compare the current version installed on https://vmstatus.domain.tld
check.cstate.update https://vmstatus.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
cstate_url="${1}"
cstate_current_version=$(curl --insecure --silent "${cstate_url}" | grep -E 'meta.*generator.*cState.*github.com' | sed 's;.*generator.*content.*cState \(v.*\) - https.*github.com.*;\1;')
cstate_repo_url="https://github.com/cstate/cstate"
cstate_new_version=$("${script_wd}"/releasetags "${cstate_repo_url}" | grep -vE -- '(dev|rc)' | head -n1)
cstate_new_version_file="/tmp/.github.cstate.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${cstate_current_version}" != "${cstate_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${cstate_current_version}) and new one (${cstate_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${cstate_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for cState (current: ${cstate_current_version}): ${cstate_new_version}." >> "${cstate_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 -- "${cstate_new_version_file}"
fi
# }}}
exit 0

255
github/check.etherpad.update.sh Executable file
View File

@ -0,0 +1,255 @@
#!/bin/sh
#
# Purpose {{{
# This script will :
# 1. Get Etherpad version from current installation (from directory)
# 2. Get latest Etherpad version from Github.
# 3. Compare installed and latest version.
# 4. Create a temp file (to monitor) if versions mismatch.
#
## 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 with Etherpad directory as argument, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_cachet_update --directory /srv/www/etherpad-lite
### 3. Monitor the temp file: /tmp/.github.etherpad.upgrade
### 3.b Or enable MAILTO in cronjob and edit the script to print a message.
## }}}
#
# 2022-08-25
# }}}
# Vars {{{
PROGNAME=$(basename "${0}"); readonly PROGNAME
PROGDIR=$(readlink -m $(dirname "${0}")); readonly PROGDIR
ARGS="${*}"; readonly ARGS
readonly NBARGS="${#}"
[ -z "${DEBUG}" ] && DEBUG=1
## Export DEBUG for sub-script
export DEBUG
## Default values for some vars
readonly ETHERPAD_INSTALL_DIR_DEFAULT="/srv/www/etherpad-lite"
readonly ETHERPAD_REPO_URL="https://github.com/ether/etherpad-lite"
readonly ETHERPAD_NEW_VERSION_FILE="/tmp/.github.etherpad.upgrade"
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
cat <<- HELP
usage: $PROGNAME [-d|-h]
Compare Etherpad installed version and latest one.
EXAMPLES:
- Check Etherpad version from default directory (${ETHERPAD_INSTALL_DIR_DEFAULT})
${PROGNAME}
- Check Etherpad version from a specific location
${PROGNAME} --directory /srv/www/my_etherpad
OPTIONS:
--debug
Enable debug messages.
-d,--dir,--directory
Etherppad installation directory.
(default: ${ETHERPAD_INSTALL_DIR_DEFAULT}).
-h,--help
Print this help message.
HELP
}
# }}}
debug_message() { # {{{
local_debug_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_debug_message}"
unset local_debug_message
return 0
}
# }}}
error_message() { # {{{
local_error_message="${1}"
local_error_code="${2}"
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}"
exit "${local_error_code:=66}"
}
# }}}
define_vars() { # {{{
## If etherpad_install_dir wasn't defined (argument) {{{
if [ -z "${etherpad_install_dir}" ]; then
## Use default value
readonly etherpad_install_dir="${ETHERPAD_INSTALL_DIR_DEFAULT}"
fi
## }}}
}
# }}}
is_var_empty() { # {{{
## Return False by default
return_var_empty="1"
## Total number of variables to test
local_total_var="${#}"
loop_count_var_empty="0"
## While it remains a variable to test
while [ "${local_total_var}" -gt "${loop_count_var_empty}" ]; do
debug_message "is_var_empty \
Test var: ${1}."
### Test if this is empty and set return value to True
[ -z "${1}" ] && return_var_empty="0"
### Increase the number of tested variables
loop_count_var_empty=$((loop_count_var_empty+1))
### Shift to the next variable
shift
done
return "${return_var_empty}"
}
# }}}
main() { # {{{
## Define all vars
define_vars
## If Etherpad install dir doesn't exists {{{
### AND Exit with error message
! test -d ${etherpad_install_dir} \
&& error_message "Etherpad installation directory (${etherpad_install_dir}) doesn't seem to exist." 01
## }}}
## Get current version from src/package.json file {{{
### OR Exit with error message
etherpad_current_version=$(sed --silent 's/.*"version": "\(.*\)".*/\1/p' "${etherpad_install_dir}"/src/package.json \
|| error_message "Can't get current Etherpad version from file (${etherpad_install_dir}/src/package.json)." 02 )
debug_message "main Etherpad installed version : ${RED}${etherpad_current_version}${COLOR_DEBUG} (from ${etherpad_install_dir}/src/package.json file)."
## }}}
## Get latest version from project repository {{{
### OR Exit with error message
etherpad_latest_version=$("${PROGDIR}/releasetags" "${ETHERPAD_REPO_URL}" | head --lines=1 | sed 's/v//' \
|| error_message "Can't get latest Etherpad version from repository (${ETHERPAD_REPO_URL})." 02 )
debug_message "main Etherpad available version : ${RED}${etherpad_latest_version}${COLOR_DEBUG} (from ${ETHERPAD_REPO_URL} project repository)."
## }}}
## If any of the two variables is empty {{{
### OR Exit with error message
### Double check :)
is_var_empty "${etherpad_current_version}" "${etherpad_latest_version}" \
&& error_message "At least one variable is empty (current version : ${etherpad_current_version}, latest version : ${etherpad_latest_version}) !" 04
## }}}
# Check if the current version is the last one {{{
## If the two versions are the same {{{
if [ "${etherpad_current_version}" = "${etherpad_latest_version}" ]; then
debug_message "Test version \
The current Etherpad version (${etherpad_current_version}) is up-to-date."
### Ensure to remove any temp file
rm --force -- "${ETHERPAD_NEW_VERSION_FILE}"
exit 0
## }}}
## If the versions are different {{{
else
debug_message "Test version \
Current version (${etherpad_current_version}) and latest one (${etherpad_latest_version}) seems to be different."
## Create a temp file to monitor
touch -- "${ETHERPAD_NEW_VERSION_FILE}"
debug_message "An upgrade is available for Cachet (current: ${etherpad_current_version}): ${etherpad_latest_version}." >> "${ETHERPAD_NEW_VERSION_FILE}"
exit 0
fi
## }}}
# }}}
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to argument management
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep -q -E -- "^-+";
then
## Print help message and exit
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in
--debug ) ## debug
DEBUG=0
;;
-h|--help ) ## help
usage
## Exit after help informations
exit 0
;;
-d|--dir|--directory ) ## Define etherpad_install_dir with given arg
### Move to the next argument
shift
### Define var
readonly etherpad_install_dir="${1}"
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "Arguments management \
${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "Arguments management \
${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "Arguments management \
No arguments/options to manage."
fi
# }}}
main
exit 255

View File

@ -0,0 +1,77 @@
#!/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

328
github/check.gitea.update Executable file
View File

@ -0,0 +1,328 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Gitea
## project on dl.gitea.io/Github.
## It based on gitea's binary available in $PATH or give 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_gitea_update
### 2-1 Create a cron job with a specific path for gitea bin, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_gitea_update /srv/bin/gitea
### 3. Monitor the temp file: /tmp/.github.gitea.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Vars {{{
readonly PROGNAME=$(basename "${0}")
readonly PROGDIR=$(readlink -m $(dirname "${0}"))
readonly ARGS="${*}"
readonly NBARGS="${#}"
## Test if DEBUG is already defined (by parent script,…)
[ -z "${DEBUG}" ] && DEBUG=1
## Default values for some vars
GITEA_BIN_PATH_DEFAULT="$(command -v gitea)"
GITEA_DOWNLOAD_DEFAULT=1
gitea_download_github=1
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
cat << HELP
usage: $PROGNAME (/path/to/gitea) [-b|-p|-d|-h]
Compare current version of an installed Gitea and the last available.
EXAMPLES:
- Compare the current version of Gitea with bin available in \$PATH
${PROGNAME}
- Compare the current version of Gitea at a specific place
${PROGNAME} /srv/bin/gitea
${PROGNAME} --path /srv/bin/gitea
- Compare version and try to download the new version if require,
next to current bin with '.to.upgrade.vX.YY.ZZ' suffix.
${PROGNAME} --download
${PROGNAME} --path /srv/bin/gitea --download
- Compare version and try to download the new version from github.
${PROGNAME} --download --github
OPTIONS:
-b,--bin,-p,--path
Set the Gitea's path to use.
--download
Try to download the new release if available.
--github
Download new version from Github repository
(dl.gitea.io is used by default).
-d,--debug
Enable debug messages.
-h,--help
Print this help message.
HELP
}
# }}}
debug_message() { # {{{
local_debug_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_debug_message}"
unset local_debug_message
return 0
}
# }}}
error_message() { # {{{
local_error_message="${1}"
local_error_code="${2}"
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}"
exit "${local_error_code:=66}"
}
# }}}
is_var_empty() { # {{{
## Return False by default
return_var_empty="1"
## Total number of variables to test
local_total_var_empty="${#}"
loop_count_var_empty="0"
## While it remains a variable to test
while [ "${local_total_var_empty}" -gt "${loop_count_var_empty}" ]; do
debug_message "is_var_empty \
Test var: ${1}."
### Test if this is empty and set return value to True
[ -z "${1}" ] && return_var_empty="0"
### Increase the number of tested variables
loop_count_var_empty=$((loop_count_var_empty+1))
### Shift to the next variable
shift
done
unset local_total_var_empty
unset loop_count_var_empty
return "${return_var_empty}"
}
# }}}
is_file_empty() { # {{{
local_file="${1}"
## File is empty by default
return_is_file_empty="0"
### Check if the file is empty
if [ ! -s "${local_file}" ]; then
return_is_file_empty="0"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} is empty or doesn't exists."
else
return_is_file_empty="1"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} exists and has a size greater than zero."
fi
return "${return_is_file_empty}"
}
# }}}
define_vars() { # {{{
## If gitea_bin_path wasn't defined (argument) {{{
## Use default value
is_var_empty "${gitea_bin_path}" \
&& gitea_bin_path="${GITEA_BIN_PATH_DEFAULT}"
## }}}
## If gitea_download wasn't defined (argument) {{{
## Use default value
is_var_empty "${gitea_download}" \
&& gitea_download="${GITEA_DOWNLOAD_DEFAULT}"
## }}}
## Directory where is current Gitea bin
gitea_bin_dir=$(readlink -m $(dirname "${gitea_bin_path}"))
## Main Gitea repo's URL
gitea_repo_url="https://github.com/go-gitea/gitea"
## Gitea's versions
gitea_current_version=$("${gitea_bin_path}" --version | cut --delimiter=' ' --fields=3)
gitea_new_version=$("${PROGDIR}"/releasetags "${gitea_repo_url}" | grep --invert-match --extended-regexp -- '(dev|rc|^$)' | head --lines=1 | sed 's/v//')
## Gitea new version's URL
if [ "${gitea_download_github}" -eq "0" ]; then
gitea_new_version_url="https://github.com/go-gitea/gitea/releases/download/v${gitea_new_version}/gitea-${gitea_new_version}-linux-amd64"
else
gitea_new_version_url="https://dl.gitea.io/gitea/${gitea_new_version}/gitea-${gitea_new_version}-linux-amd64"
fi
## Gitea new version's path
gitea_new_bin_path="${gitea_bin_path}.to.upgrade.v${gitea_new_version}"
## Temp file to monitor
gitea_new_version_file="/tmp/.github.gitea.upgrade"
}
# }}}
main() { # {{{
define_vars
# If gitea_bin_path is empty {{{
# Exit with error
is_var_empty "${gitea_current_version}" \
&& error_message "Can't get current version from Gitea's binary (${gitea_bin_path})." 1
# }}}
# If gitea_new_version is empty {{{
# Exit with error
is_var_empty "${gitea_new_version}" \
&& error_message "Can't get new version (${gitea_new_version}) from Gitea's repository (${gitea_repo_url})." 1
# }}}
# If an update is available {{{
if [ "${gitea_current_version}" != "${gitea_new_version}" ]; then
debug_message "Test version \
Current version (${RED}${gitea_current_version}${COLOR_DEBUG}) and new one (${RED}${gitea_new_version}${COLOR_DEBUG}) seems different."
## Create a temp file to monitor
touch -- "${gitea_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Gitea (current: ${gitea_current_version}): ${gitea_new_version}." >> "${gitea_new_version_file}"
## If new release should be downloaded
if [ "${gitea_download}" -eq "0" ]; then
### Download and prepare the new bin {{{
debug_message "Test version \
Download Gitea binary (from ${gitea_new_version_url} ) to ${RED}${gitea_new_bin_path}${COLOR_DEBUG} ."
wget --quiet "${gitea_new_version_url}" --output-document="${gitea_new_bin_path}"
### }}}
### If the new binary file is empty {{{
### Ensure to remove (don't want an empty upgrade file)
### Exit with error
is_file_empty "${gitea_new_bin_path}" \
&& rm --force -- "${gitea_new_bin_path}" \
&& error_message "New binary (${gitea_new_bin_path}) is empty or doesn't exists." 2
### }}}
chmod +x -- "${gitea_new_bin_path}"
fi
# }}}
# Gitea is up-to-date {{{
else
debug_message "Test version \
The current version (${RED}${gitea_current_version}${COLOR_DEBUG}) is up-to-date."
debug_message "Test version \
Ensure to remove temp file and any previous and unused releases."
rm --force -- "${gitea_new_version_file}"
find "${gitea_bin_dir}" -maxdepth 1 -type f -iname "gitea.to.upgrade*" -delete
fi
# }}}
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to arguments
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep --quiet --extended-regexp -- "^-+";
then
## Consider it as the path to Gitea
gitea_bin_path="${1}"
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1}" | grep --quiet --extended-regexp -- "^-+"; do
case "${1}" in
-b|--bin|-p|--path ) ## Define gitea_bin_path
## Move to the next argument
shift
## Define var
readonly gitea_bin_path="${1}"
;;
--download ) ## Enable download_mode
## Try to download new release if available
gitea_download=0
;;
--github ) ## Download new release from Github
## Try to download new release from Github
gitea_download_github=0
;;
-d|--debug ) ## debug
DEBUG=0
;;
-h|--help ) ## help
usage
## Exit after help informations
exit 0
;;
-- ) ## End of options list
## End the while loop
break
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "Arguments management \
${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "Arguments management \
${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "Arguments management \
No arguments/options to manage."
fi
# }}}
main
exit 0

379
github/check.glpi-agent.update Executable file
View File

@ -0,0 +1,379 @@
#!/bin/sh
#
# Purpose {{{
# This script will try to get last version of glpi-agent .deb file
# https://github.com/glpi-project/glpi-agent/releases
# 1. Get current version from APT repo (by default).
# 1.b Or use version from manually installed package (with --file option).
# 2. Get latest version from github repository.
# 3. Compare current and new versions.
# 4. Download the .deb file for this new version.
# 5. Create a temp file (to monitor) if an upgrade is available.
# }}}
## 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.glpi-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.glpi-agent.update --repo
### 3. Monitor the temp file: /tmp/.github.glpi-agent.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
# }}}
# Flags {{{
## Exit on error
set -o errexit
## Exit on unset var
### Use "${VARNAME-}" to test a var that may not have been set
set -o nounset
## Pipeline command is treated as failed
### Not available in POSIX sh https://github.com/koalaman/shellcheck/wiki/SC3040
#set -o pipefail
## Help with debugging
### Call the script by prefixing it with "TRACE=1 ./script.sh"
if [ "${TRACE-0}" -eq 1 ]; then set -o xtrace; fi
# }}}
# Vars {{{
PROGNAME=$(basename "${0}"); readonly PROGNAME
PROGDIR=$(readlink --canonicalize-missing $(dirname "${0}")); readonly PROGDIR
ARGS="${*}"; readonly ARGS
readonly NBARGS="${#}"
[ -z "${DEBUG-}" ] && DEBUG=1
## Export DEBUG for sub-script
export DEBUG
## Default values for some vars
readonly PACKAGE_NAME_DEFAULT="glpi-agent"
readonly CHECK_MODE_DEFAULT="repository"
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
cat <<- HELP
usage: $PROGNAME [-d|-h|-f|-r]
Try to get last version of ${PACKAGE_NAME_DEFAULT} .deb file.
EXAMPLES:
- Check ${PACKAGE_NAME_DEFAULT} version (from APT repository or manually installed file).
${PROGNAME}
OPTIONS:
-d,--debug
Enable debug messages.
-h,--help
Print this help message.
-f,--file,--p,--package
Use manually installed package.
-r,--repo,--repository
Use ${PACKAGE_NAME_DEFAULT} version from APT repository.
HELP
}
# }}}
debug_message() { # {{{
local_debug_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_debug_message}"
unset local_debug_message
return 0
}
# }}}
error_message() { # {{{
local_error_message="${1}"
local_error_code="${2}"
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}" >&2
unset local_error_message
exit "${local_error_code:=66}"
}
# }}}
is_var_empty() { # {{{
local_var_empty="${1}"
debug_prefix="${2:-}"
## Return False by default
return_var_empty="1"
debug_message "${debug_prefix}is_var_empty Test var value (${1})."
[ -z "${local_var_empty}" ] && return_var_empty="0"
unset debug_prefix
unset local_var_empty
return "${return_var_empty}"
}
# }}}
define_vars() { # {{{
debug_message "-- define_vars BEGIN"
## If repo_url wasn't defined {{{
is_var_empty "${repo_url-}" "|| " \
&& repo_url="https://github.com/glpi-project/glpi-agent" \
&& debug_message "| define_vars Use value (${RED}${repo_url}${COLOR_DEBUG}) for repo_url variable."
## }}}
## If package_name wasn't defined (argument) {{{
## Use default value
is_var_empty "${package_name-}" "|| " \
&& debug_message "| define_vars Use default value (${RED}${PACKAGE_NAME_DEFAULT}${COLOR_DEBUG}) for package_name variable." \
&& package_name="${PACKAGE_NAME_DEFAULT}"
## }}}
## Get new_version_major from application repository {{{
new_version_major=$("${PROGDIR}"/releasetags "${repo_url}" | grep --invert-match --extended-regexp -- '(dev|rc)' | head --lines=1 | sed 's/v//g')
if is_var_empty "${new_version_major-}" "|| "; then
error_message "define_vars Invalid value for ${package_name} new version (${new_version_major})." 1
else
debug_message "| define_vars Get value (${RED}${new_version_major}${COLOR_DEBUG}) for new_version_major variable."
fi
## }}}
## Get new_version_revision from official installer script {{{
## Because Github release version don't integer revision number…
## Download installer script
installer_script_file="/tmp/glpi-agent-${new_version_major}-linux-installer.pl"
installer_script_url="https://github.com/glpi-project/glpi-agent/releases/download/${new_version_major}/glpi-agent-${new_version_major}-linux-installer.pl"
wget --quiet "${installer_script_url}" --output-document="${installer_script_file}"
## Parse file to find any revision number
new_version_revision=$(grep --text "^my \$DEBREVISION" -- "${installer_script_file}" | cut --delimiter=\" --fields=2)
## Define new_version according to revision number
if is_var_empty "${new_version_revision-}" "|| "; then
debug_message "| define_vars No revision for this package."
new_version="${new_version_major}"
else
debug_message "| define_vars There is a revision (${new_version_revision}) for this package."
new_version="${new_version_major}-${new_version_revision}"
fi
debug_message "| define_vars Set (${RED}${new_version}${COLOR_DEBUG}) for new_version variable."
## }}}
## If new_package_filename wasn't defined {{{
is_var_empty "${new_package_filename-}" "|| " \
&& new_package_filename="${package_name}_${new_version}_all.deb" \
&& debug_message "| define_vars Use value (${RED}${new_package_filename}${COLOR_DEBUG}) for new_package_filename variable."
## }}}
## If new_package_url wasn't defined {{{
is_var_empty "${new_package_url-}" "|| " \
&& new_package_url="${repo_url}/releases/download/${new_version_major}/${new_package_filename}" \
&& debug_message "| define_vars Use value (${RED}${new_package_url}${COLOR_DEBUG}) for new_package_url variable."
## }}}
## If new_version_file wasn't defined {{{
is_var_empty "${new_version_file-}" "|| " \
&& new_version_file="/tmp/.github.${package_name}.upgrade" \
&& debug_message "| define_vars Use value (${RED}${new_version_file}${COLOR_DEBUG}) for new_version_file variable."
## }}}
## If tmp_package_path wasn't defined {{{
is_var_empty "${tmp_package_path-}" "|| " \
&& tmp_package_path="/tmp/.${new_package_filename}" \
&& debug_message "| define_vars Use value (${RED}${tmp_package_path}${COLOR_DEBUG}) for tmp_package_path variable."
## }}}
## If new_package_path wasn't defined {{{
is_var_empty "${new_package_path-}" "|| " \
&& new_package_path="/tmp/${new_package_filename}" \
&& debug_message "| define_vars Use value (${RED}${new_package_path}${COLOR_DEBUG}) for new_package_path variable."
## }}}
## If check_mode wasn't defined (argument) {{{
## Use default value
is_var_empty "${check_mode-}" "|| " \
&& debug_message "| define_vars Use default value (${RED}${CHECK_MODE_DEFAULT}${COLOR_DEBUG}) for check_mode variable." \
&& check_mode="${CHECK_MODE_DEFAULT}"
## }}}
## Get current_version according to the check_mode {{{
case "${check_mode}" in
"repo"|"repository" ) ## Check current version from repository
current_version=$(apt-cache policy -- "${package_name}" | awk '/Candidate:/ {print $2}' | sed 's/.:\(.*\)/\1/')
;;
"file" ) ## Check current version from installed .deb file
current_version=$(dpkg --list -- "${package_name}" | awk -v pattern="${package_name}" '$0~pattern {print $3}' | sed 's/.:\(.*\)-.*/\1/')
;;
* ) ## unknow mode
error_message "define_vars Invalid check mode: ${check_mode}. See help message with -h." 2
;;
esac
## If current_version is empty
is_var_empty "${current_version}" "|| " \
&& error_message "define_vars Error with current_version variable (${current_version}) for package (${package_name})." 2
## }}}
debug_message "-- define_vars END"
}
# }}}
is_version_greater_than() { # {{{
first_value="${1}"
value_to_compare="${2}"
debug_prefix="${3:-}"
## Return False by default
return_is_version_greater_than="1"
debug_message "${debug_prefix}is_version_greater_than \
Is first value (${first_value}) greater than the second value (${value_to_compare})."
if printf '%s\n' "${first_value}" "${value_to_compare}" | sort --check=quiet --version-sort; then
debug_message "${debug_prefix}is_version_greater_than ${first_value} <= ${value_to_compare} ."
return_is_version_greater_than="1"
else
debug_message "${debug_prefix}is_version_greater_than ${first_value} > ${value_to_compare} ."
return_is_version_greater_than="0"
fi
unset first_value
unset value_to_compare
unset debug_prefix
return "${return_is_version_greater_than}"
}
# }}}
main() { # {{{
debug_message "--- MAIN BEGIN"
## Define all vars
define_vars
## Uncomment variable(s) to simulate different behaviour
#current_version="14-1"
#new_version="22-1"
debug_message "-- Test version BEGIN"
## If new_version is greater than current_version {{{
if is_version_greater_than "${new_version}" "${current_version}" "|| "; then
debug_message "| Current version (${current_version}) is older than new one \
(${new_version})."
### If it doesn't already exists, download the new package {{{
if [ ! -f "${new_package_path}" ]; then
debug_message "| Download .deb file from ${package_name} repository on Github to: ${new_package_path} ."
wget --quiet "${new_package_url}" --output-document="${new_package_path}"
fi
### }}}
## }}}
## If current version is uptodate {{{
else
debug_message "| Current version (${current_version}) seems uptodate \
or newer than available version (${new_version})."
### Ensure to remove any temp file and useless .deb files
rm --force -- "${new_version_file}" "${new_package_path}" "${tmp_package_path}" "${installer_script_file}"
### Exit
debug_message "-- Test version END"
debug_message "--- MAIN END"
exit 0
fi
## }}}
debug_message "-- Test version END"
## Verify downloaded package {{{
debug_message "-- Verify downloaded package BEGIN"
## If the downloaded package has a size greater than zero {{{
if [ -s "${new_package_path}" ]; then
debug_message "| Downloaded package looks good."
### Create a temp file to monitor
touch -- "${new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for ${package_name} terminal (current: ${current_version}): ${new_version}." >> "${new_version_file}"
## }}}
## If the size is null {{{
else
debug_message "| Empty file, don't need to go further."
### Ensure to remove the file to monitor
rm --force -- "${new_version_file}" "${installer_script_file}"
### Keep a record of the downloaded package because as a new release might come soon
mv --force -- "${new_package_path}" "${tmp_package_path}"
fi
## }}}
debug_message "-- Verify downloaded package END"
# }}}
debug_message "--- MAIN END"
# Exit
exit 0
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to argument management
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument ask for help (h|help|-h|-help|-*h|-*help) {{{
if printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-*h(elp)?$"; then
usage
exit 0
fi
## }}}
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep --quiet --extended-regexp -- "^-+";
then
## Print help message and exit
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-+"; do
case "${1}" in
-d|--debug ) ## debug
DEBUG=0
debug_message "--- Manage argument BEGIN"
;;
-f|--file|--files|-p|--package ) ## Define check_mode to file mode
## Define var
readonly check_mode="file"
;;
--repo|--repository ) ## Define check_mode to repo mode
## Define var
readonly check_mode="repo"
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "| ${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "| ${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "| No arguments/options to manage."
fi
debug_message "--- Manage argument END"
# }}}
main
# This should never be reach
exit 255

View File

@ -8,7 +8,7 @@
### cf. https://git.101010.fr/gardouille-dotfiles/scripts/github/releasetags
# wget https://git.101010.fr/gardouille-dotfiles/scripts/raw/branch/master/github/releasetags
### 2. Create a cron job with Jellyfin URL as first argument, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check_jellyfin_update http://jellyfin.domain.tld:port/System/Info/Public
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_jellyfin_update http://jellyfin.domain.tld:port/System/Info/Public
### 3. Monitor the temp file: /tmp/.github.jellyfin.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.

127
github/check.nextcloud.update Executable file
View File

@ -0,0 +1,127 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Nextcloud
## project on Github or one of it's application.
## It based on the nextcloud's root directory to get the current version and
## supposed to be install from source (github) or at least get a VERSION file.
## For Nextcloud's apps, the `occ` command is used with sudo www-data.
## 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 with Nextcloud directory as first argument, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_nextcloud_update /var/www/nextcloud
### 3. Monitor the temp file: /tmp/.github.nextcloud.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect 1 argument {{{
if [ $# -ne 1 ]
then
cat << HELP
check.nextcloud.update --
Compare current version of an installed Nextcloud and the last available.
EXAMPLE:
- Compare the current version installed in /var/www/nextcloud.domain.tld
check.nextcloud.update /var/www/nextcloud.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
nc_install_dir="${1}"
nc_occ_path="${nc_install_dir}/occ"
## Nextcloud core {{{
nc_current_version=$(grep -- OC_VersionString "${nc_install_dir}"/version.php | sed "s/^\$OC.* = '\(.*\)';$/\1/" || exit 1)
nc_current_major=$(grep -- OC_VersionString "${nc_install_dir}"/version.php | sed "s/^\$OC.* = '\(.*\)';$/\1/" | cut -d"." -f1 || exit 2)
nc_repo_url="https://github.com/nextcloud/server"
nc_new_version_list="/tmp/.github.nextcloud.taglist"
#nc_new_version=$("${script_wd}"/releasetags "${nc_repo_url}" | grep -v -E -- "(^v|alpha|beta|RC)" | head -n3)
nc_new_version_file="/tmp/.github.nextcloud.upgrade"
## }}}
## Apps {{{
nc_app_upgrade=$(sudo -u www-data php --file "${nc_occ_path}" app:update --showonly)
nc_app_new_version_file="/tmp/.github.nextcloud.app.upgrade"
## }}}
# }}}
# Check Nextcloud upgrade {{{
# Get the 3 last tags releses for Nextcloud
## Exclude tag starting with "v", and those contains alpha, beta or RC
rm --force -- "${nc_new_version_list}" ; touch -- "${nc_new_version_list}"
"${script_wd}"/releasetags "${nc_repo_url}" | grep -v -E -- "(alpha|beta|RC|rc)" | sed 's/^v//' | head -n3 >> "${nc_new_version_list}"
# For all tags contained in the tag list
while IFS= read -r nc_new_version; do
# Check if the current version is the last one {{{
if [ "${nc_current_version}" != "${nc_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${nc_current_version}) and latest available (${nc_new_version}) seems to be different."
nc_new_major=$(echo "${nc_new_version}" | cut -d"." -f1)
## If it's a minor release for stable or a new stable version {{{
if [ "${nc_current_major}" -le "${nc_new_major}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test release major — A minor or major upgrade needs to be apply."
### Create a temp file to monitor
touch -- "${nc_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Nextcloud (current: ${nc_current_version}): ${nc_new_version}." >> "${nc_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "Please also take a look to the CHANGELOG: https://nextcloud.com/changelog/#latest${nc_new_major}" >> "${nc_new_version_file}"
## }}}
## It's an upgrade for a previous major release {{{
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test release major — It looks like an upgrade for a previous major release."
fi
## }}}
# }}}
# Same version {{{
else
## If no previous upgrade was already detected
if [ ! -s "${nc_app_new_version_file}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
rm --force -- "${nc_new_version_file}"
### Exit while loop
break
fi
fi
# }}}
done < "${nc_new_version_list}"
rm --force -- "${nc_new_version_list}"
# }}}
# Check apps upgrade {{{
rm --force -- "${nc_app_new_version_file}" ; touch -- "${nc_app_new_version_file}"
printf '%s' "${nc_app_upgrade}" >> "${nc_app_new_version_file}"
## If the file exists with a size bigger than 0
if [ -s "${nc_app_new_version_file}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Apps test — Upgrade seems to be available for apps. Please check ${nc_app_new_version_file}."
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Apps test — All apps seems up-to-date."
rm --force -- "${nc_app_new_version_file}"
fi
# }}}
exit 0

352
github/check.owncloud.update.sh Executable file
View File

@ -0,0 +1,352 @@
#!/bin/sh
#
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Owncloud Core
## project on Github or one of it's application.
# 1. Get current version from APT repo (by default).
# 1.b Or use version from version.php file (with --file-mode option).
# 2. Get latest version from github repository.
# 3. Compare current and new versions.
# 4. …
# 5. Create a temp file (to monitor) if an upgrade is available.
#
# 2023-03-04
# }}}
# 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.owncloud.update.sh
## 2-1 Create a cron job to compare the current version from version.php file (default to: /var/www/owncloud/version.php)
#00 20 * * * root /opt/repos/gardouille.scripts/github/check.owncloud.update.sh --file-mode
## 2-2 Create a cron job to compare the current version from version.php file on a specific location
#00 20 * * * root /opt/repos/gardouille.scripts/github/check.owncloud.update.sh --file /srv/www/owncloud/version.php
## 3. Monitor the temp file: /tmp/.github.owncloud.upgrade
# }}}
# Flags {{{
## Exit on error
set -o errexit
## Exit on unset var
### Use "${VARNAME-}" to test a var that may not have been set
set -o nounset
## Pipeline command is treated as failed
### Not available in POSIX sh https://github.com/koalaman/shellcheck/wiki/SC3040
#set -o pipefail
## Help with debugging
### Call the script by prefixing it with "TRACE=1 ./script.sh"
if [ "${TRACE-0}" -eq 1 ]; then set -o xtrace; fi
# }}}
# Vars {{{
PROGNAME=$(basename "${0}"); readonly PROGNAME
PROGDIR=$(readlink --canonicalize-missing $(dirname "${0}")); readonly PROGDIR
ARGS="${*}"; readonly ARGS
readonly NBARGS="${#}"
[ -z "${DEBUG-}" ] && DEBUG=1
## Export DEBUG for sub-script
export DEBUG
## Default values for some vars
readonly PACKAGE_NAME_DEFAULT="owncloud-complete-files"
readonly VERSION_PHP_FILE_DEFAULT="/var/www/owncloud/version.php"
readonly CHECK_MODE_DEFAULT="repository"
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
cat <<- HELP
usage: $PROGNAME [-d|-f|-h|-p|-r]
Try to compare current version of installed Owncloud with latest version on Github.
EXAMPLES:
- Default - Check current version from installed package with APT repository (default package name: ${PACKAGE_NAME_DEFAULT})
${PROGNAME}
${PROGNAME} --repo-mode
- Check current version from a specific .deb package name
${PROGNAME} --package owncloud-server
- Check current version from Owncloud's version.php file (default location: ${VERSION_PHP_FILE_DEFAULT})
${PROGNAME} --file-mode
- Check current version from Owncloud's version.php file on specific location (auto set file-mode)
${PROGNAME} --file /srv/www/owncloud/version.php
OPTIONS:
-d,--debug
Enable debug messages.
--file-mode
Get current Owncloud's version from version.php file.
-f,--file
Define version.php file location.
Default: ${VERSION_PHP_FILE_DEFAULT}
-h,--help
Print this help message.
-p,--package
Define the .deb package name to parse.
Default: ${PACKAGE_NAME_DEFAULT}
-r,--repo-mode,--repo,--repository
(default) Get current Owncloud's version of .deb package version from APT repository.
HELP
}
# }}}
debug_message() { # {{{
local_debug_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_debug_message}"
unset local_debug_message
return 0
}
# }}}
error_message() { # {{{
local_error_message="${1}"
local_error_code="${2}"
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}" >&2
unset local_error_message
exit "${local_error_code:=66}"
}
# }}}
is_var_empty() { # {{{
local_var_empty="${1}"
debug_prefix="${2:-}"
## Return False by default
return_var_empty="1"
debug_message "${debug_prefix}is_var_empty Test var value (${1})."
[ -z "${local_var_empty}" ] && return_var_empty="0"
unset debug_prefix
unset local_var_empty
return "${return_var_empty}"
}
# }}}
define_vars() { # {{{
debug_message "-- define_vars BEGIN"
## If repo_url wasn't defined {{{
is_var_empty "${repo_url-}" "|| " \
&& repo_url="https://github.com/owncloud/core" \
&& debug_message "| define_vars Use value (${RED}${repo_url}${COLOR_DEBUG}) for repo_url variable."
## }}}
## If package_name wasn't defined (argument) {{{
## Use default value
is_var_empty "${package_name-}" "|| " \
&& debug_message "| define_vars Use default value (${RED}${PACKAGE_NAME_DEFAULT}${COLOR_DEBUG}) for package_name variable." \
&& package_name="${PACKAGE_NAME_DEFAULT}"
## }}}
## Get new_version from application repository {{{
new_version=$("${PROGDIR}"/releasetags "${repo_url}" | grep -vE -- '(dev|rc)' | head -n1 | sed 's/v//g')
if is_var_empty "${new_version-}" "|| "; then
error_message "define_vars Invalid value for ${package_name} new version (${new_version})." 1
else
debug_message "| define_vars Get value (${RED}${new_version}${COLOR_DEBUG}) for new_version variable."
fi
## }}}
## If new_version_file wasn't defined {{{
is_var_empty "${new_version_file-}" "|| " \
&& new_version_file="/tmp/.github.${package_name}.upgrade" \
&& debug_message "| define_vars Use value (${RED}${new_version_file}${COLOR_DEBUG}) for new_version_file variable."
## }}}
## If check_mode wasn't defined (argument) {{{
## Use default value
is_var_empty "${check_mode-}" "|| " \
&& debug_message "| define_vars Use default value (${RED}${CHECK_MODE_DEFAULT}${COLOR_DEBUG}) for check_mode variable." \
&& check_mode="${CHECK_MODE_DEFAULT}"
## }}}
## Get current_version according to the check_mode {{{
case "${check_mode}" in
"repo"|"repository" ) ## Check current version from repository
current_version=$(apt-cache policy -- "${package_name}" | awk '/Installed:/ {print $2}' | sed 's/.:\(.*\)-.*/\1/')
;;
"file" ) ## Check current version from installed .deb file
current_version=$(sed --silent "s/^\$OC_VersionString = '\(.*\)';/\1/p" "${version_php_file}")
;;
* ) ## unknow mode
error_message "define_vars Invalid check mode: ${check_mode}. See help message with -h." 2
;;
esac
## If current_version is empty
is_var_empty "${current_version}" "|| " \
&& error_message "define_vars Error with current_version variable (${current_version}) for package (${package_name})." 2
## }}}
debug_message "-- define_vars END"
}
# }}}
is_version_greater_than() { # {{{
first_value="${1}"
value_to_compare="${2}"
debug_prefix="${3:-}"
## Return False by default
return_is_version_greater_than="1"
debug_message "${debug_prefix}is_version_greater_than \
Is first value (${first_value}) greater than the second value (${value_to_compare})."
if printf '%s\n' "${first_value}" "${value_to_compare}" | sort --check=quiet --version-sort; then
debug_message "${debug_prefix}is_version_greater_than ${first_value} <= ${value_to_compare} ."
return_is_version_greater_than="1"
else
debug_message "${debug_prefix}is_version_greater_than ${first_value} > ${value_to_compare} ."
return_is_version_greater_than="0"
fi
unset first_value
unset value_to_compare
unset debug_prefix
return "${return_is_version_greater_than}"
}
# }}}
main() { # {{{
debug_message "--- MAIN BEGIN"
## Define all vars
define_vars
## Uncomment variable(s) to simulate different behaviour
#current_version="10.13.2"
#current_version="10.13.2-3+1.1"
#new_version="10.19.2"
debug_message "-- Test version BEGIN"
## If new_version is greater than current_version {{{
if is_version_greater_than "${new_version}" "${current_version}" "|| "; then
debug_message "| Current version (${current_version}) is older than new one \
(${new_version})."
### Create a temp file to monitore
touch -- "${new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Owncloud (current: ${current_version}): ${new_version}." >> "${new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "Please also take a look to the CHANGELOG: https://owncloud.com/changelog/server/" >> "${new_version_file}"
## }}}
## If current version is uptodate {{{
else
debug_message "| Current version (${current_version}) seems uptodate \
or newer than available version (${new_version})."
### Ensure to remove any temp file
rm --force -- "${new_version_file}"
### Exit
debug_message "-- Test version END"
debug_message "--- MAIN END"
exit 0
fi
## }}}
debug_message "-- Test version END"
debug_message "--- MAIN END"
# Exit
exit 0
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to argument management
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument ask for help (h|help|-h|-help|-*h|-*help) {{{
if printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-*h(elp)?$"; then
usage
exit 0
fi
## }}}
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep --quiet --extended-regexp -- "^-+";
then
## Print help message and exit
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-+"; do
case "${1}" in
-d|--debug ) ## debug
DEBUG=0
debug_message "--- Manage argument BEGIN"
;;
-p|--package ) ## Define package_name
## Move to the next argument
shift
## Define var
readonly package_name="${1}"
;;
-f|--file ) ## Define version_php_file
## Move to the next argument
shift
## Define var
readonly version_php_file="${1}"
## AND set check_mode to file mode
readonly check_mode="file"
;;
--file-mode ) ## Define check_mode to file mode
## Define var
readonly check_mode="file"
;;
-r|--repo-mode|--repo|--repository ) ## Define check_mode to repo mode
## Define var
readonly check_mode="repo"
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "| ${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "| ${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "| No arguments/options to manage."
fi
debug_message "--- Manage argument END"
# }}}
main
# This should never be reach
exit 255

67
github/check.privatebin.update Executable file
View File

@ -0,0 +1,67 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for PrivateBin
## project on Github.
## It based on the privatebin's root directory to get the current version and
## supposed to be install from source (github) or archives.
## 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 with PrivateBin directory as first argument, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_privatebin_update /var/www/privatebin
### 3. Monitor the temp file: /tmp/.github.privatebin.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect 1 argument {{{
if [ $# -ne 1 ]
then
cat << HELP
check.privatebin.update --
Compare current version of an installed PrivateBin and the last available.
EXAMPLE:
- Compare the current version installed in /var/www/privatebin.domain.tld
check.privatebin.update /var/www/privatebin.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=0
script_wd=$(dirname "${0}")
pb_install_dir="${1}"
pb_current_version=$(cd "${pb_install_dir}" || exit 1 ; awk '/@version/ { print $3 }' lib/Configuration.php || exit 1 ; cd - > /dev/null || exit 1)
pb_repo_url="https://github.com/PrivateBin/PrivateBin"
pb_new_version=$("${script_wd}"/releasetags "${pb_repo_url}" | head -n1 | sed 's/v//')
pb_new_version_file="/tmp/.github.privatebin.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${pb_current_version}" != "${pb_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${pb_current_version}) and new one (${pb_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${pb_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for PrivateBin (current: ${pb_current_version}): ${pb_new_version}." >> "${pb_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 -- "${pb_new_version_file}"
fi
# }}}
exit 0

View File

@ -0,0 +1,113 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Rocket.Chat.Electron
## project on Github.
## 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. 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.rocketchat-electron.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.rocketchat-electron.update repo
### 3. Monitor the temp file: /tmp/.github.rocketchat-electron.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.rocketchat-electron.update --
Compare current version of an installed Rocket.Chat.Electron and the last available.
EXAMPLE:
- Compare the current version installed from .deb file
check.rocketchat-electron.update
- Compare the current version from apt's repository
check.rocketchat-electron.update repo
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
rkt_repo_url="https://github.com/RocketChat/Rocket.Chat.Electron"
if [ $# -eq 1 ] && [ "${1}" = "repo" ] ## If repository's version should be compared
then
rkt_current_version=$(apt-cache policy rocketchat | awk '/Candidate:/ {print $2}' | sed 's/.:\(.*\)-.*/\1/')
else
rkt_current_version=$(dpkg -l rocketchat | awk '/^ii.*rocketchat/ {print $3}' | sed 's/.:\(.*\)-.*/\1/')
fi
rkt_new_version=$("${script_wd}"/releasetags "${rkt_repo_url}" | head -n1 | sed 's/v//g')
rkt_new_version_file="/tmp/.github.rocketchat-electron.upgrade"
rkt_new_pkg_url="https://github.com/RocketChat/Rocket.Chat.Electron/releases/download/${rkt_new_version}/rocketchat_${rkt_new_version}_amd64.deb"
rkt_tmp_pkg_path="/tmp/.rocketchat_${rkt_new_version}_amd64.deb"
rkt_new_pkg_path="/tmp/rocketchat_${rkt_new_version}_amd64.deb"
# }}}
# Check if the current version is the last one {{{
if [ "${rkt_current_version}" != "${rkt_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${rkt_current_version}) and new one (${rkt_new_version}) seems to be different."
## If it doesn't already exists, download this new package
if [ ! -f "${rkt_new_pkg_path}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Download .deb file from Rocket.Chat.Electron repository on Github to: ${rkt_new_pkg_path} ."
wget --quiet "${rkt_new_pkg_url}" --output-document="${rkt_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 -- "${rkt_new_version_file}" "${rkt_new_pkg_path}" "${rkt_tmp_pkg_path}"
## Exit
exit 0
fi
# }}}
# Verify downloaded package {{{
## If the downloaded package has a size greater than zero {{{
if [ -s "${rkt_new_pkg_path}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Empty file ? — \
Downloaded package looks good."
### Create a temp file to monitor
touch -- "${rkt_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Rocket.Chat client Electron (current: ${rkt_current_version}): ${rkt_new_version}." >> "${rkt_new_version_file}"
### Exit
exit 0
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Empty file ? — \
Empty file, don't need to go further."
### Ensure to remove the file to monitor
rm --force -- "${rkt_new_version_file}"
### Keep a record of the downloaded package because as a new release might come soon
mv --force -- "${rkt_new_pkg_path}" "${rkt_tmp_pkg_path}"
### Exit
exit 0
fi
## }}}
# }}}
exit 255

67
github/check.searx.update Executable file
View File

@ -0,0 +1,67 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Searx
## project on Github.
## It based on the searx's root directory to get the current version and
## supposed to be install from source (github).
## 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 with Searx directory as first argument, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_searx_update /var/www/searx
### 3. Monitor the temp file: /tmp/.github.searx.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect 1 argument {{{
if [ $# -ne 1 ]
then
cat << HELP
check.searx.update --
Compare current version of an installed Searx and the last available.
EXAMPLE:
- Compare the current version installed in /var/www/searx.domain.tld
check.searx.update /var/www/searx.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
searx_install_dir="${1}"
searx_current_version=$(cd "${searx_install_dir}" || exit 1 ; grep "\(VERSION_MAJOR\|VERSION_MINOR\|VERSION_BUILD\) =" searx/version.py | cut -d\= -f2 | sed -e 's/^[[:space:]]*//' | paste -sd "." - ; cd - > /dev/null || exit 1)
searx_repo_url="https://github.com/searx/searx"
searx_new_version=$("${script_wd}"/releasetags "${searx_repo_url}" | head -n1)
searx_new_version_file="/tmp/.github.searx.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${searx_current_version}" != "${searx_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${searx_current_version}) and new one (${searx_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${searx_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Searx (current: ${searx_current_version}): ${searx_new_version}." >> "${searx_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 -- "${searx_new_version_file}"
fi
# }}}
exit 0

View File

@ -0,0 +1,79 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Self Service Password (SSP)
## project on Github.
## It's based on .deb package installation to check the current version.
## It can also be based on installation from source if the self-service-password's
## root 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_self-service-password_update
### 2-1. Create a cron job with Self Service Password (SSP) directory as first argument, eg:
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_self-service-password_update /var/www/self-service-password
### 3. Monitor the temp file: /tmp/.github.self-service-password.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.self-service-password.update --
Compare current version of an installed Self Service Password (SSP) and the last available.
EXAMPLE:
- Compare the current version installed from .deb file
check.self-service-password.update
- Compare the current version installed from sources in /var/www/self-service-password
check.self-service-password.update /var/www/self-service-password
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
ssp_repo_url="https://github.com/ltb-project/self-service-password"
if [ $# -eq 1 ] ## If source directory should be used
then
ssp_install_dir="${1}"
ssp_current_version=$(find "${ssp_install_dir}" -iname index.php -exec grep -- "^\$version" {} \; | cut -d'"' -f2)
ssp_new_version=$("${script_wd}"/releasetags "${ssp_repo_url}" | head -n1)
else ## If .deb file should be used
ssp_current_version=$(dpkg -l self-service-password | awk '/^ii.*self-service-password/ { print $3}' | sed 's/\(.*\)-.*/\1/')
ssp_new_version=$("${script_wd}"/releasetags "${ssp_repo_url}" | head -n1 | sed 's/v//g')
fi
ssp_new_version_file="/tmp/.github.self-service-password.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${ssp_current_version}" != "${ssp_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${ssp_current_version}) and new one (${ssp_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${ssp_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Self Service Password/SSP (current: ${ssp_current_version}): ${ssp_new_version}." >> "${ssp_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 -- "${ssp_new_version_file}"
fi
# }}}
exit 0

68
github/check.shaarli.update Executable file
View File

@ -0,0 +1,68 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Shaarli
## project on Github.
## It based on shaarli's binary available in $PATH or give 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_shaarli_update
### 2-1 Create a cron job with a specific path for Shaarli bin, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_shaarli_update /var/www/shaarli.domain.tld
### 3. Monitor the temp file: /tmp/.github.shaarli.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect 1 argument {{{
if [ $# -ne 1 ]
then
cat << HELP
check.shaarli.update --
Compare current version of an installed Shaarli and the last available.
EXAMPLE:
- Compare the current version installed in /var/www/shaarli.domain.tld
check.shaarli.update /var/www/shaarli.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
shaarli_install_dir="${1}"
shaarli_current_version=$(cd "${shaarli_install_dir}" || exit 1 ; grep . -m1 shaarli_version.php | cut -d" " -f3 ; cd - > /dev/null || exit 1)
shaarli_repo_url="https://github.com/shaarli/Shaarli"
shaarli_new_version=$("${script_wd}"/releasetags "${shaarli_repo_url}" | grep -vE -- '(beta)' | head -n1 | sed 's/v//')
shaarli_new_version_file="/tmp/.github.shaarli.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${shaarli_current_version}" != "${shaarli_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${shaarli_current_version}) and new one (${shaarli_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${shaarli_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Shaarli (current: ${shaarli_current_version}): ${shaarli_new_version}." >> "${shaarli_new_version_file}"
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current (${shaarli_current_version}) version is up-to-date."
rm -f -- "${shaarli_new_version_file}"
fi
# }}}
exit 0

View File

@ -8,7 +8,7 @@
### cf. https://git.101010.fr/gardouille-dotfiles/scripts/github/releasetags
# wget https://git.101010.fr/gardouille-dotfiles/scripts/raw/branch/master/github/releasetags
### 2. Create a cron job with Sickchill URL as first argument, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check_sickchill_update http://sickchill.domain.tld:port/System/Info/Public
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_sickchill_update http://sickchill.domain.tld:port/System/Info/Public
### 3. Monitor the temp file: /tmp/.github.sickchill.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.

View File

@ -0,0 +1,354 @@
#!/bin/sh
#
# Purpose {{{
# This script will try to get last version of teams-for-linux .deb file
# https://github.com/IsmaelMartinez/teams-for-linux
# 1. Get current version from APT repo (by default).
# 1.b Or use version from manually installed package (with --file option).
# 2. Get latest version from github repository.
# 3. Compare current and new versions.
# 4. Download the .deb file for this new version.
# 5. Create a temp file (to monitor) if an upgrade is available.
#
# 2023-03-04
# }}}
# 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.teams-for-linux.update
## 2-1 Create a cron job to compare the version of manually installed package
#00 20 * * * root /opt/repos/gardouille.scripts/github/check.teams-for-linux.update --file
## 3. Monitor the temp file: /tmp/.github.teams-for-linux.upgrade
# }}}
# Flags {{{
## Exit on error
set -o errexit
## Exit on unset var
### Use "${VARNAME-}" to test a var that may not have been set
set -o nounset
## Pipeline command is treated as failed
### Not available in POSIX sh https://github.com/koalaman/shellcheck/wiki/SC3040
#set -o pipefail
## Help with debugging
### Call the script by prefixing it with "TRACE=1 ./script.sh"
if [ "${TRACE-0}" -eq 1 ]; then set -o xtrace; fi
# }}}
# Vars {{{
PROGNAME=$(basename "${0}"); readonly PROGNAME
PROGDIR=$(readlink --canonicalize-missing $(dirname "${0}")); readonly PROGDIR
ARGS="${*}"; readonly ARGS
readonly NBARGS="${#}"
[ -z "${DEBUG-}" ] && DEBUG=1
## Export DEBUG for sub-script
export DEBUG
## Default values for some vars
readonly PACKAGE_NAME_DEFAULT="teams-for-linux"
readonly CHECK_MODE_DEFAULT="repository"
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
cat <<- HELP
usage: $PROGNAME [-d|-h]
Try to get last version of ${PACKAGE_NAME_DEFAULT} .deb file.
EXAMPLES:
- Check ${PACKAGE_NAME_DEFAULT} version (from APT repository or manually installed file).
${PROGNAME}
OPTIONS:
-d,--debug
Enable debug messages.
-h,--help
Print this help message.
HELP
}
# }}}
debug_message() { # {{{
local_debug_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_debug_message}"
unset local_debug_message
return 0
}
# }}}
error_message() { # {{{
local_error_message="${1}"
local_error_code="${2}"
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}" >&2
unset local_error_message
exit "${local_error_code:=66}"
}
# }}}
is_var_empty() { # {{{
local_var_empty="${1}"
debug_prefix="${2:-}"
## Return False by default
return_var_empty="1"
debug_message "${debug_prefix}is_var_empty Test var value (${1})."
[ -z "${local_var_empty}" ] && return_var_empty="0"
unset debug_prefix
unset local_var_empty
return "${return_var_empty}"
}
# }}}
define_vars() { # {{{
debug_message "-- define_vars BEGIN"
## If repo_url wasn't defined {{{
is_var_empty "${repo_url-}" "|| " \
&& repo_url="https://github.com/IsmaelMartinez/teams-for-linux" \
&& debug_message "| define_vars Use value (${RED}${repo_url}${COLOR_DEBUG}) for repo_url variable."
## }}}
## If package_name wasn't defined (argument) {{{
## Use default value
is_var_empty "${package_name-}" "|| " \
&& debug_message "| define_vars Use default value (${RED}${PACKAGE_NAME_DEFAULT}${COLOR_DEBUG}) for package_name variable." \
&& package_name="${PACKAGE_NAME_DEFAULT}"
## }}}
## Get new_version from application repository {{{
new_version=$("${PROGDIR}"/releasetags "${repo_url}" | grep -vE -- '(dev|rc)' | head -n1 | sed 's/v//g')
if is_var_empty "${new_version-}" "|| "; then
error_message "define_vars Invalid value for ${package_name} new version (${new_version})." 1
else
debug_message "| define_vars Get value (${RED}${new_version}${COLOR_DEBUG}) for new_version variable."
fi
## }}}
## If new_package_filename wasn't defined {{{
is_var_empty "${new_package_filename-}" "|| " \
&& new_package_filename="${package_name}_${new_version}_amd64.deb" \
&& debug_message "| define_vars Use value (${RED}${new_package_filename}${COLOR_DEBUG}) for new_package_filename variable."
## }}}
## If new_package_url wasn't defined {{{
is_var_empty "${new_package_url-}" "|| " \
&& new_package_url="${repo_url}/releases/download/v${new_version}/${new_package_filename}" \
&& debug_message "| define_vars Use value (${RED}${new_package_url}${COLOR_DEBUG}) for new_package_url variable."
## }}}
## If new_version_file wasn't defined {{{
is_var_empty "${new_version_file-}" "|| " \
&& new_version_file="/tmp/.github.${package_name}.upgrade" \
&& debug_message "| define_vars Use value (${RED}${new_version_file}${COLOR_DEBUG}) for new_version_file variable."
## }}}
## If tmp_package_path wasn't defined {{{
is_var_empty "${tmp_package_path-}" "|| " \
&& tmp_package_path="/tmp/.${new_package_filename}" \
&& debug_message "| define_vars Use value (${RED}${tmp_package_path}${COLOR_DEBUG}) for tmp_package_path variable."
## }}}
## If new_package_path wasn't defined {{{
is_var_empty "${new_package_path-}" "|| " \
&& new_package_path="/tmp/${new_package_filename}" \
&& debug_message "| define_vars Use value (${RED}${new_package_path}${COLOR_DEBUG}) for new_package_path variable."
## }}}
## If check_mode wasn't defined (argument) {{{
## Use default value
is_var_empty "${check_mode-}" "|| " \
&& debug_message "| define_vars Use default value (${RED}${CHECK_MODE_DEFAULT}${COLOR_DEBUG}) for check_mode variable." \
&& check_mode="${CHECK_MODE_DEFAULT}"
## }}}
## Get current_version according to the check_mode {{{
case "${check_mode}" in
"repo"|"repository" ) ## Check current version from repository
current_version=$(apt-cache policy -- "${package_name}" | awk '/Candidate:/ {print $2}' | sed 's/.:\(.*\)-.*/\1/')
;;
"file" ) ## Check current version from installed .deb file
current_version=$(dpkg --list -- "${package_name}" | awk -v pattern="${package_name}" '$0~pattern {print $3}' | sed 's/.:\(.*\)-.*/\1/')
;;
* ) ## unknow mode
error_message "define_vars Invalid check mode: ${check_mode}. See help message with -h." 2
;;
esac
## If current_version is empty
is_var_empty "${current_version}" "|| " \
&& error_message "define_vars Error with current_version variable (${current_version}) for package (${package_name})." 2
## }}}
debug_message "-- define_vars END"
}
# }}}
is_version_greater_than() { # {{{
first_value="${1}"
value_to_compare="${2}"
debug_prefix="${3:-}"
## Return False by default
return_is_version_greater_than="1"
debug_message "${debug_prefix}is_version_greater_than \
Is first value (${first_value}) greater than the second value (${value_to_compare})."
if printf '%s\n' "${first_value}" "${value_to_compare}" | sort --check=quiet --version-sort; then
debug_message "${debug_prefix}is_version_greater_than ${first_value} <= ${value_to_compare} ."
return_is_version_greater_than="1"
else
debug_message "${debug_prefix}is_version_greater_than ${first_value} > ${value_to_compare} ."
return_is_version_greater_than="0"
fi
unset first_value
unset value_to_compare
unset debug_prefix
return "${return_is_version_greater_than}"
}
# }}}
main() { # {{{
debug_message "--- MAIN BEGIN"
## Define all vars
define_vars
## Uncomment variable(s) to simulate different behaviour
#current_version="1.0.2"
#new_version="42.3.1"
debug_message "-- Test version BEGIN"
## If new_version is greater than current_version {{{
if is_version_greater_than "${new_version}" "${current_version}" "|| "; then
debug_message "| Current version (${current_version}) is older than new one \
(${new_version})."
### If it doesn't already exists, download the new package {{{
if [ ! -f "${new_package_path}" ]; then
debug_message "| Download .deb file from ${package_name} repository on Github to: ${new_package_path} ."
wget --quiet "${new_package_url}" --output-document="${new_package_path}"
fi
### }}}
## }}}
## If current version is uptodate {{{
else
debug_message "| Current version (${current_version}) seems uptodate \
or newer than available version (${new_version})."
### Ensure to remove any temp file and useless .deb files
rm --force -- "${new_version_file}" "${new_package_path}" "${tmp_package_path}"
### Exit
debug_message "-- Test version END"
debug_message "--- MAIN END"
exit 0
fi
## }}}
debug_message "-- Test version END"
## Verify downloaded package {{{
debug_message "-- Verify downloaded package BEGIN"
## If the downloaded package has a size greater than zero {{{
if [ -s "${new_package_path}" ]; then
debug_message "| Downloaded package looks good."
### Create a temp file to monitor
touch -- "${new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for ${package_name} terminal (current: ${current_version}): ${new_version}." >> "${new_version_file}"
## }}}
## If the size is null {{{
else
debug_message "| Empty file, don't need to go further."
### Ensure to remove the file to monitor
rm --force -- "${new_version_file}"
### Keep a record of the downloaded package because as a new release might come soon
mv --force -- "${new_package_path}" "${tmp_package_path}"
fi
## }}}
debug_message "-- Verify downloaded package END"
# }}}
debug_message "--- MAIN END"
# Exit
exit 0
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to argument management
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument ask for help (h|help|-h|-help|-*h|-*help) {{{
if printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-*h(elp)?$"; then
usage
exit 0
fi
## }}}
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep --quiet --extended-regexp -- "^-+";
then
## Print help message and exit
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-+"; do
case "${1}" in
-d|--debug ) ## debug
DEBUG=0
debug_message "--- Manage argument BEGIN"
;;
-f|--file|--files|-p|--package ) ## Define check_mode to file mode
## Define var
readonly check_mode="file"
;;
--repo|--repository ) ## Define check_mode to repo mode
## Define var
readonly check_mode="repo"
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "| ${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "| ${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "| No arguments/options to manage."
fi
debug_message "--- Manage argument END"
# }}}
main
# This should never be reach
exit 255

79
github/check.vaultwarden.update Executable file
View File

@ -0,0 +1,79 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Vaultwarden
## (previously Bitwarden_rs) project on Github.
## It based on /opt/vaultwarden/vaultwarden binary available or the one give
## 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_vaultwarden_update
### 2-1 Create a cron job with a specific path for vaultwarden bin, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_vaultwarden_update /srv/bin/vaultwarden
### 3. Monitor the temp file: /tmp/.github.vaultwarden.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect max 1 argument {{{
if [ $# -gt 1 ]
then
cat << HELP
check.vaultwarden.update --
Compare current version of an installed Vaultwarden and the last available.
EXAMPLE:
- Compare the current version of Vaultwarden with bin available in
/opt/vaultwarden/vaultwarden
check.vaultwarden.update
- Compare the current version of Vaultwarden at a specific place
check.vaultwarden.update /srv/bin/vaultwarden
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
if [ $# -eq 1 ] ## If an argument was gave
then
vaultwarden_bin_path="${1}"
else
vaultwarden_bin_path="/opt/vaultwarden/vaultwarden"
fi
vaultwarden_current_version=$("${vaultwarden_bin_path}" --version | sed 's/vaultwarden \(\([0-9]\{1,3\}\.\)\{2\}\([0-9]\{1,3\}\)\).*/\1/')
vaultwarden_repo_url="https://github.com/dani-garcia/vaultwarden"
vaultwarden_new_version=$("${script_wd}"/releasetags "${vaultwarden_repo_url}" | grep -vE -- '(dev|rc)' | head -n1)
vaultwarden_new_version_file="/tmp/.github.vaultwarden.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${vaultwarden_current_version}" != "${vaultwarden_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${vaultwarden_current_version}) and new one (${vaultwarden_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${vaultwarden_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Vaultwarden (current: ${vaultwarden_current_version}): ${vaultwarden_new_version}." >> "${vaultwarden_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 -- "${vaultwarden_new_version_file}"
fi
# }}}
exit 0

67
github/check.wallabag.update Executable file
View File

@ -0,0 +1,67 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Wallabag
## project on Github.
## It based on the wallabag's root directory to get the current version and
## supposed to be install from source (github).
## 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 with Wallabag directory as first argument, eg.
#00 20 * * * root /opt/repos/gardouille.scripts/github/check_wallabag_update /var/www/wallabag
### 3. Monitor the temp file: /tmp/.github.wallabag.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect 1 argument {{{
if [ $# -ne 1 ]
then
cat << HELP
check.wallabag.update --
Compare current version of an installed Wallabag and the last available.
EXAMPLE:
- Compare the current version installed in /var/www/bag.domain.tld
check.wallabag.update /var/www/bag.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
wb_install_dir="${1}"
wb_current_version=$(cd "${wb_install_dir}" || exit 1 ; git status | head -n1 | cut -d" " -f4 ; cd - > /dev/null || exit 1)
wb_repo_url="https://github.com/wallabag/wallabag"
wb_new_version=$("${script_wd}"/releasetags "${wb_repo_url}" | head -n1)
wb_new_version_file="/tmp/.github.wallabag.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${wb_current_version}" != "${wb_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${wb_current_version}) and new one (${wb_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${wb_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Wallabag (current: ${wb_current_version}): ${wb_new_version}." >> "${wb_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 -- "${wb_new_version_file}"
fi
# }}}
exit 0