system-helpers/usr/local/bin/check_updates

67 lines
1.2 KiB
Text
Raw Normal View History

2019-01-25 17:28:29 +00:00
#!/usr/bin/env bash
# usage
usage() {
USAGE=$(cat <<EOF
2019-01-25 17:52:06 +00:00
Usage: check_updates [CONFIG_FILE (absolute path)]
2019-01-25 17:28:29 +00:00
Sends out update notifications. Please see man check_updates.
2019-01-25 17:28:29 +00:00
EOF
)
echo "$USAGE";
}
set -e;
HOSTNAME=$(hostname)
UPDATES=$(/usr/bin/checkupdates)
UPDATES_AMOUNT=$(/usr/bin/checkupdates|wc -l)
2019-01-25 17:52:06 +00:00
CHECK_UPDATES_MAIL_ADDRESS="";
2019-01-25 17:28:29 +00:00
# check for config file
2022-07-10 16:29:44 +00:00
apply_config() {
local config=$1;
if [[ ! -f "$config" ]]; then
echo "No config file specified";
echo "";
usage;
exit 1;
fi
set -a;
# shellcheck disable=SC1090
2022-07-10 16:29:44 +00:00
source "$config";
set +a;
}
2019-01-25 17:28:29 +00:00
source_config() {
2022-07-10 16:29:44 +00:00
local config=$1;
local configFallback=$2;
local configGlobalFallback=$3;
if [[ -f "$config" ]]; then
apply_config "$config";
2022-07-10 16:33:00 +00:00
return;
2022-07-10 16:29:44 +00:00
fi
if [[ -f "$configFallback" ]]; then
apply_config "$configFallback";
2022-07-10 16:33:00 +00:00
return;
2022-07-10 16:29:44 +00:00
fi
if [[ -f "$configGlobalFallback" ]]; then
apply_config "$configGlobalFallback";
2022-07-10 16:33:00 +00:00
return;
2022-07-10 16:29:44 +00:00
fi
2019-01-25 17:28:29 +00:00
}
2022-07-10 16:29:44 +00:00
source_config "$1" "$HOME/.check_updates.conf" "/etc/check_updates.conf"
2019-01-25 17:28:29 +00:00
if [ "$UPDATES_AMOUNT" -gt "0" ]; then
mailx -s "[updates $HOSTNAME]" "$CHECK_UPDATES_MAIL_ADDRESS" << EOF
2019-01-25 17:28:29 +00:00
There are $UPDATES_AMOUNT updates available on $HOSTNAME.
$UPDATES
EOF
fi