#!/bin/bash # CVS $Id: apt-cu,v 1.9 2004/08/11 13:54:52 paulm Exp $ # Release version 0.1 # # Copyright owner: Paul Millar # Copyright: BSD-like license. Do what you want, but don't remove # the copyright. # Please email me diffs of any changes so I can maintain the "master" # version. # # apt-cu: cluster upgrade, and more. # # Put a file .apt-cu.rc in your home directory, which looks like this: # # # # # File must be shell-safe # DEFAULT_HOSTS="clio melpomene erato terpsichore urania attrition \ # lilith shem hathi remus" # CONF=~/.apt-cu.rc # The basic "apt-get" APTGET="apt-get --yes -q" # The commands INSTALL="$APTGET install" UPGRADE="$APTGET upgrade" UPDATE="$APTGET -q update" AUTOCLEAN="$APTGET -q autoclean" CONFIGURE="dpkg --configure -a" ORPHAN='[ -x $(which deborphan) ] && pkg="$(deborphan)" || echo deborphan not installed; [ "$pkg" != "" ] && dpkg --purge $pkg || echo No orphaned packages' # Default values.: cmd=$UPGRADE DEFAULT_HOSTS="localhost" # Try to load user prefs if [ ! -f $CONF ]; then echo "Warning: cannot load $CONF, no user preferences loaded" else . $CONF fi hosts=$DEFAULT_HOSTS ## Calculate diffs between hosts function doDiffs { echo -n Acquiring data # Get data for host in $hosts; do ssh $host dpkg-query -W|awk '{print $1}' > /tmp/$host.cu.$$ echo -n "." done echo # Find the longest package name longest=$(cat /tmp/*.cu.$$ | sort -u | awk '{print length($0)}'|sort -n | tail -1) longest=$[ $longest + 1 ] # Print titlebar echo -n "$(echo -e '\t' | expand -t$longest)" for host in $hosts; do echo -n "$host " done echo # Analyse cat /tmp/*.cu.$$|sort -u | while read pkg; do display=0 for host in $hosts; do grep -q "^$pkg$" /tmp/$host.cu.$$ || display=1 done if [ $display -eq 1 ]; then l=$[ $longest - $(echo $pkg|wc -c) ] line="$pkg $(echo -e '\t' | expand -t$l)" for host in $hosts; do grep -q "^$pkg$" /tmp/$host.cu.$$ if [ $? -eq 0 ]; then line="$line X" else line="$line " fi c=$[ $(echo $host|wc -c) - 3 ] line="$line $(echo -e '\t' | expand -t$c)" done i=$[ $i + 1 ] if [ $i -eq 10 ]; then line="$(echo "$line" | sed 's/ /_/g' | sed 's/_/ /')" i=0 fi echo "$line" fi done # Clean up for host in $hosts; do rm /tmp/$host.cu.$$ done } ## Process arguments while [ $# -gt 0 ]; do case $1 in # Options ... --local) echo Only working on localhost hosts="localhost" ;; --no-update) echo Not updating... noupdate=1 ;; # Commands (only ever one of these) ... --install) echo Installing $* cmd=$INSTALL shift break ;; --upgrade) echo Upgrading... cmd=$UPGRADE shift break ;; --configure) echo Configuring all packages... cmd=$CONFIGURE noupdate=1 shift break ;; --remorphan) echo Removing orphaned packages... cmd="$ORPHAN" noupdate=1 shift break ;; --diff) doDiffs exit ;; --cmd) echo Running arbitrary command: cmd="$1" noupdate=1 noautoclean=1 shift break ;; --help) echo "$0 [--local] [--no-update] [--upgrade | --configure | --remorphan | --diff | --install [ ...]]" exit ;; *) echo Unknown option $1. Perhaps you should try --help? exit ;; esac shift done for host in $hosts; do echo -e "\nUpdating host $host" SSH="ssh -qt root@$host" [ -z $noautoclean ] && $SSH $AUTOCLEAN [ -z $noupdate ] && $SSH $UPDATE $SSH "$cmd" $* done