summaryrefslogtreecommitdiffstats
path: root/web/update
blob: 20758aee1a7f50060ca2b47ee97aaeaaaead7961 (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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/sh

set -e

RED="\033[1;33;31m"
GREEN="\033[1;33;32m"
YELLOW="\033[1;33;33m"
BLUE="\033[1;33;34m"
WHITE="\033[1;33;37m"
NORMAL="\033[0m"

# FIXME: getopt
# FIXME: -f for forced indices download

MODE="$(basename ${0} | awk -F. '{ print $2 }')"

case "${MODE}" in
	engywuck)
		UPSTREAM_DISTRIBUTIONS="buster buster-updates buster-proposed-updates"
		DOWNSTREAM_DISTRIBUTION="engywuck"
		DOWNSTREAM_MIRROR="https://apt.progress-linux.org/packages"
		DOWNSTREAM_TAG="progress"
		;;

	engywuck-backports)
		UPSTREAM_DISTRIBUTIONS="bullseye bullseye-updates bullseye-proposed-updates"
		DOWNSTREAM_DISTRIBUTION="engywuck-backports"
		DOWNSTREAM_MIRROR="https://apt.progress-linux.org/packages"
		DOWNSTREAM_TAG="progress"
		;;

	fuchur)
		UPSTREAM_DISTRIBUTIONS="bullseye bullseye-updates bullseye-proposed-updates"
		DOWNSTREAM_DISTRIBUTION="fuchur"
		DOWNSTREAM_MIRROR="https://apt.progress-linux.org/packages"
		DOWNSTREAM_TAG="progress"
		;;

	fuchur-backports)
		UPSTREAM_DISTRIBUTIONS="sid experimental"
		DOWNSTREAM_DISTRIBUTION="fuchur-backports"
		DOWNSTREAM_MIRROR="https://apt.progress-linux.org/packages"
		DOWNSTREAM_TAG="progress"
		;;

	graograman)
		#UPSTREAM_DISTRIBUTIONS="bookworm bookworm-updates bookworm-proposed-updates"
		UPSTREAM_DISTRIBUTIONS="sid experimental"
		DOWNSTREAM_DISTRIBUTION="graograman"
		DOWNSTREAM_MIRROR="https://apt.progress-linux.org/packages"
		DOWNSTREAM_TAG="progress"
		;;

	graograman-backports)
		UPSTREAM_DISTRIBUTIONS="sid experimental"
		DOWNSTREAM_DISTRIBUTION="graograman-backports"
		DOWNSTREAM_MIRROR="https://apt.progress-linux.org/packages"
		DOWNSTREAM_TAG="progress"
		;;

	buster)
		UPSTREAM_DISTRIBUTIONS="buster buster-updates buster-proposed-updates"
		DOWNSTREAM_DISTRIBUTION="buster"
		DOWNSTREAM_MIRROR="https://apt.bfh.science/packages"
		DOWNSTREAM_TAG="bfh"
		;;

	buster-backports)
		UPSTREAM_DISTRIBUTIONS="sid experimental"
		DOWNSTREAM_DISTRIBUTION="buster-backports"
		DOWNSTREAM_MIRROR="https://apt.bfh.science/packages"
		DOWNSTREAM_TAG="bfh"
		;;
esac

UPSTREAM_SECTIONS="main contrib non-free"
UPSTREAM_MIRROR="http://debian.ethz.ch/debian"

DOWNSTREAM_SECTIONS="main contrib non-free"

Download_downstream_sources ()
{
	# Download downstream sources
#	if [ -e "downstream.${MODE}.sources" ] && [ "$(( $(stat -c %Y downstream.${MODE}.sources) + ( 4 * 3600 ) ))" -lt "$(date +%s)" ]
#	then
#		# file is older than 4 hours
		rm -f "downstream.${MODE}.sources"
#	fi

	if [ ! -e "downstream.${MODE}.sources" ]
	then
		for SECTION in ${DOWNSTREAM_SECTIONS}
		do
			wget -q -O - "${DOWNSTREAM_MIRROR}/dists/${DOWNSTREAM_DISTRIBUTION}/${SECTION}/source/Sources.xz" | xz -d >> "downstream.${MODE}.sources"
		done
	fi
}

