| 1 |
#!/bin/bash |
| 2 |
# Copyright (C) 2008 Richard Hughes <[email protected]> |
| 3 |
# |
| 4 |
# Some material taken from yum-cron, Copyright 2007 Alec Habig <[email protected]> |
| 5 |
# |
| 6 |
# Licensed under the GNU General Public License Version 2 |
| 7 |
# This program is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 2 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
|
| 12 |
[ -f /etc/sysconfig/packagekit-background ] && . /etc/sysconfig/packagekit-background |
| 13 |
|
| 14 |
# are we disabled? |
| 15 |
if [ "$ENABLED" = "no" ]; then |
| 16 |
exit 0 |
| 17 |
fi |
| 18 |
|
| 19 |
# set default for SYSTEM_NAME |
| 20 |
[ -z "$SYSTEM_NAME" ] && SYSTEM_NAME=$(hostname) |
| 21 |
|
| 22 |
PKTMP=$(mktemp /var/run/packagekit-cron.XXXXXX) |
| 23 |
PKGCLI_OPTIONS="--background --yes --no-color --quiet" |
| 24 |
|
| 25 |
# wait a random amount of time to avoid hammering the servers |
| 26 |
[ -z "$SLEEP_MAX" ] && SLEEP_MAX=$RANDOM |
| 27 |
sleep $(( $RANDOM % $SLEEP_MAX + 1 )) |
| 28 |
|
| 29 |
# do action |
| 30 |
if [ "$CHECK_ONLY" = "yes" ]; then |
| 31 |
pkgcli $PKGCLI_OPTIONS list-updates &> $PKTMP |
| 32 |
PKGCLI_RETVAL=$? |
| 33 |
else |
| 34 |
if [ "$UPDATE_OFFLINE" = "yes" ]; then |
| 35 |
pkgcli $PKGCLI_OPTIONS offline-update &>> $PKTMP |
| 36 |
PKGCLI_RETVAL=$? |
| 37 |
else |
| 38 |
pkgcli $PKGCLI_OPTIONS update &> $PKTMP |
| 39 |
PKGCLI_RETVAL=$? |
| 40 |
fi |
| 41 |
fi |
| 42 |
|
| 43 |
# this is when something useful was done |
| 44 |
if [ $PKGCLI_RETVAL -ne 5 ]; then |
| 45 |
# send email |
| 46 |
if [ -n "$MAILTO" ]; then |
| 47 |
mail -s "System updates available: $SYSTEM_NAME" $MAILTO < $PKTMP |
| 48 |
else |
| 49 |
# default behavior is to use cron's internal mailing of output from cron-script |
| 50 |
cat $PKTMP |
| 51 |
fi |
| 52 |
fi |
| 53 |
|
| 54 |
rm -f $PKTMP |