Debian Codegraph @

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

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 set -u
4 set -e
5 # set -x
6
7 if [scip-shell system . . `[`. -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=$(dirnamescip-shell system . . dirname. $(readlinkscip-shell system . . readlink. -f $0))
24
25 NAME=$(basenamescip-shell system . . 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 usagescip-shell shell shell-project 0.0.0 usage().() {
38 catscip-shell system . . 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 progressscip-shell shell shell-project 0.0.0 progress().() {
77 if [scip-shell system . . `[`. "$VERBOSE" != 0 -a -n $VERBOSE ]
78 then
79 echoscip-shell system . . echo. "$@"
80 fi
81 }
82
83 logmsgscip-shell shell shell-project 0.0.0 logmsg().() {
84 echoscip-shell system . . echo. "$@" >> $LOGFILE
85 }
86
87 logcmdscip-shell shell shell-project 0.0.0 logcmd().() {
88 logcmdpiecesscip-shell shell shell-project 0.0.0 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 logcmdpiecesscip-shell shell shell-project 0.0.0 logcmdpieces().() {
97 printfscip-shell system . . printf. "\n$ " >> $LOGFILE
98 echoscip-shell system . . echo. "$@" >> $LOGFILE
99 }
100
101 carpscip-shell shell shell-project 0.0.0 carp().() {
102 echoscip-shell system . . echo. "E: ($NAME) $*"
103 exit 1
104 }
105
106 do_unzipscip-shell shell shell-project 0.0.0 do_unzip().() {
107 logcmdscip-shell shell shell-project 0.0.0 logcmd(). unzip -qq -d "$1" "$2"
108 }
109
110 do_untargzscip-shell shell shell-project 0.0.0 do_untargz().() {
111 logcmdscip-shell shell shell-project 0.0.0 logcmd(). tar -C "$1" -zxf "$2"
112 }
113
114 do_untarbz2scip-shell shell shell-project 0.0.0 do_untarbz2().() {
115 logcmdscip-shell shell shell-project 0.0.0 logcmd(). tar -C "$1" -jxf "$2"
116 }
117
118 testarchivescip-shell shell shell-project 0.0.0 testarchive().() {
119 case "$1" in
120 do_unzip)
121 ALLDIRS=$(zipinfo -1 "$2" | cutscip-shell system . . cut. -f1 -d/ | sortscip-shell system . . sort. -u)
122 if [scip-shell system . . `[`. $(echoscip-shell system . . echo. "$ALLDIRS" | wcscip-shell system . . wc. -l) -gt 1 ]
123 then
124 testarchiveerrorscip-shell shell shell-project 0.0.0 testarchiveerror().
125 fi
126 echoscip-shell system . . echo. "$ALLDIRS"
127 ;;
128 do_untargz)
129 ALLDIRS=$(tarscip-shell system . . tar. ztf "$2" | cutscip-shell system . . cut. -f1 -d/ | sortscip-shell system . . sort. -u)
130 if [scip-shell system . . `[`. $(echoscip-shell system . . echo. "$ALLDIRS" | wcscip-shell system . . wc. -l) -gt 1 ]
131 then
132 testarchiveerrorscip-shell shell shell-project 0.0.0 testarchiveerror().
133 fi
134 echoscip-shell system . . echo. "$ALLDIRS"
135 ;;
136 do_untarbz2)
137 ALLDIRS=$(tarscip-shell system . . tar. jtf "$2" | cutscip-shell system . . cut. -f1 -d/ | sortscip-shell system . . sort. -u)
138 if [scip-shell system . . `[`. $(echoscip-shell system . . echo. "$ALLDIRS" | wcscip-shell system . . wc. -l) -gt 1 ]
139 then
140 testarchiveerrorscip-shell shell shell-project 0.0.0 testarchiveerror().
141 fi
142 echoscip-shell system . . echo. "$ALLDIRS"
143 ;;
144 esac
145 }
146
147 testarchiveerrorscip-shell shell shell-project 0.0.0 testarchiveerror().() {
148 echoscip-shell system . . echo. "E: More than one directory was found in the unwrapped archive."
149 echoscip-shell system . . echo. "E: Set WRAPDIR to wrap the contents of the tarball in a directory."
150 exit 1
151 }
152
153 make_exclude_listscip-shell shell shell-project 0.0.0 make_exclude_list().() {
154 echoscip-shell system . . echo. "$EXCLUDE_LIST" | grepscip-shell system . . grep. -v -e ^$ | sedscip-shell system . . sed. 's/^\(.*\)/--exclude=\1/'
155 }
156
157 next_source_versionscip-shell shell shell-project 0.0.0 next_source_version().() {
158 LAST_SRC=$(dpkg-parsechangelogscip-shell system . . dpkg-parsechangelog. | \
159 sed -n 's/Version: \(.*\)+[0-9\-]*/\1/p')
160 #echo "LS=$LAST_SRC"
161 if [scip-shell system . . `[`. $LAST_SRC = $VERSION ]
162 then
163 SRCVERSION=$(dpkg-parsechangelogscip-shell system . . dpkg-parsechangelog. | \
164 sed -n 's/Version: [^+]*+\(.*\)-.*/\1/p')
165 SRCVERSION=$(($SRCVERSION+1))
166 else
167 SRCVERSION=1
168 fi
169 echoscip-shell system . . echo. $SRCVERSION
170 }
171
172 ###########################################################################
173
174 if [scip-shell system . . `[`. ! -f $RCFILE ]
175 then
176 catscip-shell system . . cat. <<EOT 1>&2
177 $0 Error: No configuration parameters found in file $RCFILE.
178 Exiting.
179 EOT
180 usagescip-shell shell shell-project 0.0.0 usage().
181 exit 1
182 fi
183
184 # Read in the user/package settings
185 . $RCFILE
186
187 if [scip-shell system . . `[`. $# -lt 3 -o $# -gt 5 ]
188 then
189 usagescip-shell shell shell-project 0.0.0 usage().
190 exit 1
191 fi
192
193 ###########################################################################
194
195 DATE=$(datescip-shell system . . date. -R)
196
197 VERSION=$2
198 SRCPATH=$3
199
200 SRCVERSION=""
201 TARGETDIR=$(pwdscip-shell system . . pwd.)
202 if [scip-shell system . . `[`. $# -eq 5 ]
203 then
204 SRCVERSION="$4"
205 TARGETDIR="$5"
206 elif [scip-shell system . . `[`. $# -eq 4 ]
207 then
208 if [scip-shell system . . `[`. -d $4 ]
209 then
210 TARGETDIR="$4"
211 SRCVERSION=$(next_source_versionscip-shell shell shell-project 0.0.0 next_source_version().)
212 else
213 SRCVERSION="$4"
214 fi
215 else
216 SRCVERSION=$(next_source_versionscip-shell shell shell-project 0.0.0 next_source_version().)
217 fi
218 VERSION="$VERSION+$SRCVERSION"
219
220 if [scip-shell system . . `[`. ! -d "$TARGETDIR" ]
221 then
222 carpscip-shell shell shell-project 0.0.0 carp(). "Target directory '$TARGETDIR' doesn't exist!"
223 fi
224
225 progressscip-shell shell shell-project 0.0.0 progress(). "I: Making orig tarball for $VERSION"
226
227 ###########################################################################
228
229 LOGFILE=$TARGETDIR/$LOG
230
231 if [scip-shell system . . `[`. -f "$LOGFILE" ]
232 then
233 progressscip-shell shell shell-project 0.0.0 progress(). "W: Deleting existing log file"
234 rmscip-shell system . . 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=$(mktempscip-shell system . . mktemp. -t -d $NAME.XXXXXXXXXX) || carpscip-shell shell shell-project 0.0.0 carp(). "Couldn't make temp dir"
245
246 ###########################################################################
247
248 progressscip-shell shell shell-project 0.0.0 progress(). "I: Locating source $SRCPATH"
249
250 SRCARCHIVE=$(basenamescip-shell system . . basename. "$SRCPATH")
251 if [scip-shell system . . `[`. $(scip-shell system . . expr.exscip-shell system . . expr.prscip-shell system . . 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 cpscip-shell system . . cp. "$SRCPATH" "$TEMPDIR"
258 fi
259
260 cd $TEMPDIR || carpscip-shell shell shell-project 0.0.0 carp(). "Couldn't cd to temp dir $TEMPDIR"
261
262 ###########################################################################
263 MD5="md5sum --binary"
264
265 logmsgscip-shell shell shell-project 0.0.0 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 logcmdscip-shell shell shell-project 0.0.0 logcmd(). $MD5 $SRCARCHIVE
276
277 progressscip-shell shell shell-project 0.0.0 progress(). "I: Directory: $DIR
278 I: Package name: $PACKAGE
279 I: Version: $VERSION"
280
281 logmsgscip-shell shell shell-project 0.0.0 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 progressscip-shell shell shell-project 0.0.0 progress(). "I: Uncompressing source"
287 if $WRAPDIR
288 then
289 logcmdscip-shell shell shell-project 0.0.0 logcmd(). mkdir $DIR
290 $UNARCHIVE $DIR $SRCARCHIVE
291 else
292 INNERDIR=$(testarchivescip-shell shell shell-project 0.0.0 testarchive(). $UNARCHIVE $SRCARCHIVE)
293 $UNARCHIVE . $SRCARCHIVE
294 logcmdscip-shell shell shell-project 0.0.0 logcmd(). mv $INNERDIR $DIR
295 fi
296 # set a consistent time for the top directory
297 logcmdscip-shell shell shell-project 0.0.0 logcmd(). touch -t $TOUCHTIME $DIR
298 # repackage the archive
299 progressscip-shell shell shell-project 0.0.0 progress(). "I: Creating 'orig' tar archive"
300
301 #echo "$(make_exclude_list)"
302
303 logcmdscip-shell shell shell-project 0.0.0 logcmd(). tar cf $scip-shell shell shell-project 0.0.0 make_exclude_list().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 logcmdscip-shell shell shell-project 0.0.0 logcmd(). touch -t $TOUCHTIME $ARCHIVEFILE
309 #logcmd md5sum $ARCHIVEFILE
310 progressscip-shell shell shell-project 0.0.0 progress(). "I: Compressing archive"
311 logcmdscip-shell shell shell-project 0.0.0 logcmd(). gzip -9 $ARCHIVEFILE
312 logcmdscip-shell shell shell-project 0.0.0 logcmd(). md5sum --binary $ARCHIVEFILE.gz
313
314 logmsgscip-shell shell shell-project 0.0.0 logmsg(). "
315 -- $DEBFULLNAME <$DEBEMAIL> $DATE
316 ---------------------------------------------------------------------
317 "
318
319 ###########################################################################
320
321 progressscip-shell shell shell-project 0.0.0 progress(). "I: Moving archive $ARCHIVEFILE.gz"
322 #mv $ARCHIVEFILE $ARCHIVELOCATION
323 touchscip-shell system . . touch. $ARCHIVEFILE.gz
324 mvscip-shell system . . mv. $ARCHIVEFILE.gz $ARCHIVELOCATION
325
326 ###########################################################################
327
328 if [scip-shell system . . `[`. $CLEANUP != 0 ]
329 then
330 progressscip-shell shell shell-project 0.0.0 progress(). "I: Cleaning up $TEMPDIR"
331 rmscip-shell system . . rm. -rf $TEMPDIR
332 else
333 progressscip-shell shell shell-project 0.0.0 progress(). "I: Files left in $TEMPDIR for your inspection"
334 fi
335
336 ###########################################################################