summaryrefslogtreecommitdiffstats
path: root/bin/pget.sh
blob: d94a12d06f4edb599d74f9db339d36faa4556e68 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh

set -e

case "$(basename ${0})" in
	p*)
		MODE="progress-linux"
		;;

	b*)
		MODE="bfh"
		;;
esac

CURDIR="${PWD}"

DSCS="${@}"

for DSC in ${DSCS}
do
	URL="$(echo ${DSC} | sed -e 's|%2B|+|g' -e 's|%7E|~|g')"

	PACKAGE="$(basename ${URL} .dsc | awk -F_ '{ print $1 }')"

	if [ "$(basename ${PWD})" != "${PACKAGE}" ]
	then
		mkdir -p "${PACKAGE}"
		cd "${PACKAGE}"
	fi

	VERSION="$(wget -q ${URL} -O - | grep -m1 '^Version: ' | awk '{ print $2 }')"

	SOURCE_VERSION="$(echo ${VERSION} | awk -F: '{ print $2 }')"
	SOURCE_VERSION="${SOURCE_VERSION:-${VERSION}}"

	UPSTREAM_VERSION="$(echo ${SOURCE_VERSION} | awk -F- '{ $NF=""; print $0 }' | sed -e 's| |-|g' -e 's|-$||')"

	mkdir "${VERSION}"

	cd "${VERSION}"

	for ORIG in $(ls ../orig/${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.* ../orig/${PACKAGE}_${UPSTREAM_VERSION}.orig-*.tar.* 2>/dev/null)
	do
		if [ -e "${ORIG}" ]
		then
			ln -s "${ORIG}" ./
		fi
	done

	/usr/bin/dget --download-only "${URL}"

	for ORIG in $(ls ${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.* ${PACKAGE}_${UPSTREAM_VERSION}.orig-*.tar.* 2>/dev/null)
	do
		if [ -e "${ORIG}" ] && [ ! -h "${ORIG}" ]
		then
			mkdir -p ../orig
			mv "${ORIG}" ../orig

			ln -s ../orig/"${ORIG}" .
		fi
	done

	cd ..
	rm -f current
	ln -s "${VERSION}" current

	cd "${CURDIR}"
done