summaryrefslogtreecommitdiffstats
path: root/bin/reprepro_pull.sh
blob: f9e42f1c2e3c9dda6f5bce278a992442c7e93e71 (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
#!/bin/sh

set -e

HOSTNAME="$(hostname -f)"

_ARCHITECTURE="${1:-amd64}"

if ! ls /mnt/${_ARCHITECTURE}/*.changes > /dev/null 2>&1
then
	echo "E: no changes found in /mnt/${_ARCHITECTURE}"
	exit 1
fi

for _CHANGES in /mnt/${_ARCHITECTURE}/*.changes
do
	if [ -z "${_CHANGES}" ]
	then
		exit 0
	fi

	_SOURCE="$(grep -m1 '^Source: ' ${_CHANGES} | awk '{ print $2 }')"
	_VERSION="$(grep -m1 '^Version: ' ${_CHANGES} | awk '{ print $2 }')"
	_DISTRIBUTION="$(grep -m1 '^Distribution: ' ${_CHANGES} | awk '{ print $2 }')"
	_RELEASE="$(echo ${_DISTRIBUTION} | sed -e 's|-security||' -e 's|-updates||' -e 's|-extras||')"

	if [ -e "/srv/${HOSTNAME}/files/releases/${_RELEASE}/packages/${_SOURCE}/${_VERSION}_${_ARCHITECTURE}" ]
	then
		echo "E: /srv/${HOSTNAME}/files/releases/${_RELEASE}/packages/${_SOURCE}/${_VERSION}_${_ARCHITECTURE} - already exists"
		exit 1
	fi

	mkdir -p "/srv/${HOSTNAME}/files/releases/${_RELEASE}/packages/${_SOURCE}/${_VERSION}_${_ARCHITECTURE}"

	echo "Moving files "

	for _FILE in $(awk '{ print $3 }' ${_CHANGES} | grep -E '(\.dsc$|\.deb$|\.udeb$|\.tar.*$)' | sort -u)
	do
		echo -n "."
		mv /mnt/${_ARCHITECTURE}/${_FILE} "/srv/${HOSTNAME}/files/releases/${_RELEASE}/packages/${_SOURCE}/${_VERSION}_${_ARCHITECTURE}"
	done

	echo " done."

	mv ${_CHANGES} "/srv/${HOSTNAME}/files/releases/${_RELEASE}/packages/${_SOURCE}/${_VERSION}_${_ARCHITECTURE}"

	cd "/srv/${HOSTNAME}/files/releases/${_RELEASE}/packages/${_SOURCE}/${_VERSION}_${_ARCHITECTURE}"
	debsign.sh
done