#!/bin/sh # apt-iselect: interactive apt-cache search tool # # Dobrica Pavlinusic # http://www.rot13.org/~dpavlin/apt-iselect.html # # 2003-08-02 first version # 2003-08-03 using mktemp to create temp files, auto-install iselect # 2003-08-04 catch signals so temp files are not left behind, added # enter new search at end of results, autoconfig # # I know it's ugly, but it's still faster than aptitude :-) # # It will automatically use sudo if installed or require user to be root # because apt-cache needs this. It will also install iselect deb package # if it's not already there. # # WARNING: due to iselect limitation, maximum number of results is # 1020 and maximum length of all results is 1048576 bytes if [ ! -z "`which sudo`" ] ; then id=`sudo -p "Using sudo, please enter your password: " id -u` sudo="sudo" else id=`id -u` sudo="" fi if [ "$id" != 0 ] ; then echo "You really need to be root to use apt-cache and thus, apt-iselect !" echo "One way to do this is to install sudo which will be automatically used..." exit 1 fi if [ -z "`which iselect`" ] ; then echo "You really need iselect for apt-iselect, installing..." $sudo apt-get install iselect fi if [ -z "$*" ] ; then echo "Usage: $0 [search pattern for apt-cache search]" exit 1 fi res=`mktemp -q /tmp/apt.iselect.XXXXXX` || ( echo "Can't create temp file!" ; exit 1 ) res2=`mktemp -q /tmp/apt.iselect.XXXXXX` || ( echo "Can't create temp file!" ; rmtemp ; exit 1 ) pkg=`mktemp -q /tmp/apt.iselect.XXXXXX` || ( echo "Can't create temp file!" ; rmtemp ; exit 1 ) function rmtemp() { rm -f $res rm -f $res2 rm -f $pkg } trap 'rmtemp; exit 1' INT QUIT TERM SEGV function apt_cache_search() { search_words=$* echo "Searching apt-cache for \"$search_words\"..." apt-cache search "$*" | head -1020 > $res nr=`wc -l $res | sed 's/^ *//' | cut -d" " -f1` if [ $nr = 0 ] ; then echo "No results for \"$search_words\"" > $res2 nr="no" else echo -e "$nr results for \"$search_words\", enter new search \n" > $res2 cat $res | sed 's/^//' >> $res2 fi echo -e "\nEnter new apt-cache search " >> $res2 } apt_cache_search $* pkg_nr=3 loop=1 while [ $loop = 1 ] ; do loop=0; tmp=`iselect -P -p $pkg_nr -n "apt-iselect: $nr results for \"$search_words\"" < $res2` if echo $tmp | grep search= >/dev/null ; then apt_cache_search `echo $tmp | cut -d= -f2` loop=1 else # not search, find package info pkg_nr=`echo $tmp | cut -d: -f1` pkg_full=`echo $tmp | cut -d: -f2` pkg_name=`echo $pkg_full | cut -d" " -f1` if [ ! -z "$pkg_name" ] ; then echo -e 'Back to search results\n' > $pkg apt-cache show $pkg_name | sed 's/^\(Package: \)/\1/' >> $pkg echo 'Back to search results' >> $pkg tmp=`iselect -n "Package: $pkg_full" < $pkg` if echo $tmp | grep -i back >/dev/null ; then loop=1 elif echo $tmp | grep '^Package: ' >/dev/null ; then deb=`echo $tmp | cut -d: -f2` $sudo apt-get install $deb fi fi fi done rmtemp