/[scripts]/trunk/apt-iselect
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-iselect

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations)
Tue Jul 27 11:51:10 2004 UTC (18 years, 6 months ago) by dpavlin
File size: 4752 byte(s)
allow multi-selection of packages to install

1 #!/bin/sh
2
3 # apt-iselect: interactive apt-cache search tool
4 #
5 # Dobrica Pavlinusic <dpavlin@rot13.org>
6 # http://www.rot13.org/~dpavlin/apt-iselect.html
7 #
8 # 2003-08-02 first version
9 # 2003-08-03 using mktemp to create temp files, auto-install iselect
10 # 2003-08-04 catch signals so temp files are not left behind, added
11 # enter new search at end of results, autoconfig
12 # 2003-08-06 changed delimiter to \s/ to prevent conflict with e-mails
13 # 2003-08-15 automatically run apt-get update if there is no package list
14 # (e.g. changing apt/sources.list without update), cut lines
15 # to 80 chars before sending to iselect (bug workaround)
16 # 2003-08-31 changed delimiters to {}, q on detail page brings back list of
17 # results, highlighted search word(s) in package details
18 # 2003-09-01 changed script to work with any POSIX complient shell, and not
19 # only bash (thanks to Ulrich Doehner for bug report and
20 # suggestions), added support to use su if sudo is not
21 # installed, fixed search with more than one word (thanks
22 # to Tobias Gruetzmacher who reported this bug)
23 # 2003-09-04 moved do_sudo before first call (fixes bug when trying to
24 # install iselect)
25 # 2003-10-09 allow multi-selection of packages to view details
26 # 2003-11-13 fix for RedHat 9.0 mktemp bug suggested by Dobes Vandermeer
27 # 2004-07-27 allow multi-selection of packages to install
28 #
29 # I know it's ugly, but it's still faster than aptitude :-)
30 #
31 # It will automatically use sudo if installed or require user to enter root
32 # password when needed. It will also install iselect deb package
33 # if it's not already there.
34 #
35 # WARNING: due to iselect limitation, maximum number of results is
36 # 1020 and maximum length of all results is 1048576 bytes
37
38 if [ ! -z "`which sudo`" ] ; then
39 use_sudo=1
40 else
41 use_sudo=0
42 fi
43
44 do_sudo() {
45 msg=$1 ; shift
46 if [ "$use_sudo" = 1 ] ; then
47 sudo -p "$msg, please enter your password: " $*
48 else
49 if [ "`id -u`" != 0 ] ; then
50 echo "$msg, please enter root password..."
51 fi
52 su -c "$*"
53 fi
54 }
55
56 if [ -z "`which iselect`" ] ; then
57 echo "You really need iselect for apt-iselect, installing..."
58 do_sudo "Installing iselect" apt-get install iselect
59 fi
60
61 if [ -z "$*" ] ; then
62 echo "Usage: $0 [search pattern for apt-cache search]"
63 exit 1
64 fi
65
66 res=`mktemp /tmp/tmp-res.XXXXXX` || ( echo "Can't create temp file!" ; exit 1 )
67 res2=`mktemp /tmp/tmp-res2.XXXXXX` || ( echo "Can't create temp file!" ; rmtemp ; exit 1 )
68 sel=`mktemp /tmp/tmp-sel.XXXXXX` || ( echo "Can't create temp file!" ; rmtemp ; exit 1 )
69 pkg=`mktemp /tmp/tmp-pkg.XXXXXX` || ( echo "Can't create temp file!" ; rmtemp ; exit 1 )
70
71 rmtemp() {
72 rm -f $res
73 rm -f $res2
74 test -f $sel && rm -f $sel
75 rm -f $pkg
76 }
77
78 # need to update apt cache?
79 LANG=C apt-cache stats 2>&1 | grep "^W: Couldn't stat source package list" >/dev/null && do_sudo "apt-get update needed" apt-get update
80
81 trap 'rmtemp; exit 1' INT QUIT TERM SEGV
82
83 apt_cache_search() {
84 search_words="$@"
85
86 echo "Searching apt-cache for \"$search_words\"..."
87
88 apt-cache search "$search_words" | head -1020 > $res
89 nr=`wc -l $res | sed 's/^ *//' | cut -d" " -f1`
90 if [ $nr = 0 ] ; then
91 echo "No results for \"$search_words\"" > $res2
92 nr="no"
93 else
94 echo "$nr results for \"$search_words\", enter new search {s:search=%[Search for]S}" > $res2
95 echo >> $res2
96 cat $res | sed 's/^/{s}/' >> $res2
97 fi
98 echo >> $res2
99 echo "Enter new apt-cache search {s:search=%[Search for]S}" >> $res2
100 }
101
102 apt_cache_search "$@"
103
104 pkg_nr=3
105 loop=1
106
107 while [ $loop = 1 ] ; do
108
109 loop=0;
110 iselect -m -d '{,}' -P -p $pkg_nr -n "apt-iselect: $nr results for \"$search_words\"" < $res2 > $sel
111
112 if [ ! -s $sel ] ; then
113 exit 0;
114 elif tmp=`grep search= <$sel 2>/dev/null` ; then
115 apt_cache_search `echo $tmp | grep search= | cut -d= -f2`
116 loop=1
117 else
118 # not search, find packages info
119
120 echo '{s}Back to search results' > $pkg
121 echo >> $pkg
122 hl_regex=`echo $search_words | sed -e 's/ /|/' -e 's,^,s#(,' -e 's,$,)#{b}\\\1{/b}#g,'`
123
124 cat "$sel" | while read tmp ; do
125
126 pkg_nr=`echo $tmp | cut -d: -f1`
127 pkg_full=`echo $tmp | cut -d: -f2`
128 pkg_name=`echo $pkg_full | cut -d" " -f1`
129 pkg_list="$pkg_list $pkg_name"
130
131 apt-cache show "$pkg_name" | cut -c-128 | sed 's/^\(Package: \)/{s}\1/' | sed -r "$hl_regex" | sed '1,3 s,{/*b},,g' >> $pkg
132
133 done
134 echo '{s}Back to search results' >> $pkg
135
136 tmp=`iselect -d '{,}' -n "Packages: $pkg_list" -m < $pkg`
137 if echo $tmp | grep -i back >/dev/null ; then
138 loop=1
139 elif echo $tmp | grep '^Package: ' >/dev/null ; then
140 deb=`echo $tmp | sed -e 's,{b/*},,g' -e 's,Package: *,,g'`
141 do_sudo "Installing '$deb'" apt-get install $deb
142 elif [ -z "$tmp" ] ; then
143 loop=1
144 else
145 echo -n "Can't parse output '$tmp' from iselect! Press enter to continue..."
146 read tmp
147 loop=1
148 fi
149 fi
150 done
151
152 rmtemp

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26