e-file 根据文件名查询gentoo包的脚本
一直想在gentoo下实现一个类似ubuntu的apt-file的功能,幸好已经有 http://www.portagefilelist.de 这个网站了,就花了2小时写了个小脚本直接到这个站取数据了,感觉效果还可以,先发出来,算是预览版吧,以后会再完善的.
输出格式参考了 eix ,代码如下:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #!/bin/sh #AUTHOR: bones7456 (bones7456<at>gmail<dot>com) #VERSION: 20081120 ##License: GPL #e-file is like apt-file for gentoo, but data is online if [[ $# -ne 1 ]];then 	echo "Usage: `basename $0` filename" 	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 } { 	if($1=="dir" && $2=="package"){ 		FLAG=1 		next 	} 	if($1=="Retrieved" && $2=="from"){ 		if(FOUND){ 			for(i in ver){ 				split(i,ii,/\//) 				printf("%c[%d;%d;%dm* ",27,2,0,32) 				printf("%c[0m%s/",27,ii[1]) 				printf("%c[%d;%d;%dm%s\n",27,2,1,29,ii[2]) 				printf("%c[%d;%d;%dm\t",27,2,0,32) 				printf("Available versions:\t%s\n",ver[i]) 				printf("\tMatched File:\t\t") 				printf("%c[0m",27) 				printf("%s\n\n",file[i]) 			} 		}else{ 			print "No matches found." 		} 		exit 	} 	if(FLAG==1 && NF!=0){ 		ver[$1 "/" $2]=$NF " " ver[$1 "/" $2] 		file[$1 "/" $2]=$3 "/" $4 		FOUND=1 	} }' | 
截个图:

脚本下载地址
oceanboo 在 2008年11月20日 21:25 说:【 】
骨头,我太崇拜你了。
bones7456 在 2008年11月20日 23:51 说:【 】
哈哈,这个简陋的脚本貌似还挺受欢迎的,发出10个小时已经在gentoo-china overlay里面了.
cbkid 在 2008年11月21日 14:43 说:【 】
顶一下你,还不知道overlay呢,很厉害的东西呢。。。。
bones7456 : 更新了e-file 在 2008年11月25日 13:46 说:【 】
[…] 上的 bones7456给 iPod 转视频的脚本 上的 drivel给 iPod 转视频的脚本 上的 drivele-file 根据文件名查询gentoo包的脚本 上的 […]
xiooli 在 2008年12月27日 15:05 说:【 】
骨头的awk貌似很娴熟阿,呵呵,看起来awk很强悍的样子,我awk就会点基本的,看来得花点时间学学awk了:)