There are a couple of ways to do this.
Using a Script
A quick and dirty solution would be to write a script called apt-get or aptitude and make it call the actual program as such:
#!/bin/bash
# filename: apt-get
# '$@' is all of the arguments passed to the script
/usr/bin/apt-get-bin "$@"
# or /usr/bin/aptitude-bin "$@"
if [[ $1 == *upgrade* ]] ; then
checkrestart
fi
Make the script executable: chmod +x apt-get. You may also want to make the script owned by root: chown root apt-get; chgrp root apt-get. Be careful not to set the setuid bit on your script, because if an attacker gains write privileges to it, they could quickly and easily modify it to give them a root shell.
This method would of course require you to move the actual binary to another location and move your shell script to some location in your path. The proper place to put user scripts is /usr/local/bin. In this situation though, you should put your script in the location the actual binary was in before you moved it in order to keep things organized.
Replacing the binary with a script in this manner is fairly intrusive and affects all users on the machine. As an alternative, you could call your script something like apt-get-cr and just remember to call that script instead of apt-get. You could also write a shell function.
Using a Shell Function
Using a shell function allows you to keep the command name apt-get without having to move around binaries.
apt-get() {
# 'command' makes sure this function doesn't call itself.
# You could also use a direct path the binary as shown above.
command apt-get "$@"
if [[ $1 == *upgrade* ]] ; then
checkrestart
fi
}
Put this function somewhere in your shell configuration (~/.bashrc, ~/.zshrc, etc.)
This method is generally a lot less intrusive than the script method. Also, it doesn't require moving around the binaries, which is generally something only the root user can do.
On the downside, the shell function method isn't always very portable between shells and doesn't inherently mesh well with graphical interfaces such as launcher bars in the way the script method does (you can almost always treat a script like an executable binary.)