gentoo-auto-update/check_updates.sh

58 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2018-04-08 17:28:42 +02:00
#!/bin/sh
PATH="$PATH:/usr/sbin:/sbin"
TMP_FILE=$(mktemp)
MAIL=$(mktemp)
2024-04-22 10:23:03 +02:00
# Possible race condition: if someone runs `eix blah` at the exact same time,
# it will block the update. But that seems highly improbable.
# The mail goal is to avoid stacking updates or eix-sync/eix-updates
PORTAGE_RUNING=$(pgrep 'emerge|eix')
if [ "${PORTAGE_RUNING}" ]; then
echo "Error: another emerge is already running, exiting"
exit 1
fi
2018-04-08 17:28:42 +02:00
PORTAGE_QUIET='1'
2024-04-22 10:23:03 +02:00
eix-sync 1>/dev/null 2>${TMP_FILE} || eix-update 1>/dev/null 2>${TMP_FILE}
2018-04-08 17:28:42 +02:00
emerge -v --update --newuse --deep --with-bdeps=y --quiet-build=y @security \
&>> ${TMP_FILE}
emerge -v --update --newuse --deep --with-bdeps=y --quiet-build=y @system \
&>> ${TMP_FILE}
emerge -v --update --newuse --deep --with-bdeps=y --quiet-build=y @unavailable
&>> ${TMP_FILE}
2018-04-10 09:09:53 +02:00
emerge -v --update --newuse --deep --with-bdeps=y --quiet-build=y @world \
2018-04-08 17:28:42 +02:00
&>> ${TMP_FILE}
if [ "$(grep '\[ebuild U' ${TMP_FILE})" != '' ]; then
echo "From: $(whoami)@$(hostname -f)" > ${MAIL}
echo "To: root@$(hostname -f)" >> ${MAIL}
echo "Subject: $(hostname -f):$(grep Total: ${TMP_FILE} \
| cut -d ':' -f 2 | cut -d ')' -f 1))" >> ${MAIL}
echo "Content-Type: text/plain; charset=UTF-8" >> ${MAIL}
2018-05-22 00:54:59 +02:00
echo "Date: $(date --rfc-email)" >> ${MAIL}
printf "\n" >> ${MAIL}
2018-04-08 17:28:42 +02:00
cat ${TMP_FILE} >> ${MAIL}
if [ "$(lsof -n | awk '{ if ($6 == "DEL") print $9 }' | sort -u)" ]; then
restart-services --no-color >> ${MAIL}
2018-04-08 17:28:42 +02:00
fi
2018-05-15 10:07:32 +02:00
if ! [ -z "$(grep -v '{}' /var/lib/portage/preserved_libs_registry)" ]; then
emerge -v --quiet-build=y @preserved-rebuild >> ${MAIL}
2018-05-15 10:07:32 +02:00
fi
2018-04-08 17:28:42 +02:00
emerge -p --depclean --with-bdeps\=y >> ${MAIL}
2018-04-27 10:33:12 +02:00
eix-test-obsolete \
| grep -Pv '^No|^Skipping|[Aa]ll.*packages are in the database' \
>> ${MAIL}
2018-04-08 17:28:42 +02:00
cat ${MAIL} | sendmail -t root@$(hostname -f)
fi
rm ${TMP_FILE} ${MAIL}