Thursday, November 17, 2011

Debian/Ubuntu markauto cleanup script.


The Debian installer has a bad habit of marking packages 80% of packages as manually installed which causes a horrible dependency issue.

The script below lists packages which if marked automatically installed wont be removed. This also prevents listing of packages which are having important priority.


#! /bin/bash



# Script to print packages which if marked as installed automatically will not be removed (cause its it's a dependency of another manually installed package)

# This may give wrong output in circular dependencies, cause -

# aptitude why A -- B depends/recommends A

# aptitude why B -- A depends/recommends B

# this means both A and B will be included.

# in this case, one or both of them will have to be manually installed

list="$(aptitude search '~i' | grep --invert-match '..A' | cut -d ' ' -f4)"

# function to cut first line in variable list.

cut_first() {

 list="$(echo "$list" | tail -n +2)"

}

while [[ "$list" != "" ]]

do

 process="$(echo "$list" | head -1)"

 aptitude why $process | grep --ignore-case --regexp="recommends" --regexp="depends" &> /dev/null

 if [[ $? == 0 && "$(aptitude show "$process" | grep --ignore-case --regexp="Priority: required" --regexp="Priority: Important")" == "" ]]

 then

  echo "$process"

 fi

 cut_first

done



Before you use -- I warn, check if the package list is correct, to confirm, all packages if marked auto should not remove any packages as vacant dependencies.

After this you can have a clean system where you can check if the manually installed packages are ok or not.

No comments:

Post a Comment