Repository 32bit  Forum
Repository 64bit  Wiki

Aboutpkg

Da Slacky.eu.
Versione delle 10:38, 12 set 2006, autore: L1q1d (Discussione | contributi)

(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)

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
# v. 0.0.3 - 14.08.05
#
# this script allows you to check (rapidly enough) the packages
# installed in your linux-box.
#
# (by gall0ws -at- tiscali -dot- it)
#
# suggestion: put this script in /usr/bin
#

# set some variables:
DIR=/var/log/packages	# packages directory
PAGER=/usr/bin/less	# set the default pager

# set the functions:
function usage() {
  cat << USAGE
eg:
aboutpkg [ -e ] packagename

 -d, --desc		show package description (slack-desc)
 -e, --examine 		examine the content of the packages
 -l, --list 		show all packages installed 
 -L, --list-tidy	show all packages by installation order
 -s, --search [string]	search the string in installed packages
 -h, --help 		display this help and exit

USAGE
  exit 0
}

function packsearch () {
  if [ -z "$ARG" ]; then
    echo "which package are you searching for?"
    exit 1
  fi
  ls $DIR | grep -i $ARG

  if [ -z "`ls $DIR | grep -i $ARG`" ]; then
    echo "the package doesn't seem to be installed."
  fi
  exit 0
}

function packdesc() {
  if [ -z "$ARG" ]; then
    echo "which package are you searching for?"
    exit 1
  fi

  PACK=`ls $DIR | grep -i $ARG`
  NAME="`echo $PACK | cut -f1 -d -`:"  

  if [ -z "$PACK" ]; then
    echo "no package found"
    exit 0
  fi

  cd $DIR
  grep -A 11 DESCRIP $PACK | cut -d : -f2 | more # more here is 
  cd $OLDPWD 					 # just better than less
  exit 0
}

function packexamine() {
  if [ -z "$ARG" ]; then
    echo "which package are you searching for?"
    exit 1
  fi

  PACK=`ls $DIR | grep -i $ARG`
  
  if [ -z "$PACK" ]; then
    echo "no package found"
    exit 0
  fi

  cd $DIR
  $PAGER $PACK
  cd $OLDPWD 
  exit 0
}

function packlist() {
for i in `ls $DIR`; do
  echo -ne "$i\n" 
  echo -ne "\t`cat $DIR/$i | grep -A1 DESCRIP | tail -1 | cut -d : -f2`\n\n" 
done

exit 0
}

function secondlist () {
  ls -tr $DIR | $PAGER	# display the list of the installed packages 
  exit 0                # (by installation order)
}

function stringsearch() {
  if [ -z "$ARG" ]; then
    echo "which string are you searching for?"
    exit 1
  fi

  grep $ARG $DIR/* | cut -c 19-

  if [ -z "`grep $ARG $DIR/*`" ]; then
    echo "no strings found."
  fi
  exit 0  
}


# parser:

if [ "$1" == "-d" ] || [ "$1" == "--desc" ]; then
  ARG="$2"
  packdesc
elif [ "$1" == "-e" ] || [ "$1" == "--examine" ]; then
  ARG="$2"
  packexamine
elif [ "$1" == "-l" ] || [ "$1" == "--list" ]; then
  packlist | $PAGER
elif [ "$1" == "-L" ] || [ "$1" == "--list-tidy" ]; then
  secondlist | $PAGER
elif [ "$1" == "-s" ] || [ "$1" == "--search" ]; then
  ARG="$2"
  stringsearch
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
  usage
elif [ "`expr substr $1 1 1`" == "-" ]; then
  echo "aboutpkg: invalid option $1"
  exit 1 
else
  ARG="$1"
  packsearch
fi

## EOF ##

  • Data: 03 Jun 2006
  • Autore: Gallows
  • Versione: 0.0.3
Strumenti personali
Namespace

Varianti