summaryrefslogtreecommitdiffstats
path: root/docs/changelogs.example
blob: 22ec3f915cc2251e1aae8e9f2556a03f5e8b697a (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/sh
# This is an example script that can be hooked into reprepro
# to either generate a hierarchy like packages.debian.org/changelogs/
# or to generate changelog files in the "third party sites"
# location apt-get changelogs looks if it is not found in
# Apt::Changelogs::Server.
#
# All you have to do is to:
# - copy it into you conf/ directory,
# - if you want "third party site" style changelogs, edit the
#   CHANGELOGDIR variable below,
# and
# - add the following to any distribution in conf/distributions
#   you want to have changelogs and copyright files extracted:
#Log:
# --type=dsc changelogs.example
# (note the space at the beginning of the second line).
# This will cause this script to extract changelogs for all
# newly added source packages. (To generate them for already
# existing packages, call "reprepro rerunnotifiers").

# DEPENDENCIES: dpkg >= 1.13.9

if test "x${REPREPRO_OUT_DIR:+set}" = xset ; then
	# Note: due to cd, REPREPRO_*_DIR will no longer
	# be usable. And only things relative to outdir will work...
	cd "${REPREPRO_OUT_DIR}" || exit 1
else
	# this will also trigger if reprepro < 3.5.1 is used,
	# in that case replace this with a manual cd to the
	# correct directory...
	cat "changelog.example needs to be run by reprepro!" >&2
	exit 1
fi

# CHANGELOGDIR set means generate full hierarchy
# (clients need to set Apt::Changelogs::Server to use that)
CHANGELOGDIR=changelogs

# CHANGELOGDIR empty means generate changelog (and only changelog) files
# in the new "third party site" place apt-get changelog is using as fallback:
#CHANGELOGDIR=

# Set to avoid using some predefined TMPDIR or even /tmp as
# tempdir:

# TMPDIR=/var/cache/whateveryoucreated

if test -z "$CHANGELOGDIR" ; then
addsource() {
	DSCFILE="$1"
	CANONDSCFILE="$(readlink --canonicalize "$DSCFILE")"
	CHANGELOGFILE="${DSCFILE%.dsc}.changelog"
	BASEDIR="$(dirname "$CHANGELOGFILE")"
	if ! [ -f "$CHANGELOGFILE" ] ; then
		EXTRACTDIR="$(mktemp -d)"
		(cd -- "$EXTRACTDIR" && dpkg-source --no-copy -x "$CANONDSCFILE" > /dev/null)
		install --mode=644 -- "$EXTRACTDIR"/*/debian/changelog "$CHANGELOGFILE"
		chmod -R u+rwX -- "$EXTRACTDIR"
		rm -r -- "$EXTRACTDIR"
	fi
	if [ -L "$BASEDIR"/current."$CODENAME" ] ; then
		# should not be there, just to be sure
		rm -f -- "$BASEDIR"/current."$CODENAME"
	fi
	# mark this as needed by this distribution
	ln -s -- "$(basename "$CHANGELOGFILE")" "$BASEDIR/current.$CODENAME"
	JUSTADDED="$CHANGELOGFILE"
}
delsource() {
	DSCFILE="$1"
	CHANGELOGFILE="${DSCFILE%.dsc}.changelog"
	BASEDIR="$(dirname "$CHANGELOGFILE")"
	BASENAME="$(basename "$CHANGELOGFILE")"
	if [ "x$JUSTADDED" = "x$CHANGELOGFILE" ] ; then
		exit 0
	fi
#	echo "delete, basedir=$BASEDIR changelog=$CHANGELOGFILE, dscfile=$DSCFILE, "
 	if [ "x$(readlink "$BASEDIR/current.$CODENAME")" = "x$BASENAME" ] ; then
 		rm -- "$BASEDIR/current.$CODENAME"
 	fi
 	NEEDED=0
 	for c in "$BASEDIR"/current.* ; do
 		if [ "x$(readlink -- "$c")" = "x$BASENAME" ] ; then
 			NEEDED=1
 		fi
 	done
 	if [ "$NEEDED" -eq 0 -a -f "$CHANGELOGFILE" ] ; then
 		rm -r -- "$CHANGELOGFILE"
		# to remove the directory if now empty
		rmdir --ignore-fail-on-non-empty -- "$BASEDIR"
 	fi
}

else # "$CHANGELOGDIR" set:

addsource() {
	DSCFILE="$1"
	CANONDSCFILE="$(readlink --canonicalize "$DSCFILE")"
	TARGETDIR="${CHANGELOGDIR}/${DSCFILE%.dsc}"
	SUBDIR="$(basename $TARGETDIR)"
	BASEDIR="$(dirname $TARGETDIR)"
	if ! [ -d "$TARGETDIR" ] ; then
		#echo "extract $CANONDSCFILE information to $TARGETDIR"
		mkdir -p -- "$TARGETDIR"
		EXTRACTDIR="$(mktemp -d)"
		(cd -- "$EXTRACTDIR" && dpkg-source --no-copy -x "$CANONDSCFILE" > /dev/null)
		install --mode=644 -- "$EXTRACTDIR"/*/debian/copyright "$TARGETDIR/copyright"
		install --mode=644 -- "$EXTRACTDIR"/*/debian/changelog "$TARGETDIR/changelog"
		chmod -R u+rwX -- "$EXTRACTDIR"
		rm -r -- "$EXTRACTDIR"
	fi
	if [ -L "$BASEDIR"/current."$CODENAME" ] ; then
		# should not be there, just to be sure
		rm -f -- "$BASEDIR"/current."$CODENAME"
	fi
	# mark this as needed by this distribution
	ln -s -- "$SUBDIR" "$BASEDIR/current.$CODENAME"
	JUSTADDED="$TARGETDIR"
}
delsource() {
	DSCFILE="$1"
	TARGETDIR="${CHANGELOGDIR}/${DSCFILE%.dsc}"
	SUBDIR="$(basename $TARGETDIR)"
	BASEDIR="$(dirname $TARGETDIR)"
	if [ "x$JUSTADDED" = "x$TARGETDIR" ] ; then
		exit 0
	fi
#	echo "delete, basedir=$BASEDIR targetdir=$TARGETDIR, dscfile=$DSCFILE, "
 	if [ "x$(readlink "$BASEDIR/current.$CODENAME")" = "x$SUBDIR" ] ; then
 		rm -- "$BASEDIR/current.$CODENAME"
 	fi
 	NEEDED=0
 	for c in "$BASEDIR"/current.* ; do
 		if [ "x$(readlink -- "$c")" = "x$SUBDIR" ] ; then
 			NEEDED=1
 		fi
 	done
 	if [ "$NEEDED" -eq 0 -a -d "$TARGETDIR" ] ; then
 		rm -r -- "$TARGETDIR"
		# to remove the directory if now empty
		rmdir --ignore-fail-on-non-empty -- "$BASEDIR"
 	fi
}
fi # CHANGELOGDIR

ACTION="$1"
CODENAME="$2"
PACKAGETYPE="$3"
if [ "x$PACKAGETYPE" != "xdsc" ] ; then
# the --type=dsc should cause this to never happen, but better safe than sorry.
	exit 1
fi
COMPONENT="$4"
ARCHITECTURE="$5"
if [ "x$ARCHITECTURE" != "xsource" ] ; then
	exit 1
fi
NAME="$6"
shift 6
JUSTADDED=""
if [ "x$ACTION" = "xadd" -o "x$ACTION" = "xinfo" ] ; then
	VERSION="$1"
	shift
	if [ "x$1" != "x--" ] ; then
		exit 2
	fi
	shift
	while [ "$#" -gt 0 ] ; do
		case "$1" in
			*.dsc)
				addsource "$1"
				;;
			--)
				exit 2
				;;
		esac
		shift
	done
elif [ "x$ACTION" = "xremove" ] ; then
	OLDVERSION="$1"
	shift
	if [ "x$1" != "x--" ] ; then
		exit 2
	fi
	shift
	while [ "$#" -gt 0 ] ; do
		case "$1" in
			*.dsc)
				delsource "$1"
				;;
			--)
				exit 2
				;;
		esac
		shift
	done
elif [ "x$ACTION" = "xreplace" ] ; then
	VERSION="$1"
	shift
	OLDVERSION="$1"
	shift
	if [ "x$1" != "x--" ] ; then
		exit 2
	fi
	shift
	while [ "$#" -gt 0 -a "x$1" != "x--" ] ; do
		case "$1" in
			*.dsc)
				addsource "$1"
			;;
		esac
		shift
	done
	if [ "x$1" != "x--" ] ; then
		exit 2
	fi
	shift
	while [ "$#" -gt 0 ] ; do
		case "$1" in
			*.dsc)
				delsource "$1"
				;;
			--)
				exit 2
				;;
		esac
		shift
	done
fi

exit 0
# Copyright 2007,2008,2012 Bernhard R. Link <brlink@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1301  USA