Created
January 31, 2012 13:27
-
-
Save slomo/1710461 to your computer and use it in GitHub Desktop.
apticron for arch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# copy this file to /usr/local/sbin (or any other $PATH location) | |
# add to daily.cron | |
VAR_FILE="/var/lib/pacicron/sha" | |
MAIL_TO="root" | |
HOST=$(uname -n) | |
if [[ ! -f ${VAR_FILE} ]]; then | |
echo "${VAR_FILE} doesn't exits. Therefore creating." | |
mkdir $(dirname ${VAR_FILE}) | |
touch ${VAR_FILE} | |
else | |
echo "Using hash from ${VAR_FILE}." | |
fi | |
# syncs and downloads all packages, without asking | |
pacman -Swuy --noconfirm | |
SHA_NEW=$(pacman -Qu | sha1sum | cut -d" " -f1) | |
SHA_OLD=$(cat ${VAR_FILE}) | |
if [[ ${SHA_NEW} != ${SHA_OLD} ]]; then | |
MSG="Following packages would be installed:\n\r\n\r$(pacman -Qu)\r\n\r\nSincerly yours pacicron\r\n" | |
echo -e ${MSG} | mail -s "New updates avaible on ${HOST}" ${MAIL} | |
echo ${SHA_NEW} > ${VAR_FILE} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
i found a bug in your script.
It should be
echo -e ${MSG} | mail -s "New updates avaible on ${HOST}" ${MAIL_TO}
not
echo -e ${MSG} | mail -s "New updates avaible on ${HOST}" ${MAIL}