#!/bin/bash # # pacsearch for pacman # # Copyright (c) 2005 by Miklos Vajna # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. # # Advantages: # - ~8-500 times faster # - supports regular expressions # - searches the sync and the local database # Disadvantages: # - doesn't search in package descriptions msg() { echo -e "\033[1;32m==>\033[1;0m \033[1;1m$1\033[1;0m" >&2 } error() { echo -e "\033[1;31m==> ERROR:\033[1;0m \033[1;1m$1\033[1;0m" >&2 exit 1 } if [ "$1" == "-u" ]; then if [ "`id -u`" = "0" ]; then msg "Updating the package cache" slocate -U /var/lib/pacman/ -o /var/lib/frugalware/pacsearch.db chmod 644 /var/lib/frugalware/pacsearch.db exit 0 else error "You must be root to update the cache." fi fi if [ ! -e /var/lib/frugalware/pacsearch.db ]; then error "Could not open database: run \"pacsearch -u\" as root!" fi regexp=`echo $1|sed 's|^\^|/|g;s/\$$/-/'` slocate -l 0 -d /var/lib/frugalware/pacsearch.db -r $regexp \ |sed "s|/var/lib/pacman/\([^/]*/[^/]*\).*|\1|; \ s/-\([^-]\+-[^-]\+$\)/ \1/" |uniq