Repository 32bit  Forum
Repository 64bit  Wiki

Aboutpkg: differenze tra le versioni

Da Slacky.eu.
 
m (adattato a GeSHi syntax)
 
(Una revisione intermedia di un utente non mostrate)
Riga 3: Riga 3:
Script molto comodo e utile, serve a controllare i pacchetti installati nel sistema e anche ad analizzarne il contenuto, veramente indispensabile.
Script molto comodo e utile, serve a controllare i pacchetti installati nel sistema e anche ad analizzarne il contenuto, veramente indispensabile.
= Script =
= Script =
<pre>
+
<source lang="bash">
#!/bin/bash
#!/bin/bash
# v. 0.0.3 - 14.08.05
+
#
  +
# 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
# this script allows you to check (rapidly enough) the packages
# installed in your linux-box.
# installed in your linux-box.
#
#
# (by gall0ws -at- tiscali -dot- it)
+
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
#
+
# suggestion: put this script in /usr/bin
+
## packages directory:
#
+
DIR=/var/log/packages
# set some variables:
+
test -z "$PAGER" && PAGER=less
DIR=/var/log/packages # packages directory
 
PAGER=/usr/bin/less # set the default pager
 
# set the functions:
+
## set the functions:
function usage() {
function usage() {
cat << USAGE
cat << USAGE
eg:
eg:
aboutpkg [ -e ] packagename
+
aboutpkg [ -a name ] [ -e name ] [ -s string ] [ -l ] [ -L ]
-d, --desc show package description (slack-desc)
+
-d, --desc show package description (slack-desc)
-e, --examine examine the content of the packages
+
-e, --examine examine the content of the packages
-l, --list show all packages installed
+
-l, --list show all packages by installation order
-L, --list-tidy show all packages by installation order
+
-L, --list-name show all packages by name
-s, --search [string] search the string in installed packages
+
-s, --search [string] search the string in installed packages
-h, --help display this help and exit
+
-h, --help display this help and exit
USAGE
USAGE
Riga 34: Riga 34:
}
}
function packsearch () {
+
function pack_search() {
if [ -z "$ARG" ]; then
+
[ -z "$1" ] && {
echo "which package are you searching for?"
+
echo "which package are you searching for?"
exit 1
+
exit 1
fi
+
}
ls $DIR | grep -i $ARG
 
if [ -z "`ls $DIR | grep -i $ARG`" ]; then
+
ls $DIR | grep -i $1
echo "the package doesn't seem to be installed."
+
fi
+
[ -z "`ls $DIR | grep -i $1`" ] && {
exit 0
+
echo "the package doesn't seem to be installed."
  +
}
  +
exit 0
}
}
function packdesc() {
+
function pack_desc() {
if [ -z "$ARG" ]; then
+
[ -z "$1" ] && {
echo "which package are you searching for?"
+
echo "which package are you searching for?"
exit 1
+
exit 1
fi
+
}
PACK=`ls $DIR | grep -i $ARG`
+
PACK=`ls $DIR | grep -i $1`
NAME="`echo $PACK | cut -f1 -d -`:"
+
NAME="`echo $PACK | cut -f1 -d -`:"
+
if [ -z "$PACK" ]; then
+
[ -z "$PACK" ] && {
echo "no package found"
+
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
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() {
+
function pack_examine() {
if [ -z "$ARG" ]; then
+
[ -z "$1" ] && {
echo "which package are you searching for?"
+
echo "which package are you searching for?"
exit 1
+
exit 1
fi
+
}
  +
  +
PACK=`ls $DIR | grep -i $1`
  +
  +
[ -z "$PACK" ] && {
  +
echo "no package found"
  +
exit 0
  +
}
PACK=`ls $DIR | grep -i $ARG`
+
cd $DIR
+
$PAGER $PACK
if [ -z "$PACK" ]; then
+
cd $OLDPWD
echo "no package found"
 
exit 0
exit 0
fi
+
}
cd $DIR
+
## so useless..
$PAGER $PACK
+
function packs_list_name() {
cd $OLDPWD
+
ls $DIR | $PAGER
exit 0
+
  +
exit 0
}
}
function packlist() {
+
function packs_list() {
for i in `ls $DIR`; do
+
ls -tr $DIR | $PAGER
echo -ne "$i\n"
 
echo -ne "\t`cat $DIR/$i | grep -A1 DESCRIP | tail -1 | cut -d : -f2`\n\n"
 
done
 
exit 0
+
exit 0
}
}
function secondlist () {
+
function string_search() {
ls -tr $DIR | $PAGER # display the list of the installed packages
+
[ -z "$1" ] && {
exit 0 # (by installation order)
+
echo "which string are you searching for?"
}
+
exit 1
  +
}
function stringsearch() {
+
grep $1 $DIR/* | cut -c 19-
if [ -z "$ARG" ]; then
+
echo "which string are you searching for?"
+
[ -z "`grep $1 $DIR/*`" ] && {
exit 1
+
echo "no strings found."
fi
+
}
+
exit 0
grep $ARG $DIR/* | cut -c 19-
 
 
if [ -z "`grep $ARG $DIR/*`" ]; then
 
echo "no strings found."
 
fi
 
exit 0
 
}
}
 
# parser:
# parser:
+
case $1 in
if [ "$1" == "-d" ] || [ "$1" == "--desc" ]; then
+
ARG="$2"
+
'-e'|'--examine')
packdesc
+
pack_examine $2
elif [ "$1" == "-e" ] || [ "$1" == "--examine" ]; then
+
;;
ARG="$2"
+
packexamine
+
'-d'|'--desc')
elif [ "$1" == "-l" ] || [ "$1" == "--list" ]; then
+
pack_desc $2
packlist | $PAGER
+
;;
elif [ "$1" == "-L" ] || [ "$1" == "--list-tidy" ]; then
+
secondlist | $PAGER
+
'-l'|'--list')
elif [ "$1" == "-s" ] || [ "$1" == "--search" ]; then
+
packs_list | $PAGER
ARG="$2"
+
;;
stringsearch
+
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+
'-L'|'--list-name')
usage
+
packs_list_name | $PAGER
elif [ "`expr substr $1 1 1`" == "-" ]; then
+
;;
echo "aboutpkg: invalid option $1"
+
exit 1
+
'-s'| '--search')
else
+
string_search $2
ARG="$1"
+
;;
packsearch
+
fi
+
'-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 ##
## EOF ##
  +
</source>
</pre>
+
* Data: 05 Oct 2006
 
* Data: 03 Jun 2006
 
* Autore: Gallows
* Autore: Gallows
* Versione: 0.0.3
+
* Versione: 0.1.0

Versione attuale delle 02:17, 8 mag 2011

[modifica] Descrizione

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

[modifica] 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
Strumenti personali
Namespace

Varianti