Alexander Schäferdiek
dde06a6da3
All checks were successful
continuous-integration/drone/push Build is passing
66 lines
1.2 KiB
Bash
Executable file
66 lines
1.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# usage
|
|
usage() {
|
|
USAGE=$(cat <<EOF
|
|
Usage: check_updates [CONFIG_FILE (absolute path)]
|
|
|
|
Sends out update notifications. Please see man check_updates.
|
|
EOF
|
|
)
|
|
echo "$USAGE";
|
|
}
|
|
|
|
set -e;
|
|
|
|
HOSTNAME=$(hostname)
|
|
UPDATES=$(/usr/bin/checkupdates)
|
|
UPDATES_AMOUNT=$(/usr/bin/checkupdates|wc -l)
|
|
CHECK_UPDATES_MAIL_ADDRESS="";
|
|
|
|
# check for config file
|
|
apply_config() {
|
|
local config=$1;
|
|
|
|
if [[ ! -f "$config" ]]; then
|
|
echo "No config file specified";
|
|
echo "";
|
|
usage;
|
|
exit 1;
|
|
fi
|
|
|
|
set -a;
|
|
# shellcheck disable=SC1090
|
|
source "$config";
|
|
set +a;
|
|
}
|
|
|
|
source_config() {
|
|
local config=$1;
|
|
local configFallback=$2;
|
|
local configGlobalFallback=$3;
|
|
|
|
if [[ -f "$config" ]]; then
|
|
apply_config "$config";
|
|
return;
|
|
fi
|
|
|
|
if [[ -f "$configFallback" ]]; then
|
|
apply_config "$configFallback";
|
|
return;
|
|
fi
|
|
|
|
if [[ -f "$configGlobalFallback" ]]; then
|
|
apply_config "$configGlobalFallback";
|
|
return;
|
|
fi
|
|
}
|
|
source_config "$1" "$HOME/.check_updates.conf" "/etc/check_updates.conf"
|
|
|
|
if [ "$UPDATES_AMOUNT" -gt "0" ]; then
|
|
mailx -s "[updates $HOSTNAME]" "$CHECK_UPDATES_MAIL_ADDRESS" << EOF
|
|
There are $UPDATES_AMOUNT updates available on $HOSTNAME.
|
|
|
|
$UPDATES
|
|
EOF
|
|
fi
|