2010-05-05 11:42:48 -07:00
|
|
|
#!/bin/bash
|
2008-03-04 03:08:16 -08:00
|
|
|
# Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
|
|
|
|
#
|
|
|
|
# Some material taken from yum-cron, Copyright 2007 Alec Habig <ahabig@umn.edu>
|
|
|
|
#
|
|
|
|
# Licensed under the GNU General Public License Version 2
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
[ -f /etc/sysconfig/packagekit-background ] && . /etc/sysconfig/packagekit-background
|
|
|
|
|
2008-03-16 11:46:03 -07:00
|
|
|
# are we disabled?
|
2009-06-05 03:56:42 -07:00
|
|
|
if [ "$ENABLED" = "no" ]; then
|
2008-03-16 11:46:03 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-05-05 11:41:23 -07:00
|
|
|
# set default for SYSTEM_NAME
|
|
|
|
[ -z "$SYSTEM_NAME" ] && SYSTEM_NAME=$(hostname)
|
2008-03-04 03:08:16 -08:00
|
|
|
|
|
|
|
PKTMP=$(mktemp /var/run/packagekit-cron.XXXXXX)
|
2009-11-24 08:22:43 -08:00
|
|
|
PKCON_OPTIONS="--background --noninteractive --plain"
|
2008-03-04 03:08:16 -08:00
|
|
|
|
2008-03-04 08:42:34 -08:00
|
|
|
# wait a random amount of time to avoid hammering the servers
|
2010-05-05 11:42:48 -07:00
|
|
|
[ -z "$SLEEP_MAX" ] && SLEEP_MAX=$RANDOM
|
|
|
|
sleep $(( $RANDOM % $SLEEP_MAX + 1 ))
|
2008-03-04 08:42:34 -08:00
|
|
|
|
2008-03-04 03:08:16 -08:00
|
|
|
# do action
|
2009-06-05 03:56:42 -07:00
|
|
|
if [ "$CHECK_ONLY" = "yes" ]; then
|
2009-11-24 08:22:43 -08:00
|
|
|
pkcon $PKCON_OPTIONS get-updates &> $PKTMP
|
|
|
|
PKCON_RETVAL=$?
|
2008-03-04 03:08:16 -08:00
|
|
|
else
|
2009-11-24 08:22:43 -08:00
|
|
|
pkcon $PKCON_OPTIONS update &> $PKTMP
|
|
|
|
PKCON_RETVAL=$?
|
2008-03-04 03:08:16 -08:00
|
|
|
fi
|
|
|
|
|
2009-11-24 08:22:43 -08:00
|
|
|
# this is when seomthing useful was done
|
|
|
|
if [ $PKCON_RETVAL -ne 5 ]; then
|
|
|
|
# send email
|
|
|
|
if [ -n "$MAILTO" ]; then
|
2010-05-05 11:41:23 -07:00
|
|
|
mail -s "System updates available: $SYSTEM_NAME" $MAILTO < $PKTMP
|
2009-11-24 08:22:43 -08:00
|
|
|
else
|
|
|
|
# default behavior is to use cron's internal mailing of output from cron-script
|
|
|
|
cat $PKTMP
|
|
|
|
fi
|
2008-03-04 03:08:16 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f $PKTMP
|
|
|
|
|