Gund is a script that should be run by cron on a daily basis to check for updates to a Gentoo system. It syncs the portage tree checks for different types of updates and then writes the output to STDOUT. If run from root's crontab then the administator should get the message and can then handle accordingly

The Script

#!/bin/bash
# gund v 2005-12-13-c

cmd=$0
opt=$1

echo "Gentoo Update Notification Dragon '$cmd' on:" `/usr/bin/hostname`
echo "Options: self,sync,glsa,update,revdep,clean,depclean,prune"

export FEATURES="notitles strict"
export NOCOLOR="true"
export PATH=/bin:/usr/bin
export PORTAGE_NICENESS=15

# If any of these phrases are listed in the emerge output 
#  the automatic update will not take place, is passed to egrep
no_auto="apache|glibc|postgresql|ssh"

if [ "$opt" = "self" ]; then
  # neat that I can overwrite myself while I'm running and start it.
  echo "Updrading Self..."
  wget -q -O- http://www.edoceo.com/dl/gund > $cmd
  exit
fi

if [ -z $opt ] || [ "$opt" = "sync" ]; then
  emerge --sync >/dev/null || exit
fi

# GLSA
if [ -z $opt ] || [ "$opt" = "glsa" ]; then
  echo "* GLSA Checks"
  buf=`glsa-check --test all 2>&1 |grep '^[0-9]'`
  for glsa in $buf
  do
    glsa-check --print $glsa 2>/dev/null|head -n2
    glsa-check --pretend $glsa 2>/dev/null|egrep '^The following|    '
    echo
  done
fi

# Update
# note: may not want --deep in here
if [ -z $opt ] || [ "$opt" = "update" ]; then
  echo "* Checking for updates [ -DNpuv ]"
  buf=`emerge -DNpuv --nospinner world |grep '^\[ebuild'`
  if [ -n "$buf" ]; then
    echo "${buf}" | /bin/egrep ${no_auto} >/dev/null
    if [ "$?" != "0" ]; then
      echo "** Performing Automatic Update"
      echo $buf|sed 's/ +\[eb/\n\[eb/g'
      emerge -DNu --nospinner world >/dev/null
    else
      echo "** Manual Update Required, fetching"
      # uncomment below to perform download now
      emerge -DNu --fetch-only >/dev/null
      echo $buf|sed 's/ \[eb/\n\[eb/g'
    fi
  fi
fi

# Revdeps
if [ -z $opt ] || [ "$opt" = "revdep" ] ; then
  if [ -e /usr/bin/revdep-rebuild ]; then
    echo "* Reverse Dependency required rebuilds"
    revdep-rebuild --pretend --quiet | egrep '^  broken|^\[ebuild'
    rm ./.revdep-rebuild.*
  fi
fi

# Packages that can be removed
if [ -z $opt ] || [ "$opt" = "clean" ]; then
  echo "* Cleaning [ -cpv world ]"
  emerge --clean --nospinner --pretend --verbose world
fi
if [ -z $opt ] || [ "$opt" = "depclean" ]; then
  echo "* Useless Packages [ --depclean -pv ]"
  emerge -pv --depclean --nospinner | egrep '^ \w+'
fi
if [ -z $opt ] || [ "$opt" = "prune" ]; then
  echo "* Packages to prune [ -pPv ]"
  emerge -pPv --nospinner | egrep '^ \w+|^ +selected'
fi

Change Log

  • 2005-07-11 - Cleaned, added GLSA checks and revdep-rebuild.
  • 2005-03-13 - Created