Topic: Catching apt-get install as you go
I've been looking for a way of seeing what I've actually installed on my system for some time. I found a couple of solutions that didn't really get me where I wanted to go. I think the fundamental problem is that the particular information I want isn't logged on the system by default.
I've come up with the following way of logging it myself, in ~/.bashrc:
alias install='~/bin/install_and_log install'Then as ~/bin/install_and_log:
#!/bin/bash
# wrapper around apt-get install that logs the application being installed
LOG_FILE=~/backup/apt-get_install.log
args=("$@")
if [ "$1" != "install" ]; then
echo "This script should be run as a proxy for apt-get install to log installs in $LOG_FILE"
exit 1
fi
if [ ! $2 ]; then
echo "Please select a program to install or use -s to simulate an install"
exit 1
fi
if [ "$2" == "-s" ]; then
if [ ! $3 ]; then
echo "Please select a program to simulate installing"
exit 1
fi
SIM_EXIT=0
echo -e "Running simulated install now: \n"
for (( i = 2 ; i < ${#args[@]} ; i++ )); do
sudo apt-get install -s ${args[$i]}
if [ "$?" != "0" ]; then
echo -e "\e[0;31mERROR: on ${args[$i]}\e[0m" >&2
SIM_EXIT=1
fi
echo -e "\n"
done
exit $SIM_EXIT
else
for (( i = 1 ; i < ${#args[@]} ; i++ )); do
DESC=$(apt-cache show ${args[$i]} | grep --max-count=1 -i "description:" | cut -c14-)
if [ "$DESC" == "" ]; then
echo -e "\e[0;31mAborting at ${args[$i]} \e[0m\n" >&2
exit 1
else
sudo apt-get install ${args[$i]}
if [ ! $? ]; then
echo -e "\e[0;31mInstall of ${args[$i]} failed.\e[0m" >&2
exit 1
fi
RIGHT_NOW=$(date +"%Y-%m-%d %a %H:%M")
echo -e "$RIGHT_NOW\t${args[$i]}\t=>\t$DESC\n" >> $LOG_FILE
echo -e "LOGGED: ${args[$i]} installed at $RIGHT_NOW \n"
fi
done
fiThis will result in the following sort of log, as ~/backup/apt-get_install.log:
2009-06-12 Fri 11:49 apt-doc => Documentation for APT
2009-06-12 Fri 11:49 nginx => small, but very powerful and efficient web serverThis script was made with the dangerous combination of haste, ignorance and Google; as such, if you (and I'm sure someone does) have suggestions for improvements they would be much appreciated.
Last edited by fhsm (2009-06-12 15:49:45)