wiki:AptitudeUpdateScript
Last modified 13 months ago Last modified on 10/24/15 14:33:10

Debian Aptitude Upgrade Scripts

These scripts were written to enable the quick and easy updating of Debian packages and the recording of the updates in the /root/Changelog, see ticket:470#comment:6.

The following two scripts, a-up and logchanges, are installed in /usr/local/bin on PuffinServer, PenguinServer and ParrotServer and are used to do system updates and record the updates in /root/Changelog. The contents of the Changelog is then emailed to root by metche so that the people working on the server know what updates have been applied.

Notification of available Debian updates are sent by email every 5 mins after they become available via Munin on PenguinServer, see the apt_all graphs:

Updating servers is simply a matter of:

sudo -i
a-up

a-up

#!/bin/bash

# This script runs "aptitude full-upgrade" and updates the Changelog 

# location of the logchange script
LOGCHANGE="/usr/local/bin/logchange"

# check that the logchange script is installed
if [[ ! -f $LOGCHANGE ]] ; then
  echo "You need to install the $LOGCHANGE script before you can run $0"
  exit
fi

# check that apt-show-versions in installed and if it isn't then install it
if [[ ! -f "/usr/bin/apt-show-versions" ]] ; then
  echo "Installing apt-show-versions, please wait a while after it's installed"
  logchange "apt-show-versions : installed"
  aptitude install apt-show-versions
  exit
fi

# get updates
apt-get -qq update
# get a list of updates
UPDATES=$(apt-show-versions -b -u | xargs)
# if we have updates then install them and write the list of updates to the 
# Changelog
if [[ $UPDATES ]]; then
  echo "About to upgrade $UPDATES"
  logchange "$UPDATES : updated"
  aptitude full-upgrade
  exit
else
  echo "No updates today"
  exit
fi

logchange

#!/bin/bash

# This is a script to update the Changelog

# File name of the Changelog
CHANGELOG_NAME="Changelog"

DATESTAMP=$(date +%Y-%m-%d)
TIMESTAMP=$(date +%Y-%m-%d-%H-%M-%S)

# check that $HOME is set
if [[ $HOME ]]; then
  CHANGELOG_DIR=$HOME
  CHANGELOG=$CHANGELOG_DIR/$CHANGELOG_NAME
  BACKUP_DIR=$CHANGELOG_DIR/.$CHANGELOG_NAME
  CHANGELOG_BACKUP=$BACKUP_DIR/$CHANGELOG_NAME.$TIMESTAMP
else
  echo "You are homeless?"
  exit
fi

# get a username and if we can't use root
if [[ $SUDO_USER ]]; then
  CHANGELOG_EDITOR=$SUDO_USER
elif [[ $USER ]]; then
  CHANGELOG_EDITOR=$USER
else
  CHANGELOG_EDITOR=root
fi

# check for some changes on standard input
if [[ $1 ]]; then
  CHANGES=$1
elif [[ ! $1 ]]; then
  echo "Type the changes you would like recorded then [ENTER]:"
  read changes
  CHANGES=$changes
fi

# create the backup directory if it doesn't exist 
if [[ ! -d "${BACKUP_DIR}" ]] ; then
  mkdir $BACKUP_DIR
fi

# backup the CHANGELOG if it exists
if [[ -f "${CHANGELOG}" ]] ; then
  cp -a $CHANGELOG $CHANGELOG_BACKUP
fi

# write the date and user to the CHANGELOG 
echo -e "$DATESTAMP\t$CHANGELOG_EDITOR" > $CHANGELOG

# write what we have done, taken from standard in
echo -e "\t*\t$CHANGES" >> $CHANGELOG

# write a blank line 
echo >> $CHANGELOG

# write the backup back to the $CHANGELOG
if [[ -f "${CHANGELOG_BACKUP}" ]] ; then
  cat $CHANGELOG_BACKUP >> $CHANGELOG
fi