slackpb: pulizia del codice..aiutatemi!!
Inviato: mar 20 set 2005, 22:37
Salve ragazzi ieri mi so messo in testa di fare uno script che mi facilitasse la ricerca sul package browser di slackware. Ebbene si'! l'ho finito adesso e però mi sembra che il codice sia un pò sporco. Mi date una mano a pulirlo un pò? :P
Vi ringrazio anticipatamente 
Codice: Seleziona tutto
#!/bin/sh
##########################################################################
# #
# Copyright (C) 2005-2006 - SlackPB v1.0 by Fr4NkiR #
# #
# Author: Francesco 'Fr4NkiR' Pasqua <frankir@gmail.com> #
# #
# Thanks: #
# - Fulvio 'VuLfiO' Becherucci for english translation #
# <blue69shark89@yahoo.it> #
# #
# Slackpb 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. #
# #
# Slackpb 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., 675 Mass Ave, Cambridge, MA 02139, USA. #
# #
##########################################################################
ver=1.0
file=/tmp/slackpb.tmp
conn=`/sbin/ifconfig ppp0 &> /dev/null`
#Testing Internet Connection
if [ "$conn" == "" ];
then
echo -e "\nWarning: ppp0 is down - Are you connected on internet?!\n"
exit 0
fi
help()
{
echo "slackpp by Fr4NkiR
Usage: slackpb --ACTION WORD OPTION
--slack WORD < -c|-10.2|-10.1|-10.0|-9.1|-9.0|-8.1 >
--patches WORD < -c|-10.2|-10.1|-10.0|-9.1|-9.0|-8.1 >
--extra WORD < -c|-10.2|-10.1|-10.0|-9.1|-9.0|-8.1 >
--help View this message
--version View slackpb version
Example: slackpb --slack libFLAC.so -c"
}
slack_ver()
{
if [ $sv != "-10.2" ] && [ $sv != "-10.1" ] && [ $sv != "-10.0" ] && [ $sv != "-9.1" ] && [ $sv != "-9.0" ] && [ $sv != "-8.1" ];
then
opt="current"
else
opt=`echo $sv | cut -d"-" -f2`
fi
}
alg()
{
url="http://www.slackware.it/pb/searchfile.php?v=$opt&c=$category&string=$word&w=on"
/usr/bin/lynx -dump -accept_all_cookies $url > $file
start=`cat -n /tmp/slackpb.tmp | grep "Showing" | awk -F " " '{printf $1" "}' | awk -F" " '{print $1}'`
end=`cat -n /tmp/slackpb.tmp | grep "Showing" | awk -F " " '{printf $1" "}' | awk -F" " '{print $2}'`
tot_line=`expr $end - $start`
head -n $end $file &> /tmp/pb
tail -n $tot_line /tmp/pb &> $file
cat $file | grep 486 | awk -F" " '{print $1}' | awk -F"]" '{print $2}'
cat $file | grep 386 | awk -F" " '{print $1}' | awk -F"]" '{print $2}'
cat $file | grep 686 | awk -F" " '{print $1}' | awk -F"]" '{print $2}'
rm -rf $file && rm -rf /tmp/pb
}
not_par()
{
if [ "$word" == "" ];
then
echo -e "\nError:\tParameters insufficient: you haven't insert the WORD.\n\tPlease type 'slackpb --help' for more informations!\n"
exit 1
fi
}
if [ "$3" == "" ];
then sv="current"
else sv=$3
fi
case $1 in
"--slack")
word=$2; not_par; category="slackware"
slack_ver && alg
exit 0
;;
"--patches")
word=$2; not_par; category="slackware"
slack_ver && alg
exit 0
;;
"--extra")
word=$2; not_par; category="slackware"
slack_ver && alg
exit 0
;;
"--help")
help
exit 0
;;
"--version")
echo "slackpb $ver"
exit 0
;;
*)
help
exit 0
;;
esac