I am LAZY bones? AN ancient AND boring SITE

2008年 11月 25日 的归档

更新了e-file

之前发布的e-file,看起来好像还是挺受欢迎的,没多久,就有人给写了ebuild文件,进了gentoo-china overlay.于是打算再稍微完善一下.
周末去了趟上海,也没空更新这个脚本,拖到今天,终于弄好了,呵呵.
ChangeLog:

20081125:
优化代码结构
增加本地已安装版本的显示
增加Homepage和Description的显示

老套路,贴代码和截图:

#!/bin/sh
#AUTHOR: bones7456 (bones7456<at>gmail<dot>com)
##License: GPL
#e-file is like apt-file for gentoo, but data is online
VERSION=20081125
 
function printhelp(){
cat <<EOF
This is e-file ($VERSION)
	Usage: `basename $0` filename
EOF
}
if [[ $# -ne 1 ]];then
	printhelp
	exit 1
fi
 
URL="http://www.portagefilelist.de/index.php/Special:PFLQuery2?file=$1&searchfile=lookup&lookup=file#result"
 
w3m -dump -cols 3000 $URL | awk '
BEGIN{
	FLAG=0
	FOUND=0
	"emerge --info | grep PORTDIR" | getline
	split($0,PORTDIR,/\"/)
}
{
	if($1=="dir" && $2=="package"){
		FLAG=1
		next
	}
	if($1=="Retrieved" && $2=="from"){
		if(FOUND){
			for(pkg in vers){
				split(pkg,ii,/\//)
				NF=0
				cmd="ls -tgGd --time-style=+%c /var/db/pkg/" pkg "* 2>/dev/null"
				cmd | getline
				if(NF==0){
					installed=0
				}else{
					installed=1
					install_time=""
					for(i=4;i<NF;i++)install_time=install_time " " $i
					install_time=substr(install_time,2)
					split($NF,install_arr,pkg "-")
				}
				NF=0
				cmd="(grep -h HOMEPAGE " PORTDIR[2] "/" pkg "/*.ebuild | tail -n 1)2>/dev/null"
				cmd | getline
				if(NF==0){
					HOMEPAGE=""
				}else{
					split($0,tempArr,/\"/)
					HOMEPAGE=tempArr[2]
				}
				NF=0
				cmd="(grep -h DESCRIPTION " PORTDIR[2] "/" pkg "/*.ebuild | tail -n 1)2>/dev/null"
				cmd | getline
				if(NF==0){
					DESCRIPTION=""
				}else{
					split($0,tempArr,/\"/)
					DESCRIPTION=tempArr[2]
				}
 
				setcolor(1,32)
				if(installed){
					printf("[I] ")
				}else{
					printf(" *  ")
				}
				clearcolor()
				printf("%s/",ii[1])
				setcolor(1,29)
				printf("%s\n",ii[2])
				setcolor(0,32)
				printf("\tAvailable Versions:\t%s\n",vers[pkg])
				if(installed){
					printf("\tLast Installed Ver:\t")
					setcolor(7,34)
					printf("%s",install_arr[2])
					setcolor(0,35)
					printf("(%s)\n",install_time)
					setcolor(0,32)
				}
				if(HOMEPAGE){
					printf("\tHomepage:\t\t")
					clearcolor()
					printf("%s\n",HOMEPAGE)
					setcolor(0,32)
				}
				if(DESCRIPTION){
					printf("\tDescription:\t\t")
					clearcolor()
					printf("%s\n",DESCRIPTION)
					setcolor(0,32)
				}
				printf("\tMatched Files:\t\t")
				clearcolor()
				printf("%s\n\n",files[pkg])
			}
		}else{
			print "No matches found."
		}
		exit
	}
	if(FLAG==1 && NF!=0){
		T=1
		split(vers[$1 "/" $2],vers_arr,/ /)
		for(i in vers_arr){
			if(vers_arr[i]==$NF){
				T=0
				break
			}
		}
		if(T)vers[$1 "/" $2]=$NF " " vers[$1 "/" $2]
		T=1
		split(files[$1 "/" $2],files_arr,/; /)
		for(i in files_arr){
			if(files_arr[i]==($3 "/" $4)){
				T=0
				break
			}
		}
		if(T)files[$1 "/" $2]=$3 "/" $4 "; " files[$1 "/" $2]
		FOUND=1
	}
}
function setcolor(a,b){
printf("%c[%d;%d;%dm",27,2,a,b)
}
function clearcolor(){
printf("%c[0m",27)
}
'


从图中看到的,其实 portagefilelist.de 的数据也是比较旧的,sys-process/dcron的版本还停留在 2.9 的年代,而本地安装的,早已经是 3.2 了.
脚本下载地址