开发者

Bash / apt - check package version before installation

The command "dpkg" has the option "-E" or "--skip-same-version" in order not to install a package if its same version is already installed.

From what I know "apt-get" does not have anything similar.

So I came up with this:

Installed=`sudo apt-开发者_开发技巧cache policy openjdk-6-jre | sed -n '2p' | cut -c 14-` #6b20-1.9.9-0ubuntu1~10.04.2
Candidate=`sudo apt-cache policy openjdk-6-jre | sed -n '3p' | cut -c 14-` #6b20-1.9.9-0ubuntu1~10.04.2

if [ "$Installed" -ne "$Candidate" ]; then 
    apt-get -fy install openjdk-6-jre
elif [ "$Installed" -eq "$Candidate" ]; then 
    echo 'Candidate version already installed.'
fi

My question: is there any other easier way of doing this? I am trying to use this information inside a bash script so that everything happens automatically...

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