Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: SCRIPT: Get a list of packages you've installed since the initial installation

  1. #1
    Join Date
    May 2006
    Location
    Texas
    Beans
    567

    SCRIPT: Get a list of packages you've installed since the initial installation

    With feisty coming up, those who prefer to fresh install may want to know all the packages you have installed yourself outside of the base installation to allow you to pick up very quickly where you left off.

    I have created this script, that works in ubuntu, xubuntu, and kubuntu that allows you to do that. It not only allows you to pair down the installed packages to the one's you added yourself, but also allows you the choice to omit libraries (seeing as those are generally dependencies) as well as the choice to omit the long list of kernel and module versions that have likely been installed and allows you to output the package list to a file.

    The script works by amassing a long list of packages using timestamps as well as using the core meta packages and then removing those packages from the list of installed packages.

    To use this script, make sure you are in the home directory and do the following: (make sure word wrap is turned off by the way)
    Code:
    gedit user_installed_packages # or use kate for kde and mousepad for xfce
    Then copy and paste the script:
    Code:
    #!/bin/bash
    
    #Ask for version to set DESKTOP
    while [ "$answer" != "ubuntu" -a "$answer" != "kubuntu" -a "$answer" != "xubuntu" ]; do 
    	echo "Was your install cd ubuntu, kubuntu, or xubuntu (type out exactly)?"
            read answer
    done
    
    #Get the installed packages
    INSTALLED_PACKAGES=$(dpkg --get-selections | grep -v deinstall | awk '{print $1}')
    
    #Get date of minimal and use that to find untouched packages
    INSTALL_DATE=$(ls -l /var/lib/dpkg/info | grep ubuntu-minimal.list | awk '{print $6}')
    BASE_PKG=$(ls -l /var/lib/dpkg/info | grep $INSTALL_DATE | awk '{print $8}' | sed 's/.list//g')
    
    #Get the dependencies of the meta packages used during install
    STANDARD=$(apt-cache show ubuntu-standard | grep -E ^Depends | sed 's/^Depends: //' | \
    sed 's/, /\n/g' | sed 's/ | /\n/g')
    MINIMAL=$(apt-cache show ubuntu-minimal | grep -E ^Depends | sed 's/^Depends: //' | \
    sed 's/, /\n/g' | sed 's/ | /\n/g')
    DESKTOP=$(apt-cache show $answer"-desktop" | grep -E ^Depends | sed 's/^Depends: //' | \
    sed 's/, /\n/g' | sed 's/ | /\n/g')
    
    #Set up the grep strings (what a stupid way to do this)
    GREP_STRING=$(for x in $(echo $BASE_PKG) $(echo $STANDARD) $(echo $MINIMAL) \
    $(echo $DESKTOP) ; do echo "$x|" ; done)
    CLEAN_GREP=$(echo $GREP_STRING | sed 's/\ //g' | sed "s/|$/\'/" | sed "s/^/\'/")
    
    # Find the new packages and setup nolib
    NEW_PACKAGES=$(echo "$INSTALLED_PACKAGES" | grep -Evw $CLEAN_GREP)
    NOLIB=$(echo "$NEW_PACKAGES" | grep -Ev ^lib)
    
    # Ask for libraries or no libraries, kernel or no kernel, and output file or not
    while [ "$choice" != "y" -a "$choice" != "n" ]; do 
    	echo "Include libraries in the results (y/n)?"
            read choice
    done
    
    if [ "$choice" = "y" ] ; then
    	OUTPUT=$(echo "$NEW_PACKAGES")
    else
    	OUTPUT=$(echo "$NOLIB")
    fi
    
    while [ "$response" != "y" -a "$response" != "n" ]; do 
    	echo "Include every version of the kernels and modules that you have installed (y/n)?"
            read response
    done
    
    if [ "$response" = "n" ] ; then
    	OUTPUT=$(echo "$OUTPUT" | grep -Ev '^linux-headers-2|^linux-image-2|^linux-restricted-modules-2')
    fi
    
    while [ "$input" != "y" -a "$input" != "n" ]; do 
    	echo "Do you want to output the package list to a text file (y/n)?"
            read input
    done
    
    if [ "$input" = "n" ] ; then
    	echo "$OUTPUT"
    else
    	echo -e "What should the name of the file be?\n(Make sure you can write \
    to it and make sure the path exists)"
    	read file
    	if [ "${file%%/*}" = "~" ] ; then
    		file="/home/$USER$(echo $file | sed 's/~//')"
    	fi
    echo "$OUTPUT" > $file
    fi
    exit
    Save and exit, then
    Code:
    chmod +x user_installed_packages
    To run it then
    Code:
    ./user_installed_packages
    Just follow the prompts and you should get what you want.

    Note: this is not 100% perfect, a few packages can slip by that were part of the base installation, but generally that is maybe 3-4.
    Last edited by bruenig; April 8th, 2007 at 06:15 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Eastern United States
    Beans
    396

    Re: SCRIPT: Get a list of packages you've installed since the initial installation

    A friend of mine mentioned this post to me. Great idea and great script! I am surprised it didn't get more attention.

    Incidentally, when I ran this it seems the installed package list that generated included some packages that I had installed and then later removed. Was that intended?
    Last edited by klytu; March 31st, 2007 at 02:33 PM.
    "Klaatu barada nikto"
    On the keyboard of life, always keep one finger on the escape button.
    Registered Linux User 424417

  3. #3
    Join Date
    Jun 2006
    Beans
    Hidden!

    Re: SCRIPT: Get a list of packages you've installed since the initial installation

    how about:

    Code:
    dpkg --get-selections
    dpkg --get-selections | grep -E '\<install$'
    dpkg --get-selections | grep -E '\<install$' | cut -f 1

  4. #4
    Join Date
    May 2006
    Location
    Texas
    Beans
    567

    Re: SCRIPT: Get a list of packages you've installed since the initial installation

    Quote Originally Posted by klytu View Post
    A friend of mine mentioned this post to me. Great idea and great script! I am surprised it didn't get more attention.

    Incidentally, when I ran this it seems the installed package list that generated included some packages that I had installed and then later removed. Was that intended?
    Hmmm, that does appear to happen. I never even considered that. I just assumed that those things would be gone. Such a thing can be fixed though. I have changed the script above.

  5. #5
    Join Date
    Apr 2006
    Location
    Surrounded by idiots!
    Beans
    1,295
    Distro
    Kubuntu 4.10

    Re: SCRIPT: Get a list of packages you've installed since the initial installation

    Nice one, I really needed something like this because I setup a mail server and forgot all the packages I installed. Saved me a heap of time, thanks .

  6. #6
    Join Date
    Mar 2006
    Location
    Eastern United States
    Beans
    396

    Re: SCRIPT: Get a list of packages you've installed since the initial installation

    Quote Originally Posted by bruenig View Post
    Hmmm, that does appear to happen. I never even considered that. I just assumed that those things would be gone. Such a thing can be fixed though. I have changed the script above.
    Nice job! It was also educational for me to read through your scripts. Thanks!
    "Klaatu barada nikto"
    On the keyboard of life, always keep one finger on the escape button.
    Registered Linux User 424417

  7. #7
    Join Date
    Oct 2005
    Location
    Columbus, OH
    Beans
    47

    Re: SCRIPT: Get a list of packages you've installed since the initial installation

    This script is awsome! Thank you. I like that it asks you if you want the libraries included. I figured that dependancies will install the ones I need along the way.

  8. #8
    Join Date
    Aug 2005
    Beans
    18

    Re: SCRIPT: Get a list of packages you've installed since the initial installation

    Thanks, this is exactly what I was looking for. It'll be a big help with a fresh install.

    This wiki page has a section on "Clean install with /home on separate partition". Maybe your script should be part of this.

  9. #9
    Join Date
    Mar 2007
    Location
    Florida
    Beans
    126
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: SCRIPT: Get a list of packages you've installed since the initial installation

    Very nice script, thank you for putting your time into this. Thanks
    -Martin

  10. #10
    Join Date
    Dec 2006
    Beans
    77
    Distro
    Ubuntu 6.10 Edgy

    Re: SCRIPT: Get a list of packages you've installed since the initial installation

    Hi,
    your script is very nice.

    It would be good to have a version that doesn't need user feedback and then could be put to cron.daily
    Thanks to all who help me out and the developpers!

    Friendly greetings... CU

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •