Skip to content

Instantly share code, notes, and snippets.

@slomo
Created January 31, 2012 13:27
Show Gist options
  • Save slomo/1710461 to your computer and use it in GitHub Desktop.
Save slomo/1710461 to your computer and use it in GitHub Desktop.
apticron for arch
#!/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
@thepaffy
Copy link

thepaffy commented Jan 9, 2017

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment