2007-11-20 00:21:41 +01:00
|
|
|
#!/bin/bash
|
2008-02-22 20:24:38 +01:00
|
|
|
# Copyright (C) 2008 Terence Simpson <tsimpson@ubuntu.com>
|
2008-01-17 19:43:26 +01:00
|
|
|
# Modified by Siegfried-A. Gevatter <rainct@ubuntu.com>
|
2008-02-22 20:24:38 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
2008-02-22 20:24:38 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# See file /usr/share/common-licenses/GPL for more details.
|
|
|
|
#
|
|
|
|
# ##################################################################
|
2007-11-20 00:21:41 +01:00
|
|
|
#
|
|
|
|
# This script simulates «dget»'s behaviour for files hosted at
|
|
|
|
# launchpadlibrarian.net.
|
|
|
|
#
|
|
|
|
# Detailed description:
|
|
|
|
# This script attempts to download the source package in the same
|
|
|
|
# way as dget does, but from launchpadlibrarian.net, which doesn't
|
|
|
|
# store all the files in the same directory. It (the script) assumes
|
|
|
|
# that the files are stored in sequential directories on Launchpad
|
|
|
|
# Librarian and attemps to download and then unpack them.
|
|
|
|
|
|
|
|
GET="wget"
|
|
|
|
UNPACK="dpkg-source -x {dsc-file}"
|
2008-02-22 20:24:38 +01:00
|
|
|
DIRECT_TO_NULL="/dev/null"
|
2007-11-20 00:21:41 +01:00
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat << EOF
|
|
|
|
Usage: $0 [-d] <Launchpad URL>
|
|
|
|
|
2008-08-27 11:21:36 -04:00
|
|
|
This scripts simulates «dget»'s behaviour for files hosted at
|
2007-11-20 00:21:41 +01:00
|
|
|
launchpadlibrarian.net.
|
|
|
|
|
2008-02-22 20:24:38 +01:00
|
|
|
If you specify the -d option then it won't do anything, except download the
|
|
|
|
.dsc file, but just print the commands it would run otherwise.
|
2007-11-20 00:21:41 +01:00
|
|
|
|
|
|
|
Example:
|
2008-02-22 20:24:38 +01:00
|
|
|
$(basename $0) http://launchpadlibrarian.net/10348157/coreutils_5.97-5.4ubuntu1.dsc
|
2007-11-20 00:21:41 +01:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2008-02-22 20:24:38 +01:00
|
|
|
while [ $# -ne 1 ]; do
|
|
|
|
case "$1" in
|
|
|
|
-d|--debug)
|
|
|
|
# Debug Mode
|
|
|
|
OUTPUT="/tmp/"
|
|
|
|
GET="echo ${GET}"
|
|
|
|
UNPACK="echo ${UNPACK}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-v|--verbose)
|
|
|
|
DIRECT_TO_NULL="$(tty)"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
echo "Unknown option: \`$1'"
|
|
|
|
usage >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $# -ne 1 ]
|
2007-11-20 00:21:41 +01:00
|
|
|
then
|
2008-02-22 20:24:38 +01:00
|
|
|
usage
|
|
|
|
exit 1
|
2007-11-20 00:21:41 +01:00
|
|
|
fi
|
|
|
|
|
2008-02-22 20:24:38 +01:00
|
|
|
## internal functions
|
|
|
|
getBase() {
|
|
|
|
echo "Getting ${BASE}/${NUMBER}/${FILE}"
|
|
|
|
if [ -f "$FILE" ]; then rm -f $FILE; fi # Remove .dsc incase the last run was with debug
|
|
|
|
if ! wget ${BASE}/${NUMBER}/${FILE} -O ${OUTPUT}${FILE} 2>${DIRECT_TO_NULL}
|
2007-11-24 01:04:24 +01:00
|
|
|
then
|
2008-02-22 20:24:38 +01:00
|
|
|
echo "Failed to fetch «.dsc» file, aborting."
|
|
|
|
exit 1
|
2007-11-24 01:04:24 +01:00
|
|
|
fi
|
2008-02-22 20:24:38 +01:00
|
|
|
}
|
2007-11-24 01:04:24 +01:00
|
|
|
|
2008-02-22 20:24:38 +01:00
|
|
|
getUrl() {
|
|
|
|
if [ -f "$2" ]
|
2007-11-20 00:21:41 +01:00
|
|
|
then
|
2008-02-22 20:24:38 +01:00
|
|
|
##Todo: Check the md5sum in the .dsc to see if we should redownload or not
|
|
|
|
echo "Skipping already downloaded ${2}"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Getting ${1}${2}"
|
|
|
|
if ! $GET ${1}${2} 2>$DIRECT_TO_NULL
|
|
|
|
then
|
|
|
|
echo "Failed to fetch «${3}»"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
unpack() {
|
|
|
|
if ! $UNPACK
|
|
|
|
then
|
|
|
|
echo "Failed to unpack source, aborting."
|
2007-11-20 00:21:41 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2008-02-22 20:24:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
## begin #!/bin/bash
|
2007-11-20 00:21:41 +01:00
|
|
|
|
|
|
|
# Store download URL into a local variable to be able to modify it
|
|
|
|
URL=$1
|
|
|
|
|
|
|
|
if [ ${URL:0:4} == 'www.' ]
|
|
|
|
then
|
|
|
|
URL="http://"${URL:4}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${URL:0:7} != 'http://' ]
|
|
|
|
then
|
|
|
|
URL="http://"$URL
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${URL:0:30} != 'http://launchpadlibrarian.net/' ]
|
|
|
|
then
|
|
|
|
echo "Error: This utility only works for files on launchpadlibrarian.net."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${URL##*.} != 'dsc' ]
|
|
|
|
then
|
|
|
|
echo "You have to provide the URL for the .dsc file."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2008-02-22 20:24:38 +01:00
|
|
|
#BASE="http://$(echo $URL|cut -d '/' -f 3)" #Not needed as we know the base URL
|
|
|
|
BASE="http://launchpadlibrarian.net"
|
2007-11-20 00:21:41 +01:00
|
|
|
NUMBER="$(echo $URL|cut -d '/' -f 4)"
|
|
|
|
FILE="$(echo $URL|cut -d '/' -f 5)"
|
|
|
|
|
|
|
|
UNPACK=$(echo $UNPACK | sed s/{dsc-file}/${FILE}/g)
|
|
|
|
|
2008-02-22 20:24:38 +01:00
|
|
|
if [ -f "$FILE" ]; then rm -f $FILE; fi
|
|
|
|
getBase;
|
|
|
|
PkgVersion="$(grep -B100 "^Files:" ${OUTPUT}${FILE}|grep "^Version:"|cut -d' ' -f2)"
|
|
|
|
PkgName="$(grep -B100 "^Files:" ${OUTPUT}${FILE}|grep "^Source:"|cut -d' ' -f2)"
|
2007-11-20 00:21:41 +01:00
|
|
|
|
2008-02-22 20:24:38 +01:00
|
|
|
if $(echo ${PkgVersion} | grep '-' >/dev/null)
|
2007-11-20 00:21:41 +01:00
|
|
|
then
|
2008-02-22 20:24:38 +01:00
|
|
|
getUrl ${BASE}/$((${NUMBER}-1))/ "$(echo $FILE|sed 's,\.dsc,.diff.gz,')" "diff.gz"
|
|
|
|
getUrl ${BASE}/$((${NUMBER}-2))/ "${PkgName}_$(echo ${PkgVersion}|sed 's,-[0-9]*[a-z]*[0-9]*,.orig.tar.gz,')" "orig.tar.gz"
|
|
|
|
else
|
|
|
|
getUrl ${BASE}/$((${NUMBER}-1))/ "${PkgName}_${PkgVersion}.tar.gz" "tar.gz"
|
2007-11-20 00:21:41 +01:00
|
|
|
fi
|
|
|
|
|
2008-02-22 20:24:38 +01:00
|
|
|
if [ "x${OUTPUT}" != "x" ]
|
|
|
|
then rm -f ${OUTPUT}${FILE}
|
2007-11-20 00:21:41 +01:00
|
|
|
fi
|
|
|
|
|
2008-02-22 20:24:38 +01:00
|
|
|
unpack;
|