Download_upstream_sources ()
{
	# Download upstream sources
	if [ -e "upstream.${MODE}.sources" ] && [ "$(( $(stat -c %Y upstream.${MODE}.sources) + ( 4 * 3600 ) ))" -lt "$(date +%s)" ]
	then
		# file is older than 4 hours
		rm -f "upstream.${MODE}.sources"
	fi

	if [ ! -e "upstream.${MODE}.sources" ]
	then
		for DISTRIBUTION in ${UPSTREAM_DISTRIBUTIONS}
		do
			case "${DISTRIBUTION}" in
				*-*)
					;;

				*)
					if wget -q -O /dev/null "http://security.debian.org/dists/${DISTRIBUTION}/updates/Release"
					then
						for SECTION in ${UPSTREAM_SECTIONS}
						do
							wget -q -O - "http://security.debian.org/dists/${DISTRIBUTION}/updates/${SECTION}/source/Sources.xz" | xz -d >> "upstream.${MODE}.sources"
						done
					fi

					if wget -q -O /dev/null "http://security.debian.org/dists/${DISTRIBUTION}-security/Release"
					then
						for SECTION in ${UPSTREAM_SECTIONS}
						do
							wget -q -O - "http://security.debian.org/dists/${DISTRIBUTION}-security/${SECTION}/source/Sources.xz" | xz -d >> "upstream.${MODE}.sources"
						done
					fi
					;;
			esac

			for SECTION in ${UPSTREAM_SECTIONS}
			do
				wget -q -O - "${UPSTREAM_MIRROR}/dists/${DISTRIBUTION}/${SECTION}/source/Sources.xz" | xz -d >> "upstream.${MODE}.sources"
			done
		done
	fi
}

Download_downstream_sources
Download_upstream_sources

# Process downstream sources
DOWNSTREAM_PACKAGES="$(awk '/^Package: / { print $2 }' downstream.${MODE}.sources | sort -u)"

echo "################################################################################"
echo "${DOWNSTREAM_DISTRIBUTION}"
echo "################################################################################"

echo -n "Comparing versions... "

for PACKAGE in ${DOWNSTREAM_PACKAGES}
do
	DOWNSTREAM_VERSION="$(sed -n "/^Package: ${PACKAGE}$/,/^Version:/p" downstream.${MODE}.sources | awk '/^Version: / { print $2 }')"
	UPSTREAM_VERSION="$(sed -n "/^Package: ${PACKAGE}$/,/^Version:/p" upstream.${MODE}.sources | awk '/^Version: / { print $2 }' | sort -rV | head -n1)"

	if echo ${UPSTREAM_VERSION} | grep -qs '-'
	then
		# package is non-native
		DOWNSTREAM="$(echo ${DOWNSTREAM_VERSION} | sed -e "s|~${DOWNSTREAM_TAG}.*||" -e "s|${DOWNSTREAM_TAG}.*||")"
	else
		# package is native
		DOWNSTREAM="$(echo ${DOWNSTREAM_VERSION} | sed -e "s|-0.0~${DOWNSTREAM_TAG}.*||" -e "s|-0.*${DOWNSTREAM_TAG}.*||")"
	fi

	if grep -qs "^${PACKAGE} ${UPSTREAM_VERSION}$" ignore.txt
	then
		continue
	fi

	if [ -z "${UPSTREAM_VERSION}" ] && grep -qs "^${PACKAGE} ${DOWNSTREAM_VERSION}$" ignore.txt
	then
		continue
	fi

	if [ -z "${UPSTREAM_VERSION}" ]
	then
		echo "${BLUE}${PACKAGE}${NORMAL} '!${DOWNSTREAM_VERSION}'"
		continue
	fi

	# comparing versions
	if dpkg --compare-versions ${UPSTREAM_VERSION} eq ${DOWNSTREAM}
	then
		echo -n "."
	elif dpkg --compare-versions ${UPSTREAM_VERSION} gt ${DOWNSTREAM}
	then
		echo "${RED}${PACKAGE}${NORMAL} '${UPSTREAM_VERSION} >> ${DOWNSTREAM_VERSION}'"
	elif dpkg --compare-versions ${UPSTREAM_VERSION} lt ${DOWNSTREAM}
	then
		echo "${YELLOW}${PACKAGE}${NORMAL} '${UPSTREAM_VERSION} << ${DOWNSTREAM_VERSION}'"
	else
		echo "${PACKAGE}: internal error"
	fi
done

echo " done."