SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2009-06-10 04:08:39

fhsm
#! Junkie
From: New Hampshire, USA
Registered: 2009-01-05
Posts: 445

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
fi

This 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 server

This 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)

Offline

Be excellent to each other!

#2 2009-08-14 10:53:04

fhsm
#! Junkie
From: New Hampshire, USA
Registered: 2009-01-05
Posts: 445

Re: Catching apt-get install as you go

Another interesting solution showed up on the .bashrc thread.

Offline

#3 2009-09-05 19:37:31

dpeirce
New Member
Registered: 2009-09-01
Posts: 5

Re: Catching apt-get install as you go

'dpkg -l > progs.txt' ?????

In faith, Dave
Viva Texas

Offline

#4 2009-09-05 23:46:06

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: Catching apt-get install as you go

fhsm wrote:

Another interesting solution showed up on the .bashrc thread.

Hehe I was just going to post that again big_smile

+1 cool


I'm so meta, even this acronym

Offline

#5 2009-09-06 12:01:31

gruen
#! Member
From: Germany
Registered: 2008-12-03
Posts: 55

Re: Catching apt-get install as you go

To get a package list (installed and deinstalled packages) I use:

$ dpkg --get-selections > crunchbang-package-list.txt

Last edited by gruen (2009-09-06 12:03:10)


Samsung N220 | Ubuntu 10.04 LTS | #! 11 "Waldorf" & Xfce
http://twitter.com/herrgruen

Offline

#6 2009-10-12 18:29:42

fhsm
#! Junkie
From: New Hampshire, USA
Registered: 2009-01-05
Posts: 445

Re: Catching apt-get install as you go

Both great ways to get a list of what is installed but not what you installed. The point of this script is to just log the actual primary package that you installed onto the base system. Not what came with the distro / dependences of things you installed. Anyone have an easy way of just getting at what you've installed?

Offline

#7 2009-10-12 20:46:13

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Catching apt-get install as you go

/var/log/dpkg.log has the logs of what has been installed in what hasnt

so something like

awk '$3 ~ /install|remove/ {print $3 ": "$4}' /var/log/dpkg.log

should give you a list of what was installed and what wasn't

note though if you install then remove something this will show up as 2 entries, it could probably be done to show only what is installed but its abit beyond my awk abilities, plus its probably easier to do it in python


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#8 2009-10-12 21:13:27

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Catching apt-get install as you go

ok i was bored

#! /usr/bin/env python

log = open('/var/log/dpkg.log','r').read()
install=[]
remove=[]
for lines in log.split('\n'):
    if len(lines) > 1:
        lines = lines.split(' ')
        if lines[2] == 'remove':                    
            if lines[3] in install:
                install.remove(lines[3])
            else:
                remove.append(lines[3])

        elif lines[2] == 'install':
            if lines[3] in remove:
                remove.remove(lines[3])
            else:
                install.append(lines[3])

print 'installed apps:\n-----------------------\n'
for entries in install: print entries
print 'removed apps:\n-------------------------\n'
for entries in remove: print entries

(chmod +x foobar to make it executable)


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#9 2009-10-12 22:23:02

fhsm
#! Junkie
From: New Hampshire, USA
Registered: 2009-01-05
Posts: 445

Re: Catching apt-get install as you go

Another interesting solution and one that I considered initially (see link in my first post) but one that doesn't account for log rotation. As such it would really need to be a monthly cron job on /var/log/dpkg.log.1 and append a separately maintained log file or run through /var/log/dpkg.log.[n+1].

Even going over all the available logs this still isn't quite what I was after because it shows everything that has been installed (updates / dependencies etc), instead of just the primary package requested. For example if I ran this script over a concatenation of all my dpkg.log files midori would show up multiple times - once when I ran apt-get install midori and then every time I ran apt-get update and a new midori package was available.

All of that said accounting for removals (which I had not considered) is actually quite valuable. Something I'll have to think about.

Offline

#10 2009-10-13 12:03:36

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Catching apt-get install as you go

it would be hard to get rid of duplicates due to updates because they would have different names
one solution could be

install = set([lines.partition('-')[0] for lines in install])
remove = set([lines.partition('-')[0] for lines in remove])

inserted just before the print statements of my script

set gets rid of straight duplicates.
partition splits the packages by the first '-' so you would get 'foo' from 'foo-bar-0.1'
although i suspect it may chop off some important bits of some package names.
there isn't really a way around this with out writing something very OTT.

UPDATE:
thinking about it the best way would probably be a highbred of my script on your wrapper
ie

function aptinstall(){sudo apt-get install $@ && echo $@ >> file} 

the wrapper would out put 'installed package other-info' to a file
then a script to to sort out packages that were installed then deinstalled etc.

Last edited by benj1 (2009-10-13 12:19:12)


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#11 2009-10-13 14:02:45

alon_h
#! Junkie
Registered: 2008-12-13
Posts: 269

Re: Catching apt-get install as you go

sounds like you're after something like (or a twist on) aptitude's log:

cat /var/log/aptitude
...
Aptitude 0.4.11.11: log report
Sun, Oct  4 2009 23:00:04 +0200

IMPORTANT: this log only lists intended actions; actions which fail due to
dpkg problems may not be completed.

Will install 9 packages, and remove 1 packages.
42.2MB of disk space will be used
===============================================================================
[REMOVE, NOT USED] octave3.0-htmldoc
[INSTALL, DEPENDENCIES] libarpack2
[INSTALL, DEPENDENCIES] libftgl2
[INSTALL, DEPENDENCIES] libgraphicsmagick++3
[INSTALL, DEPENDENCIES] libgraphicsmagick3
[INSTALL, DEPENDENCIES] libqrupdate1
[INSTALL, DEPENDENCIES] octave3.2-common
[INSTALL, DEPENDENCIES] octave3.2-htmldoc
[HOLD] libgdl-1-common
[INSTALL] octave3.2
[UPGRADE] qtoctave 0.8.1+dfsg-3 -> 0.8.2+dfsg-1
===============================================================================

Log complete.
...

it makes an entry for every committed change, with some grepping it shouldn't be too hard to get a log of just installed & removed packages by date. but as the disclaimer says it doesn't account for dpkg errors.
you'd need to use aptitude instead of apt-get though (they're almost the same... and aptitude has the ncurses option).

a.

Last edited by alon_h (2009-10-13 14:09:05)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo