/[scripts]/trunk/apt-remove
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/apt-remove

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (show annotations)
Wed Jan 25 22:13:22 2006 UTC (16 years, 8 months ago) by dpavlin
File size: 3701 byte(s)
at least in repository: evil brother of apt-iselect, this scripts allows you
to easily remove packages from sytem.

1 #!/bin/sh
2
3 # apt-remove: interactive apt-get remove tool
4 #
5 # Dobrica Pavlinusic <dpavlin@rot13.org>
6 #
7 # based on well-known apt-iselect available at:
8 # https://www.rot13.org/~dpavlin/apt-iselect-remove.html
9 #
10 # 2006-01-04 first version
11 #
12 # It will automatically use sudo if installed or require user to enter root
13 # password when needed. It will also install iselect deb package
14 # if it's not already there.
15 #
16 # WARNING: due to iselect limitation, maximum number of results is
17 # 1020 and maximum length of all results is 1048576 bytes
18
19 if [ ! -z "`which sudo`" ] ; then
20 use_sudo=1
21 else
22 use_sudo=0
23 fi
24
25 do_sudo() {
26 msg=$1 ; shift
27 if [ "$use_sudo" = 1 ] ; then
28 sudo -p "$msg, please enter your password: " $*
29 else
30 if [ "`id -u`" != 0 ] ; then
31 echo "$msg, please enter root password..."
32 fi
33 su -c "$*"
34 fi
35 }
36
37 if [ -z "`which iselect`" ] ; then
38 echo "You really need iselect for apt-iselect, installing..."
39 do_sudo "Installing iselect" apt-get install iselect
40 fi
41
42 if [ -z "$*" ] ; then
43 echo "Usage: $0 [search pattern for dpkg -i search]"
44 exit 1
45 fi
46
47 res=`mktemp /tmp/tmp-res.XXXXXX` || ( echo "Can't create temp file!" ; exit 1 )
48 res2=`mktemp /tmp/tmp-res2.XXXXXX` || ( echo "Can't create temp file!" ; rmtemp ; exit 1 )
49 sel=`mktemp /tmp/tmp-sel.XXXXXX` || ( echo "Can't create temp file!" ; rmtemp ; exit 1 )
50 pkg=`mktemp /tmp/tmp-pkg.XXXXXX` || ( echo "Can't create temp file!" ; rmtemp ; exit 1 )
51
52 rmtemp() {
53 rm -f $res
54 rm -f $res2
55 test -f $sel && rm -f $sel
56 rm -f $pkg
57 }
58
59 trap 'rmtemp; exit 1' INT QUIT TERM SEGV
60
61 dpkg_l_search() {
62 search_words="$*"
63
64 echo "Searching dpkg -l for \"$search_words\"..."
65
66 COLUMNS=500 dpkg -l "$@" | grep ^ii | awk '{print $2}' | head -1020 > $res
67 nr=`wc -l $res | sed 's/^ *//' | cut -d" " -f1`
68 if [ $nr = 0 ] ; then
69 echo "No results for \"$search_words\"" > $res2
70 nr="no"
71 else
72 echo "$nr results for \"$search_words\", enter new search {s:search=%[Search for]S}" > $res2
73 echo >> $res2
74 cat $res | sed 's/^/{s}/' >> $res2
75 fi
76 if [ $nr -gt 0 ] ; then
77 echo >> $res2
78 echo "{s:_quick_install_}Remove all selected" >> $res2
79 fi
80 echo >> $res2
81 echo "Enter new dpkg -l search {s:search=%[Search for]S}" >> $res2
82 }
83
84 dpkg_l_search "$@"
85
86 pkg_nr=3
87 loop=1
88
89 while [ $loop = 1 ] ; do
90
91 loop=0;
92 iselect -m -d '{,}' -P -p $pkg_nr -n "apt-iselect: $nr results for \"$search_words\"" < $res2 > $sel
93
94 if [ ! -s $sel ] ; then
95 exit 0;
96 elif tmp=`grep search= <$sel 2>/dev/null` ; then
97 dpkg_l_search `echo $tmp | grep search= | cut -d= -f2`
98 loop=1
99 elif tmp=`grep -i ':_quick_install_' $sel` ; then
100 debs=`grep -v ':_quick_install_' $sel | cut -d: -f2 | cut -d" " -f1 | xargs echo`
101 do_sudo "Removing '$debs'" apt-get remove $debs
102 else
103 # not search, find packages info
104
105 echo '{s}Back to search results' > $pkg
106 echo >> $pkg
107 hl_regex=`echo $search_words | sed -e 's/ /|/' -e 's,^,s#(,' -e 's,$,)#{b}\\\1{/b}#g,'`
108
109 cat "$sel" | while read tmp ; do
110
111 pkg_nr=`echo $tmp | cut -d: -f1`
112 pkg_full=`echo $tmp | cut -d: -f2`
113 pkg_name=`echo $pkg_full | cut -d" " -f1`
114 pkg_list="$pkg_list $pkg_name"
115
116 apt-cache show "$pkg_name" | cut -c-128 | sed 's/^\(Package: \)/{s}\1/' | sed -r "$hl_regex" | sed '1,3 s,{/*b},,g' >> $pkg
117
118 done
119 echo '{s}Back to search results' >> $pkg
120
121 tmp=`iselect -d '{,}' -n "Packages: $pkg_list" -m < $pkg`
122 if echo $tmp | grep -i back >/dev/null ; then
123 loop=1
124 elif echo $tmp | grep '^Package: ' >/dev/null ; then
125 deb=`echo $tmp | sed -e 's,{b/*},,g' -e 's,Package: *,,g'`
126 do_sudo "Removing '$deb'" apt-get remove $deb
127 elif [ -z "$tmp" ] ; then
128 loop=1
129 else
130 echo -n "Can't parse output '$tmp' from iselect! Press enter to continue..."
131 read tmp
132 loop=1
133 fi
134 fi
135 done
136
137 rmtemp

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26