Tuesday, June 16, 2009

How to acquire URLs of the packages from apt (Debian,Ubuntu)[updated]

Following script will list the URLs of the packages and it's dependencies
1. copy it to apt_urls.sh
2. make it executable chmod +x apt_urls.sh
3. use it ./apt_urls.sh
eg:- ./apt_urls.sh mysql-server



CODE:

#!/bin/bash
if [[ $# = 0 ]]
then
echo "Usage:"
echo "$0 "
exit 0
fi

DEPS="/tmp/deps.list"

function get_urls(){
if [[ $1 == 'upgrade' || $1 == 'dist-upgrade' ]]
then
echo $( apt-get $1 -s | grep Inst | awk '{print $2}') > $DEPS
else
echo $( apt-get install $1 -s | grep Inst | awk '{print $2}') > $DEPS
fi
}

function list_urls(){
for PKG in $( cat $DEPS )
do
PKG_PATH=$( apt-cache show $PKG | grep Filename: | awk '{print $2}' );
PKG_DIR=$( echo $PKG_PATH| awk -F '/' '{print $2}' );
BASE_URL=$( grep ^deb /etc/apt/sources.list | grep $PKG_DIR | awk '{print $2}' );

for URL in $BASE_URL
do
echo $URL/$PKG_PATH
done | sort | uniq
done
}


get_urls $1
list_urls

No comments:

Post a Comment