Aboutpkg

Descrizione

Script molto comodo e utile, serve a controllare i pacchetti installati nel sistema e anche ad analizzarne il contenuto, veramente indispensabile.

Script

#!/bin/bash
#
#        aboutpkg v. 0.1.0
#
#  Copyright (c) 2005, 2006 Sergio Perticone <gall0ws@tiscali.it>.
#  All rights reserved.
#
#  Redistribution and use of this script, with or without modification,
#  are permitted provided that this copyright notice and the following
#  disclaimer are retained.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
#
# this script allows you to check (rapidly enough) the packages
# installed in your linux-box.
#
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
 
## packages directory:
DIR=/var/log/packages
 
test -z "$PAGER" && PAGER=less
 
## set the functions:
function usage() {
  cat << USAGE
eg:
aboutpkg [ -a name ] [ -e name ] [ -s string ] [ -l ] [ -L ]
 
  -d, --desc		show package description (slack-desc)
  -e, --examine 	examine the content of the packages
  -l, --list 		show all packages by installation order
  -L, --list-name       show all packages by name
  -s, --search [string]	search the string in installed packages
  -h, --help 		display this help and exit
 
USAGE
  exit 0
}
 
function pack_search() {
    [ -z "$1" ] && {
	echo "which package are you searching for?"
	exit 1
    }
 
    ls $DIR | grep -i $1
 
    [ -z "`ls $DIR | grep -i $1`" ] && {
	echo "the package doesn't seem to be installed."
    }
    exit 0
}
 
function pack_desc() {
    [ -z "$1" ] && {
	echo "which package are you searching for?"
	exit 1
    }
 
    PACK=`ls $DIR | grep -i $1`
    NAME="`echo $PACK | cut -f1 -d -`:"  
 
    [ -z "$PACK" ] && {
	echo "no package found"
	exit 0
    }
 
    cd $DIR
    grep -A 11 DESCRIP $PACK | cut -d : -f2- | more   # more(1) here is better than other pagers
    cd $OLDPWD
    exit 0
}
 
function pack_examine() {
    [ -z "$1" ] && {
	echo "which package are you searching for?"
	exit 1
    }
 
    PACK=`ls $DIR | grep -i $1`
 
    [ -z "$PACK" ] && {
	echo "no package found"
	exit 0
    }
 
    cd $DIR
    $PAGER $PACK
    cd $OLDPWD 
    exit 0
}
 
## so useless..
function packs_list_name() {
    ls $DIR | $PAGER
 
    exit 0
}
 
function packs_list() {
    ls -tr $DIR | $PAGER
 
    exit 0
}
 
function string_search() {
    [ -z "$1" ] && {
	echo "which string are you searching for?"
	exit 1
    }
 
    grep $1 $DIR/* | cut -c 19-
 
    [ -z "`grep $1 $DIR/*`" ] && {
	echo "no strings found."
    }
    exit 0  
}
 
# parser:
case $1 in
 
    '-e'|'--examine')
	pack_examine $2
	;;
 
    '-d'|'--desc')
	pack_desc $2
	;;
 
    '-l'|'--list')
	packs_list | $PAGER
	;;
 
    '-L'|'--list-name')
	packs_list_name | $PAGER
	;;
 
    '-s'| '--search') 
	string_search $2
	;;
 
    '-h'|'--help')
	usage
	;;
 
    -*)
	echo "aboutpkg: invalid option: -- `echo $1 | cut -d - -f2- | cut -d - -f2`"
	echo "Try \`aboutpkg --help' for more information."
	exit 1
	;;
 
    *)
	pack_search $1
	;;
esac
 
## EOF ##
  • Data: 05 Oct 2006
  • Autore: Gallows
  • Versione: 0.1.0