Vous êtes ici: La documentation de Slackware-fr » Thématique Administration » Scripts, Administration » Utilitaire de recherche de paquets installés: listpkg

Utilitaire de recherche de paquets installés: listpkg

Contributeur: Wedge

Utilisation

C'est tout simple, une fois le script copié dans un répertoire du PATH (genre /usr/bin ou /usr/local/bin par exemple), il suffit de lancer dans une console:

[wedge@chimaera ~]$ listpkg ripdvd
ripdvd-1.12.1-noarch-1wed.tgz

Le paramètre est analysé par le script qui recherche tous les paquets contenant ce “mot” dans leur nom. Les paquets correspondants sont ensuite listés sur la console.

Il est tout à fait possible de ne mettre qu'une partie du nom, ou même d'utiliser une expression régulière avec l'option -e

Le script

#! /bin/bash
 
#    listpkg v1.2
#    Copyright (C) 2005 Wedge (tycho@intuxication.org)
#
#    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
 
 
VERSION="1.2"
AUTHOR="Wedge"
MAIL="wedge.ant@gmail.com"
DATE="04/10/2005"
 
function usage()
{
cat << EOF
Usage: listpkg <OPTIONS> [NAME]
 OPTION can be one of these:
 	-h --help: display this help
	-v --version: display the version of listpkg
	-i --case-insensitive: toggle on case insensitive research
	-e --regex: in the case you want to use regular expressions (might give some strange results)
	-r --recursive: scan recursively in packages to find a file (NOT YET IMPLEMENTED)
 
 NAME can be :
 	-filename
	-list of filename (space separated)
	-words 
	-regular expressions ...
 
listpkg will return a list of slackware packages that match each word in NAME
EOF
exit 0
}
 
function version()
{
cat << EOF
listpkg v$VERSION by $AUTHOR ($MAIL)
Last modification on $DATE
EOF
exit 0
}
 
function is_present_pkg()
{
	PKGLIST=`ls /var/log/packages | grep $1 $2`
	for PKG in $PKGLIST; do
		echo "$PKG"	
	done
}
 
if [ $# -eq 0 ]; then
	usage
else
	while [ $# -gt 0 ]; do
		case $1 in
			-h|--help)
				usage;;
			-v|--version)
				version;;
			-i|--case-insensitive)
				OPTIONS="$OPTIONS -i";;
			-e|--regex)
				OPTIONS="$OPTIONS -e";;
			-*)
				usage;;
			*)
				is_present_pkg "$OPTIONS" "$1";;
		esac
		shift 1
	done
fi

Tags

administration/scripts/listpkg.txt · Dernière modification: 2010/02/22 21:30 (édition externe)