summaryrefslogtreecommitdiffstats
path: root/bin/pmove.sh
blob: 225c94ac881f53a10ad6a1527849adf2abe508b0 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/sh

set -e

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

	b*)
		MODE="bfh"
		;;
esac

CURDIR="${PWD}"

HOST="$(hostname -f)"
UPLOAD="/srv/${HOST}/upload"

for ARCHITECTURE in amd64 arm64 armel armhf i386 all
do
	if ! ls ${UPLOAD}/*_${ARCHITECTURE}.changes > /dev/null 2>&1
	then
		continue
	fi

	CHANGES="$(ls ${UPLOAD}/*_${ARCHITECTURE}.changes | sort -V)"

	for CHANGE in ${CHANGES}
	do
		FILES="$(sed -e '1,/^Files:$/ d' ${CHANGE} | sed -e '/^[0-1a-zA-Z]/,$d' | awk '{ print $5 }')"

		CONTINUE="false"
		for FILE in ${FILES}
		do
			if [ ! -e "${UPLOAD}/${FILE}" ]
			then
				CONTINUE="true"
				break
			fi
		done

		case "${CONTINUE}" in
			true)
				echo "$(basename ${CHANGE}): incomplete upload, ${FILE} is missing."
				continue
				;;
		esac

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

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

		VERSION="$(grep -m1 '^Version: ' ${CHANGE} | 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}_${ARCHITECTURE}"

		cd "${VERSION}_${ARCHITECTURE}"

		for FILE in ${FILES} ${CHANGE}
		do
			mv "${UPLOAD}/$(basename ${FILE})" .
		done

		if ls *_${ARCHITECTURE}.buildinfo > /dev/null 2>&1
		then
			# FIXING buildinfo file
			sed -i	-e '/^ DEB_BUILD_OPTIONS="/d' \
				-e 's|^ LANG="en_US.UTF-8"| LANG="C.UTF-8"|' \
			*_${ARCHITECTURE}.buildinfo
		fi

		reprepro_fix-changes.sh *_${ARCHITECTURE}.changes

		case "${MODE}" in
			progress-linux)
				psign.sh
				;;

			bfh)
				bsign.sh
				;;
		esac

		cd ..
		rm -f current_${ARCHITECTURE}
		ln -s "${VERSION}_${ARCHITECTURE}" current_${ARCHITECTURE}

		cd "${CURDIR}"
	done
done

if ls ${UPLOAD}/*.dsc > /dev/null 2>&1
then
	DSCs="$(ls ${UPLOAD}/*.dsc | sort -V)"

	for DSC in ${DSCs}
	do
		if [ ! -e "${DSC}" ]
		then
			break
		fi

		FILES="$(sed -e '1,/^Files:$/ d' ${DSC} | sed -e '/^[0-1a-zA-Z]/,$d' | awk '{ print $3 }')"

		CONTINUE="false"
		for FILE in ${FILES}
		do
			if [ ! -e "${UPLOAD}/${FILE}" ]
			then
				CONTINUE="true"
				break
			fi
		done

		case "${CONTINUE}" in
			true)
				echo "$(basename ${DSC}): incomplete upload, ${FILE} is missing."
				continue
				;;
		esac

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

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

		VERSION="$(grep -m1 '^Version: ' ${DSC} | 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}_source"
		cd "${VERSION}_source"

		for FILE in ${FILES} ${DSC}
		do
			mv "${UPLOAD}/$(basename ${FILE})" .

			if [ -e ../orig/${FILE} ]
			then
				ln -sf ../orig/${FILE} ${FILE}
			fi
		done

		case "${MODE}" in
			progress-linux)
				psign.sh
				;;

			bfh)
				bsign.sh
				;;
		esac

		if ls ${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.xz > /dev/null 2>&1 && \
		   [ ! -h "${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.xz" ]
		then
			mkdir -p ../orig

			mv "$(ls ${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.*)" ../orig
			ln -s $(ls ../orig/${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.*) ./
		fi

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

		cd "${CURDIR}"
	done
fi