Debian Codegraph @

malai-core/org.malai.core/src/debian/repackage

raw symbols SCIP
1 #!/bin/sh
2
3 set -u
4 set -e
5 # set -x
6
7 if [ -f ~/.devscripts ]
8 then
9 . ~/.devscripts
10 fi
11
12 PACKAGE=frobinator
13 UPSTREAM=sourceforge.net
14
15 UNARCHIVE=do_unzip
16 WRAPDIR=true
17
18 LOG=README.Debian-source
19
20 VERBOSE=${VERBOSE:-1}
21 CLEANUP=${CLEANUP:-0}
22
23 SCRIPTDIR=$(dirname $(readlink -f $0))
24
25 NAME=$(basename $0)
26 RCFILE=$SCRIPTDIR/repackagerc
27
28 EXCLUDE_LIST=""
29 # Originally '197001010000.00' but tar complains about an
30 # "implausibly old time stamp"
31 TOUCHTIME=199001010000.00
32
33 # Set a consistent umask for repackaging so that the tarball is reproducible
34 # (overridable in the rc file)
35 umask 002
36
37 usage() {
38 cat <<EOT 1>&2
39 Usage: $NAME --upstream-version x.y.z filename.zip
40 [src_package_revision] [target_dir]
41
42 Where the the version x.y.z is the version number of the new version and
43 filename.zip (or .tar.gz or whatever) is the new source filename for the
44 package $PACKAGE.
45
46 If filename.zip starts with http:// or ftp:// then wget is used to download
47 the archive first.
48
49 The file $RCFILE must exist and set the following environment variables
50 (and these are their current versions):
51
52 PACKAGE=$PACKAGE
53 UPSTREAM=$UPSTREAM
54
55 UNARCHIVE=$UNARCHIVE
56 EXCLUDE_LIST=$EXCLUDE_LIST
57
58 (EXCLUDE_LIST is a list of exclusions for tar, one per line. Note that
59 spaces in path names are problematic)
60
61 It is expected that this utility is run by uscan or and is run in the
62 base directory of the source package.
63
64 The optional argument 'src_package_revision' can be specified to
65 indicate additional cycles of source package revision that may have
66 been undertaken in addition to the regular packaging activities.
67 If not specified, the debian/changelog is parsed to try to work out what
68 the source revision should be.
69
70 The optional argument 'target_dir' may be used to specify where the repackaged
71 source should be left.
72
73 EOT
74 }
75
76 progress() {
77 if [ "$VERBOSE" != 0 -a -n $VERBOSE ]
78 then
79 echo "$@"
80 fi
81 }
82
83 logmsg() {
84 echo "$@" >> $LOGFILE
85 }
86
87 logcmd() {
88 logcmdpieces "$@"
89 "$@" >> $LOGFILE
90 }
91
92 # This is a truly appalling hack, but the only sensible way to
93 # maintain proper quoting in the log, it seems, unless each command is
94 # double quoted to begin with... which is also an ugly, bug-attracting
95 # hack.
96 logcmdpieces() {
97 printf "\n$ " >> $LOGFILE
98 echo "$@" >> $LOGFILE
99 }
100
101 carp() {
102 echo "E: ($NAME) $*"
103 exit 1
104 }
105
106 do_unzip() {
107 logcmd unzip -qq -d "$1" "$2"
108 }
109
110 do_untargz() {
111 logcmd tar -C "$1" -zxf "$2"
112 }
113
114 do_untarbz2() {
115 logcmd tar -C "$1" -jxf "$2"
116 }
117
118 testarchive() {
119 case "$1" in
120 do_unzip)
121 ALLDIRS=$(zipinfo -1 "$2" | cut -f1 -d/ | sort -u)
122 if [ $(echo "$ALLDIRS" | wc -l) -gt 1 ]
123 then
124 testarchiveerror
125 fi
126 echo "$ALLDIRS"
127 ;;
128 do_untargz)
129 ALLDIRS=$(tar ztf "$2" | cut -f1 -d/ | sort -u)
130 if [ $(echo "$ALLDIRS" | wc -l) -gt 1 ]
131 then
132 testarchiveerror
133 fi
134 echo "$ALLDIRS"
135 ;;
136 do_untarbz2)
137 ALLDIRS=$(tar jtf "$2" | cut -f1 -d/ | sort -u)
138 if [ $(echo "$ALLDIRS" | wc -l) -gt 1 ]
139 then
140 testarchiveerror
141 fi
142 echo "$ALLDIRS"
143 ;;
144 esac
145 }
146
147 testarchiveerror() {
148 echo "E: More than one directory was found in the unwrapped archive."
149 echo "E: Set WRAPDIR to wrap the contents of the tarball in a directory."
150 exit 1
151 }
152
153 make_exclude_list() {
154 echo "$EXCLUDE_LIST" | grep -v -e ^$ | sed 's/^\(.*\)/--exclude=\1/'
155 }
156
157 next_source_version() {
158 LAST_SRC=$(dpkg-parsechangelog | \
159 sed -n 's/Version: \(.*\)+[0-9\-]*/\1/p')
160 #echo "LS=$LAST_SRC"
161 if [ $LAST_SRC = $VERSION ]
162 then
163 SRCVERSION=$(dpkg-parsechangelog | \
164 sed -n 's/Version: [^+]*+\(.*\)-.*/\1/p')
165 SRCVERSION=$(($SRCVERSION+1))
166 else
167 SRCVERSION=1
168 fi
169 echo $SRCVERSION
170 }
171
172 ###########################################################################
173
174 if [ ! -f $RCFILE ]
175 then
176 cat <<EOT 1>&2
177 $0 Error: No configuration parameters found in file $RCFILE.
178 Exiting.
179 EOT
180 usage
181 exit 1
182 fi
183
184 # Read in the user/package settings
185 . $RCFILE
186
187 if [ $# -lt 3 -o $# -gt 5 ]
188 then
189 usage
190 exit 1
191 fi
192
193 ###########################################################################
194
195 DATE=$(date -R)
196
197 VERSION=$2
198 SRCPATH=$3
199
200 SRCVERSION=""
201 TARGETDIR=$(pwd)
202 if [ $# -eq 5 ]
203 then
204 SRCVERSION="$4"
205 TARGETDIR="$5"
206 elif [ $# -eq 4 ]
207 then
208 if [ -d $4 ]
209 then
210 TARGETDIR="$4"
211 SRCVERSION=$(next_source_version)
212 else
213 SRCVERSION="$4"
214 fi
215 else
216 SRCVERSION=$(next_source_version)
217 fi
218 VERSION="$VERSION+$SRCVERSION"
219
220 if [ ! -d "$TARGETDIR" ]
221 then
222 carp "Target directory '$TARGETDIR' doesn't exist!"
223 fi
224
225 progress "I: Making orig tarball for $VERSION"
226
227 ###########################################################################
228
229 LOGFILE=$TARGETDIR/$LOG
230
231 if [ -f "$LOGFILE" ]
232 then
233 progress "W: Deleting existing log file"
234 rm "$LOGFILE"
235 fi
236
237 ###########################################################################
238
239 DIR=${PACKAGE}-$VERSION.orig
240
241 ARCHIVEFILE=${PACKAGE}_${VERSION}.orig.tar
242 ARCHIVELOCATION="$TARGETDIR"
243
244 TEMPDIR=$(mktemp -t -d $NAME.XXXXXXXXXX) || carp "Couldn't make temp dir"
245
246 ###########################################################################
247
248 progress "I: Locating source $SRCPATH"
249
250 SRCARCHIVE=$(basename "$SRCPATH")
251 if [ $(expr substr "$SRCPATH" 1 7) = "http://" -o \
252 $(expr substr "$SRCPATH" 1 6) = "ftp://" ]
253 then
254 UPSTREAMURL="$SRCPATH"
255 wget "$UPSTREAMURL" -O "$TEMPDIR/$SRCARCHIVE"
256 else
257 cp "$SRCPATH" "$TEMPDIR"
258 fi
259
260 cd $TEMPDIR || carp "Couldn't cd to temp dir $TEMPDIR"
261
262 ###########################################################################
263 MD5="md5sum --binary"
264
265 logmsg "
266 Repackaging of original source for $PACKAGE
267 ---------------------------------------------------------------------
268
269 $PACKAGE version $VERSION.
270
271 Downloaded file: $SRCARCHIVE
272 From: $UPSTREAM
273 Path: $SRCPATH"
274
275 logcmd $MD5 $SRCARCHIVE
276
277 progress "I: Directory: $DIR
278 I: Package name: $PACKAGE
279 I: Version: $VERSION"
280
281 logmsg "
282 The following commands were used to repackage the original source (the
283 'touch' commands ensure that the md5sum of the archives stays the same):"
284
285 # get the source
286 progress "I: Uncompressing source"
287 if $WRAPDIR
288 then
289 logcmd mkdir $DIR
290 $UNARCHIVE $DIR $SRCARCHIVE
291 else
292 INNERDIR=$(testarchive $UNARCHIVE $SRCARCHIVE)
293 $UNARCHIVE . $SRCARCHIVE
294 logcmd mv $INNERDIR $DIR
295 fi
296 # set a consistent time for the top directory
297 logcmd touch -t $TOUCHTIME $DIR
298 # repackage the archive
299 progress "I: Creating 'orig' tar archive"
300
301 #echo "$(make_exclude_list)"
302
303 logcmd tar cf $ARCHIVEFILE --owner 0 --group 0 --numeric-owner \
304 $(make_exclude_list) \
305 $DIR
306
307 # Also set a consistent time on the tar archive
308 logcmd touch -t $TOUCHTIME $ARCHIVEFILE
309 #logcmd md5sum $ARCHIVEFILE
310 progress "I: Compressing archive"
311 logcmd gzip -9 $ARCHIVEFILE
312 logcmd md5sum --binary $ARCHIVEFILE.gz
313
314 logmsg "
315 -- $DEBFULLNAME <$DEBEMAIL> $DATE
316 ---------------------------------------------------------------------
317 "
318
319 ###########################################################################
320
321 progress "I: Moving archive $ARCHIVEFILE.gz"
322 #mv $ARCHIVEFILE $ARCHIVELOCATION
323 touch $ARCHIVEFILE.gz
324 mv $ARCHIVEFILE.gz $ARCHIVELOCATION
325
326 ###########################################################################
327
328 if [ $CLEANUP != 0 ]
329 then
330 progress "I: Cleaning up $TEMPDIR"
331 rm -rf $TEMPDIR
332 else
333 progress "I: Files left in $TEMPDIR for your inspection"
334 fi
335
336 ###########################################################################