0x00
最近在编译xxxx时,发现有个configure时提示缺少某个模块,google了一把,找到了对应的包,apt下就解决了。
但是感觉每次都google挺搓的,所以就写了一个脚本,用于反查包名。如果有更好的方法,希望不吝赐教。
0x01
代码如下:
#!/bin/bash
function printHelp()
{
echo "Usage:"
echo "this script depends on aptitude , apt-file and awk"
echo $0 "pack_name_pattern component_pattern_name"
echo "for example:$0 xml2 xml2-config"
}
if [ $# -lt 2 ];then
printHelp
exit 0
fi
echo "Start update apt file"
exec 3>&1
apt-file update 1>&null
exec 1>&3
echo "Finish update apt file"
pl=$(aptitude search $1 | awk '{print $2}')
plarr=("$pl")
for item in $plarr
do
echo $(apt-file list "$item") | grep $2 > null
if [ $? -eq 0 ];then
echo "candidate:$item"
fi
done
0x02
核心原理是利用aptitude先根据包的名字不完全匹配,再利用apt-file列出包中所有模块。再和模块名做匹配。
注意apt-file不能使用 dpkg -L 代替,因为dpkg只能列出已安装的包。
0x03
脚本有两个比较大的限制:
1.包名比较能做不完全匹配,如果包名猜的有问题,就会导致找不到准确的包名;
2.apt-file更新和查找速度比较忙。