forked from alarig/gentoo-auto-update
Compare commits
No commits in common. "master" and "master" have entirely different histories.
1 changed files with 15 additions and 45 deletions
|
@ -1,32 +1,9 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
|
||||||
# check_updates.sh
|
|
||||||
# $1 - message transport agent, either sendmail or gotify, default to sendmail
|
|
||||||
#
|
|
||||||
|
|
||||||
PATH="$PATH:/usr/sbin:/sbin"
|
PATH="$PATH:/usr/sbin:/sbin"
|
||||||
|
|
||||||
TMP_FILE=$(mktemp)
|
TMP_FILE=$(mktemp)
|
||||||
MESSAGE=$(mktemp)
|
MAIL=$(mktemp)
|
||||||
MESSAGE_IS_MAIL=1
|
|
||||||
|
|
||||||
# message transport agent, either sendmail or gotify
|
|
||||||
# if you use gotify, you need to install gotify-cli
|
|
||||||
MTA=${1:-sendmail}
|
|
||||||
case "${MTA}" in
|
|
||||||
sendmail)
|
|
||||||
MTA='sendmail -t root@$(hostname -f)'
|
|
||||||
;;
|
|
||||||
gotify)
|
|
||||||
MTA='gotify p -q -t $TITLE'
|
|
||||||
MESSAGE_IS_MAIL=0
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Error: unknown MTA"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Possible race condition: if someone runs `eix blah` at the exact same time,
|
# Possible race condition: if someone runs `eix blah` at the exact same time,
|
||||||
# it will block the update. But that seems highly improbable.
|
# it will block the update. But that seems highly improbable.
|
||||||
|
@ -51,37 +28,30 @@ emerge -v --update --newuse --deep --with-bdeps=y --quiet-build=y @world \
|
||||||
&>> ${TMP_FILE}
|
&>> ${TMP_FILE}
|
||||||
|
|
||||||
if [ "$(grep '\[ebuild U' ${TMP_FILE})" != '' ]; then
|
if [ "$(grep '\[ebuild U' ${TMP_FILE})" != '' ]; then
|
||||||
if [ ${MESSAGE_IS_MAIL} -eq 1 ]; then
|
echo "From: $(whoami)@$(hostname -f)" > ${MAIL}
|
||||||
# The message is a mail we add corresponding headers
|
echo "To: root@$(hostname -f)" >> ${MAIL}
|
||||||
echo "From: $(whoami)@$(hostname -f)" > ${MESSAGE}
|
echo "Subject: $(hostname -f):$(grep Total: ${TMP_FILE} \
|
||||||
echo "To: root@$(hostname -f)" >> ${MESSAGE}
|
| cut -d ':' -f 2 | cut -d ')' -f 1))" >> ${MAIL}
|
||||||
echo "Subject: $(hostname -f):$(grep Total: ${TMP_FILE} \
|
echo "Content-Type: text/plain; charset=UTF-8" >> ${MAIL}
|
||||||
| cut -d ':' -f 2 | cut -d ')' -f 1))" >> ${MESSAGE}
|
echo "Date: $(date --rfc-email)" >> ${MAIL}
|
||||||
echo "Content-Type: text/plain; charset=UTF-8" >> ${MESSAGE}
|
printf "\n" >> ${MAIL}
|
||||||
echo "Date: $(date --rfc-email)" >> ${MESSAGE}
|
cat ${TMP_FILE} >> ${MAIL}
|
||||||
printf "\n" >> ${MESSAGE}
|
|
||||||
else
|
|
||||||
TITLE = "$(hostname -f):$(grep Total: ${TMP_FILE} \
|
|
||||||
| cut -d ':' -f 2 | cut -d ')' -f 1)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat ${TMP_FILE} >> ${MESSAGE}
|
|
||||||
|
|
||||||
if [ "$(lsof -n | awk '{ if ($6 == "DEL") print $9 }' | sort -u)" ]; then
|
if [ "$(lsof -n | awk '{ if ($6 == "DEL") print $9 }' | sort -u)" ]; then
|
||||||
restart-services --no-color >> ${MESSAGE}
|
restart-services --no-color >> ${MAIL}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -z "$(grep -v '{}' /var/lib/portage/preserved_libs_registry)" ]; then
|
if ! [ -z "$(grep -v '{}' /var/lib/portage/preserved_libs_registry)" ]; then
|
||||||
emerge -v --quiet-build=y @preserved-rebuild >> ${MESSAGE}
|
emerge -v --quiet-build=y @preserved-rebuild >> ${MAIL}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
emerge -p --depclean --with-bdeps\=y >> ${MESSAGE}
|
emerge -p --depclean --with-bdeps\=y >> ${MAIL}
|
||||||
|
|
||||||
eix-test-obsolete \
|
eix-test-obsolete \
|
||||||
| grep -Pv '^No|^Skipping|[Aa]ll.*packages are in the database' \
|
| grep -Pv '^No|^Skipping|[Aa]ll.*packages are in the database' \
|
||||||
>> ${MESSAGE}
|
>> ${MAIL}
|
||||||
|
|
||||||
eval "${MTA}" < "${MESSAGE}"
|
cat ${MAIL} | sendmail -t root@$(hostname -f)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm ${TMP_FILE} ${MESSAGE}
|
rm ${TMP_FILE} ${MAIL}
|
||||||
|
|
Loading…
Reference in a new issue