You are here: Home / Debian GNU/Linux / Servers / PHP / Setup a email alert for PEAR upgrades

Setup a email alert for PEAR upgrades

by Pierre-Yves Landuré last modified Jul 11, 2013 05:56

PEAR (for PHP Extension and Application Repository) is a PHP libraries collection. It is also a tool that allow to manage these libraries. The first rule of system security is to keep the system up to date. This howto help you to setup a email alert when upgrades are available on the system via PEAR.

This howto is tested on:

  • Debian 6.0 Squeeze
  • Debian 7.0 Wheezy

Setup

Installing PEAR

Install the PEAR package:

command apt-get install php-pear

Upgrade the PEAR core a first time:

pear channel-update pear.php.net
pear upgrade PEAR

Upgrade PECL:

command pecl channel-update pecl.php.net
command pecl upgrade

Setting up the upgrade check

Create a cron script to daily check for PEAR upgrades:

command echo '#!/bin/bash

command test -x "/usr/bin/pear" || exit 1

MAILNAME=$(command hostname --fqdn)

# Check for channels updates
command pear update-channels 2>&1 > "/dev/null"
command pecl update-channels 2>&1 > "/dev/null"

# Check for upgrades
PEAR_UPGRADES=$(command pear list-upgrades \
| command egrep -v "No upgrades available")

if [ -n "${PEAR_UPGRADES}" ]; then
echo "New PEAR ugprades available:
${PEAR_UPGRADES}

Upgrade ${MAILNAME} PEAR install with:

command pear upgrade

Upgrade ${MAILNAME} PECL install with:

command pecl upgrade

" | mail -s "[${MAILNAME}] PEAR upgrades available" "root"
fi' \
> '/etc/cron.daily/pear-upgrades'
command chmod +x '/etc/cron.daily/pear-upgrades'

When new PEAR upgrades are available, a e-mail alert is sent to the root user. Make sure that you receive the system emails.

The upgrades need an action from the system administrator because a human hand can be needed if the upgrade break dependencies.

Thanks

  • Thanks to PEAR developers.