This file is indexed.

/usr/bin/cvs-buildpackage is in cvs-buildpackage 5.26.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#! /bin/bash
#                               -*- Mode: Sh -*- 
# deb-cvs --- 
# Author           : Manoj Srivastava ( srivasta@tiamat.datasync.com ) 
# Created On       : Mon May 26 14:23:17 1997
# Created On Node  : tiamat.datasync.com
# Last Modified By : Manoj Srivastava
# Last Modified On : Sat Jun  5 18:14:52 2004
# Last Machine Used: glaurung.internal.golden-gryphon.com
# Update Count     : 156
# Status           : Unknown, Use with caution!
# HISTORY          : 
# Description      : 
# $Id: cvs-buildpackage,v 1.58 2003/08/22 17:24:29 srivasta Exp $
# 

# Make sure we abort on error
set -e

progname="`basename \"$0\"`"
pversion='$Revision: 1.58 $'

setq() {
    # Variable Value Doc string
    if [ "x$2" = "x" ]; then
	echo >&2 "$progname: Unable to determine $3"
	exit 1;
    else
	if [ ! "x$Verbose" = "x" ]; then
	    echo "$progname: $3 is $2";
	fi
	eval "$1=\"\$2\"";
    fi
}

withecho () {
        echo " $@" >&2
        "$@"
}

usageversion () {
        cat >&2 <<END
Debian GNU/Linux $progname $pversion.
           Copyright (C) 1997 Manoj Srivastava.
This is free software; see the Artistic Licence for copying
conditions.  There is NO warranty.  

Usage: $progname  [options]
Options: 
  -h           print this message
  -M<module>   CVS module name.     }
  -P<package>  Package name.        } Allow operation out of the
  -V<version>  Package Version      } checked out source tree
  -T<tag>      CVS Tag to use
  -U<tag>      Upstream tag to use
  -C<command>  The Build-package command to use, nominally dpkg-buildpackage
  -G<method>   The command to execute that'll get the orig tarball in the 
               current directory.
  -A           Use apt to get original tarball if it does not exist.
  -R<root dir> Root directory.
  -W<work dir> Working directory.
  -F           Force a cvs tag -F before exporting (Only valid in a
               CVS working dir)
  -E           Force a full export when building, instead of unpacking the
               orig.tar.gz and using cvs 'rdiff' to bring it up-to-date.
  -n           "Dry-run" mode - No action taken, only print commands.
  -op          The opposite of -E, unpacking the orig.tar.gz (o) and using 
               cvs 'rdiff' (p) to bring it up-to-date.
  -tC          Clean all non-upload files in workdir after a successful build.
  -ctp         Include <package>_ at start of CVS tag.
  -x<prefix>   CVS default module prefix.
  -f<script>   A hook script to be called to fix up permission if nit using
               the full export mechanism.
  -H<script>   A hook script to be called from the checked out dir before 
               calling dpkg-buildpackage
 The rest are passed to dpkg-buildpackage, though we do pay attention
 to the -r option. These are the options supported:
    -r<gain-root-command>
    -p<pgp-command>
    -d            do not check build dependencies and conflicts
    -D            check build dependencies and conflicts
    -k<keyid>     the key to use for signing
    -sgpg         the sign-command is called like GPG
    -spgp         the sign-command is called like PGP 
    -us           unsigned source
    -uc           unsigned changes
    -a<arch>      architecture field of the changes _file_name_
    -b            binary-only, do not build source } also passed to
    -B            binary-only, no arch-indep files } dpkg-genchanges
    -S            source only, no binary files     } 
    -v<version>   changes since version <version>     
    -m<maint>     maintainer for package is <maint>   
    -e<maint>     maintainer for release is <maint>   
    -si (default) src includes orig for rev. 0 or 1   
    -sa           uploaded src always includes orig   
    -sd           uploaded src is diff and .dsc only  
    -ap           add pause before starting signature process
    -i<regex>     ignore diffs of files matching regex
    -I<filename>  filter out files when building tarballs
END
}

#
# Long term variables, which may be set in the config file or the
# environment: 
# DEBUG rootdir workdir (if all original sources are kept in one dir)
#
# 

action='withecho'
DEBUG=${DEBUG:-0}

TEMPDIR=/tmp/$$
mkdir $TEMPDIR || exit 1
TEMPFILE=$TEMPDIR/cl-tmp

cleansource=0
TAGOPT=

# Command line
TEMP=$(getopt -a -s bash -o hC:EAH:G:M:P:R:T:U:V:W:Ff:dcnr:x:Bbp:Dk:a:Sv:m:e:i:I: --long ctp,help,tC,sgpg,spgp,us,uc,op,si,sa,sd,ap,sp,su,sk,sr,sA,sP,sU,sK,sR,ss,sn -n 'cvs-buildpackage' -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"

while true ; do
    case "$1" in
        -h)    usageversion; exit 0  ; shift   ;;
	-C)    opt_buildpackage="$2" ; shift 2 ;;
	-H)    opt_hook="$2"   	    ; shift 2 ;;
	-f)    opt_fix="$2"   	    ; shift 2 ;;
        -G)    opt_get_orig="$2"     ; shift 2 ;;
	-M)    opt_cvsmodule="$2"    ; shift 2 ;;
	-P)    opt_package="$2"      ; shift 2 ;;
	-R)    opt_rootdir="$2"      ; shift 2 ;;
	-T)    opt_tag="$2"          ; shift 2 ;;
	-U)    opt_utag="$2"         ; shift 2 ;;
	-V)    opt_version="$2"      ; shift 2 ;;
	-W)    opt_workdir="$2"      ; shift 2 ;;
	-F)    opt_forcetag=1        ; shift   ;;
       --ctp)  opt_packageintag=1    ; shift   ;;
	-n)    action='echo'         ; shift   ;;
        -r)    opt_rootcommand="$2"  ; shift 2 ;;
       --op)   opt_fullexport="NO"     ; shift   ;;
       --tC)   cleansource=1         ; shift   ;;
	-x)    opt_prefix="$2"       ; shift 2 ;;
	-E)    opt_fullexport="YES"      ; shift   ;;
        -A)    opt_use_apt="YES"	; shift	;;
	-d)    dpkg_options=("${dpkg_options[@]}" "$1")   ; shift   ;;
        -B)    dpkg_options=("${dpkg_options[@]}" "$1")   ; shift   ;;
        -b)    dpkg_options=("${dpkg_options[@]}" "$1")   ; shift   ;;
        -S)    dpkg_options=("${dpkg_options[@]}" "$1")   ; shift   ;;
        -p)    dpkg_options=("${dpkg_options[@]}" "$1$2") ; shift 2 ;;
       --help) usageversion; dpkg --help;        exit 0  ; shift    ;;
       --us)   dpkg_options=("${dpkg_options[@]}" "-us")  ; shift   ;;
       --uc)   dpkg_options=("${dpkg_options[@]}" "-uc")  ; shift   ;;
       --sgpg) dpkg_options=("${dpkg_options[@]}" "-sgpg"); shift   ;;
       --spgp) dpkg_options=("${dpkg_options[@]}" "-spgp"); shift   ;;
       --si)   dpkg_options=("${dpkg_options[@]}" "-si")  ; shift   ;;
       --sd)   dpkg_options=("${dpkg_options[@]}" "-sd")  ; shift   ;;
       --ap)   dpkg_options=("${dpkg_options[@]}" "-ap")  ; shift   ;;
       --sa)   dpkg_options=("${dpkg_options[@]}" "-sa")  ; shift   ;;
       --sp)   dpkg_options=("${dpkg_options[@]}" "-sp")  ; shift   ;;
       --su)   dpkg_options=("${dpkg_options[@]}" "-su")  ; shift   ;;
       --sk)   dpkg_options=("${dpkg_options[@]}" "-sk")  ; shift   ;;
       --sr)   dpkg_options=("${dpkg_options[@]}" "-sr")  ; shift   ;;
       --sA)   dpkg_options=("${dpkg_options[@]}" "-sA")  ; shift   ;;
       --sP)   dpkg_options=("${dpkg_options[@]}" "-sP")  ; shift   ;;
       --sU)   dpkg_options=("${dpkg_options[@]}" "-sU")  ; shift   ;;
       --sK)   dpkg_options=("${dpkg_options[@]}" "-sK")  ; shift   ;;
       --sR)   dpkg_options=("${dpkg_options[@]}" "-sR")  ; shift   ;;
       --sn)   dpkg_options=("${dpkg_options[@]}" "-sn")  ; shift   ;;
       --ss)   dpkg_options=("${dpkg_options[@]}" "-ss")  ; shift   ;;
        -D)    dpkg_options=("${dpkg_options[@]}" "$1")   ; shift   ;;
        -k)    dpkg_options=("${dpkg_options[@]}" "$1$2") ; shift 2 ;;
        -a)    dpkg_options=("${dpkg_options[@]}" "$1$2") ; shift 2 ;;
        -v)    dpkg_options=("${dpkg_options[@]}" "$1$2") ; shift 2 ;;
        -m)    dpkg_options=("${dpkg_options[@]}" "$1$2") ; shift 2 ;;
        -e)    dpkg_options=("${dpkg_options[@]}" "$1$2") ; shift 2 ;;
        -i)    dpkg_options=("${dpkg_options[@]}" "$1$2") ; shift 2 ;;
        -I)    dpkg_options=("${dpkg_options[@]}" "$1$2") ; shift 2 ;;
        --)      shift ; break ;;
        *) echo >&2 "Internal error!($1)"
            usageversion; exit 1           ;;
    esac
done
for arg in ${1+"$@"}; do
    case "$arg" in
	*)    opt_package="$arg" ;;
    esac
done

if [ "x$opt_cvsmodule" = "x" -a "x$opt_package" = "x" -a \
      ! -e 'debian/changelog' ] ; then
    echo >&2 "$progname should be run in the top working directory of"
    echo >&2 "a Debian Package, or an explicit package (or CVS module) name"
    echo >&2 "should be given." 
    exit 1
fi

if [ "x$opt_tag" != "x" ]; then
    TAGOPT=-r$opt_tag
fi

# Command line, env variable, config file, or default
# This anomalous position is in case we need to check out the changelog
# below (anaomalous since we ahve not loaded the config file yet)
if [ ! "x$opt_prefix" = "x" ]; then
    prefix="$opt_prefix"
elif [ ! "x$CVSDEB_PREFIX" = "x" ]; then
    prefix="$CVSDEB_PREFIX"
elif [ ! "x$conf_prefix" = "x" ]; then
    prefix="$conf_prefix"
else
    prefix=""
fi

# put a slash at the end of the prefix
if [ "X$prefix" != "X" ]; then
    prefix="$prefix/";
    prefix=`echo $prefix | sed 's://:/:g'`;
fi

if [ ! -f CVS/Root ]; then
    if [ "X$CVSROOT" = "X" ]; then
	echo "no CVS/Root file found, and CVSROOT var is empty" >&2
	exit 1
    fi
else
    CVSROOT=$(cat CVS/Root)
    export CVSROOT
fi

if [ "x$opt_package" = "x" ]; then
    # Get the official package name and version.
    if [ -f debian/changelog ]; then
	# Ok, changelog exists
	 setq "package" \
	    "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" \
		"source package"
	setq "version" \
	    "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" \
		"source version"
    elif [ "x$opt_cvsmodule" != "x" ]; then
	# Hmm. Well, see if we can checkout the changelog file
	rm -f $TEMPFILE
	cvs -q co -p $TAGOPT $opt_cvsmodule/debian/changelog > $TEMPFILE
        setq "package" \
	    "`dpkg-parsechangelog -l$TEMPFILE | sed -n 's/^Source: //p'`" \
          "source package"
        setq "version" \
          "`dpkg-parsechangelog -l$TEMPFILE | sed -n 's/^Version: //p'`" \
          "source version"
        rm -f "$TEMPFILE"
    else
	# Well. We don't know what this package is.
	echo >&2 " This does not appear be a Debian source tree, since"
	echo >&2 " theres is no debian/changelog, and there was no"
	echo >&2 " package name or cvs module given on the comand line"
	echo >&2 " it is hard to figure out what the package name "
	echo >&2 " should be. I give up."
	exit 1
    fi
else
    # The user knows best; package name is provided
    setq "package" "$opt_package" "source package"

    # Now, the version number
    if [ "x$opt_version" != "x" ]; then
	# All hail the user provided value
	setq "version" "$opt_version" "source package"
    elif [ -f debian/changelog ]; then
	# Fine, see what the changelog says
	setq "version" \
	    "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" \
		"source version"
    elif [ "x$opt_cvsmodule" != "x" ]; then
	# Hmm. The CVS module name is known, so lets us try exporting changelog
	rm -f $TEMPFILE
	cvs -q co -p $TAGOPT $opt_cvsmodule/debian/changelog > $TEMPFILE
        setq "version" \
          "`dpkg-parsechangelog -l$TEMPFILE | sed -n 's/^Version: //p'`" \
          "source version"
        rm -f "$TEMPFILE"
    else
	# Ok, try exporting the package name
	rm -f $TEMPFILE
	cvsmodule="${prefix}$package"
	cvs -q co -p $TAGOPT $cvsmodule/debian/changelog > $TEMPFILE
        setq "version" \
          "`dpkg-parsechangelog -l$TEMPFILE | sed -n 's/^Version: //p'`" \
          "source version"
        rm -f "$TEMPFILE"
    fi
fi

rm -f $TEMPFILE
rmdir $TEMPDIR


non_epoch_version=$(echo -n "$version" | perl -pe 's/^\d+://')
upstream_version=$(echo -n "$non_epoch_version" | sed  -e 's/-[^-]*$//')
debian_version=$(echo -n $non_epoch_version |  perl -nle 'm/-([^-]*)$/ && print $1')

# The default
if [ "X$opt_rootdir" != "X" ]; then
    rootdir="$opt_rootdir"
else
    rootdir='/usr/local/src/Packages'
fi

if [ "X$opt_workdir" != "X" ]; then
    workdir="$opt_workdir"
else
    workdir="$rootdir/$package"
fi

sversion=$non_epoch_version
uversion=$upstream_version
tversion=$debian_version

# Load site defaults and over rides.
if [ -f /etc/cvsdeb.conf ]; then
    . /etc/cvsdeb.conf
fi

# Load user defaults and over rides.
if [ -f ~/.cvsdeb.conf ]; then
    . ~/.cvsdeb.conf
fi

# Handle module prefixes
if [ ! "x$opt_prefix" = "x" ]; then
    prefix="$opt_prefix"
elif [ ! "x$CVSDEB_PREFIX" = "x" ]; then
    prefix="$CVSDEB_PREFIX"
elif [ ! "x$conf_prefix" = "x" ]; then
    prefix="$conf_prefix"
else
    prefix=""
fi



# put a slash at the end of the prefix
if [ "X$prefix" != "X" ]; then
    prefix="$prefix/";
    prefix=`echo $prefix | sed 's://:/:g'`;
fi


# Command line, env variable, config file, or default
if [ ! "x$opt_packageintag" = "x" ]; then
    packageintag="$opt_packageintag"
elif [ ! "x$CVSDEB_PACKAGEINTAG" = "x" ]; then
    packageintag="$CVSDEB_PACKAGEINTAG"
elif [ ! "x$conf_packageintag" = "x" ]; then
    packageintag="$conf_packageintag"
else
    packageintag=""
fi


if [ "x$opt_tag" != "x" ]; then
    cvstag="$opt_tag"
else
    cvstag=$(echo -n "debian_version_$non_epoch_version" | \
	tr -c -- "-_a-zA-Z0-9" "_")
fi

if [ "X$opt_utag" != "X" ]; then
    cvs_upstream_tag="$opt_utag"
else
    cvs_upstream_tag=$(echo -n "upstream_version_$upstream_version" | \
	tr -c -- "-_a-zA-Z0-9" "_")
fi

if [ "x$packageintag" != x ]; then
    cvstag=$(echo -n "${package}_$cvstag"|tr -c -- "-_a-zA-Z0-9~" "_") 
    cvs_upstream_tag=$(echo -n "${package}_$cvs_upstream_tag" | \
	tr -c -- "-_a-zA-Z0-9" "_")
fi

if [ "x$opt_cvsmodule" != "x" ]; then
  cvsmodule="$opt_cvsmodule"
else
  cvsmodule="${prefix}$package" 
fi

# conf_dpkg_options is where one may stash -us -uc or whatever
if [ -n "${conf_dpkg_options[*]}" ]; then
    dpkg_options=("${dpkg_options[@]}" "${conf_dpkg_options[@]}");
elif [ "x$conf_dpkg_options" != "x" ] ; then
    echo "conf_dpkg_options is now supposed to be an array variable"
    echo "However, you seem to have it set to a simple variable, which"
    echo "was the old way of doing things. Please set it to an array"
    echo "variable, with a form similar to"
    echo 'dpkg_options=("${dpkg_options[@]}" "value")';
    exit 1;
fi

# If asked to debug on command line, that's what we get
if [ ! "x$opt_DEBUG" = "x" ]; then
    DEBUG="$opt_DEBUG"
fi

# Command line, env variable, config file, or default
if [ ! "x$opt_rootdir" = "x" ]; then
    rootdir="$opt_rootdir"
elif [ ! "x$CVSDEB_ROOTDIR" = "x" ]; then
    rootdir="$CVSDEB_ROOTDIR"
elif [ ! "x$conf_rootdir" = "x" ]; then
    rootdir="$conf_rootdir"
fi

# Command line, env variable, config file, or default
if [ ! "x$opt_workdir" = "x" ]; then
    workdir="$opt_workdir"
elif [ ! "x$CVSDEB_WORKDIR" = "x" ]; then
    workdir="$CVSDEB_WORKDIR"
elif [ ! "x$conf_workdir" = "x" ]; then
    workdir="$conf_workdir"
else
    workdir="$rootdir/$package"
fi

# Command line, env variable, config file, or default
if [ ! "x$opt_forcetag" = "x" ]; then
    forcetag="$opt_forcetag"
elif [ ! "x$CVSDEB_FORCETAG" = "x" ]; then
    forcetag="$CVSDEB_FORCETAG"
elif [ ! "x$conf_forcetag" = "x" ]; then
    forcetag="$conf_forcetag"
else
    forcetag=""
fi

# Command line, env variable, config file, or default
if [ ! "x$opt_rootcommand" = "x" ]; then
    rootcommand="$opt_rootcommand"
elif [ ! "x$CVSDEB_ROOTCOMMAND" = "x" ]; then
    rootcommand="$CVSDEB_ROOTCOMMAND"
elif [ ! "x$conf_rootcommand" = "x" ]; then
    rootcommand="$conf_rootcommand"
else
    rootcommand=""
fi

if [ "X$rootcommand" != "X" ]; then
     dpkg_options=("${dpkg_options[@]}" "-r$rootcommand") ;
fi


# Command line, env variable, config file, or default
if [ ! "x$opt_strict_check" = "x" ]; then
    strict_check="$opt_strict_check"
elif [ ! "x$CVSDEB_STRICT_CHECK" = "x" ]; then
    strict_check="$CVSDEB_STRICT_CHECK"
elif [ ! "x$conf_strict_check" = "x" ]; then
    strict_check="$conf_strict_check"
else
    strict_check=""
fi
# Command line, env variable, config file, or default
if [ ! "x$opt_buildpackage" = "x" ]; then
    buildpackage="$opt_buildpackage"
elif [ ! "x$CVSDEB_BUILDPACKAGE" = "x" ]; then
    buildpackage="$CVSDEB_BUILDPACKAGE"
elif [ ! "x$conf_buildpackage" = "x" ]; then
    buildpackage="$conf_buildpackage"
else
    buildpackage="dpkg-buildpackage"
fi

# Command line, env variable, config file, or default
if [ ! "x$opt_packageopts" = "x" ]; then
    cvsdeb_packageopts="$opt_packageopts"
elif [ ! "x$CVSDEB_PACKAGEOPTS" = "x" ]; then
    cvsdeb_packageopts="$CVSDEB_PACKAGEOPTS"
elif [ ! "x$conf_packageopts" = "x" ]; then
    cvsdeb_packageopts="$conf_packageopts"
else
    cvsdeb_packageopts=""
fi

if [ "X$opt_hook" != "X" ]; then
    hook_script="$opt_hook"
elif [ "X$CVSDEB_HOOK" != "X" ]; then
    hook_script="$CVSDEB_HOOK"
elif [ ! "x$conf_hook_script" = "x" ]; then
    hook_script="$conf_hook_script"
else
    hook_script=""
fi

if [ "X$opt_fix" != "X" ]; then
    fix_script="$opt_fix"
elif [ "X$CVSDEB_FIX" != "X" ]; then
    fix_script="$CVSDEB_FIX"
elif [ ! "x$conf_fix_script" = "x" ]; then
    fix_script="$conf_fix_script"
else
    fix_script=""
fi

if [ "X$opt_get_orig" != "X" ]; then
    get_orig_cmd="$opt_get_orig"
elif [ "X$CVSDEB_GET_ORIG" != "X" ]; then
    get_orig_cmd="$CVSDEB_GET_ORIG"
elif [ ! "x$conf_get_orig" = "x" ]; then
    get_orig_cmd="$conf_get_orig"
else
    get_orig_cmd=""
fi

if [ "X$opt_use_apt" != "X" ]; then
    use_apt="$opt_use_apt"
elif [ "X$CVSDEB_USE_APT" != "X" ]; then
    use_apt="$CVSDEB_USE_APT"
elif [ "X$conf_use_apt" != "X" ]; then
    use_apt="$conf_use_apt"
else
    use_apt=no
fi
case $use_apt in
  YES | Yes | yes | Y | y | TRUE | True | true | 1 ) use_apt=yes ;;
  MAYBE | Maybe | maybe | CHECK | Check | check )
    if [ -x /usr/bin/apt-get -a -x /usr/bin/apt-cache ]; then
        use_apt=yes
    else
        use_apt=no
    fi ;;
esac

# Command line, env variable, config file, or default
if [ ! "x$opt_fullexport" = "x" ]; then
    fullexport="$opt_fullexport"
elif [ ! "x$CVSDEB_FULLEXPORT" = "x" ]; then
    fullexport="$CVSDEB_FULLEXPORT"
elif [ ! "x$conf_fullexport" = "x" ]; then
    fullexport="$conf_fullexport"
else
    fullexport="YES"
fi

if [ ! -d "$workdir" ]; then
    echo >&2 "The working directory, $workdir, does not exist. Aborting"
    if [ ! -d "$rootdir" ]; then
	echo >&2 "The root directory, $rootdir, does not exist either."
    fi
    exit 1;
fi

# No user defined changes here
pkgdir="$workdir/$package-$upstream_version"
oversion="$workdir/${package}_${upstream_version}.orig.tar.gz"

if [ $DEBUG -gt 0 ]; then
    echo >&2 ""
    echo >&2 "============================================================"
    echo >&2 ""
    echo >&2 "Non Epoch Version = $non_epoch_version "
    echo >&2 "Upstream Version  = $upstream_version "
    echo >&2 "Debian Version    = $debian_version"
    echo >&2 ""
    echo >&2 "cvs tag           = $cvstag"
    echo >&2 "cvs upstream tag  = $cvs_upstream_tag"
    echo >&2 ""
    echo >&2 "Working Directory = $workdir"
    echo >&2 "Package Directory = $pkgdir"
    echo >&2 ""
    echo >&2 "Original="
    echo >&2 "   $oversion"
    echo >&2 ""
    echo >&2 "============================================================"
    echo >&2 ""
fi
export non_epoch_version upstream_version debian_version cvstag 
export package cvs_upstream_tag 

if [  -f debian/changelog  ]; then
    # Checking for uncommitted changes
    if [ "X$strict_check" != "X" ]; then
	unknown_regexp='^(M|A) ';
    else
	unknown_regexp='^(M|A|\?) ';
    fi
    set +e
    uncommitted=$(cvs -n update 2>/dev/null | egrep $unknown_regexp);
    set -e
    answer=""
    if [ "X$uncommitted" != "X" ]; then
	echo "There are uncommitted files."
	echo "$uncommitted"
	echo -n "Are you sure you wish to proceed?[y/N]: "
	read answer
	case $answer in
	    [Yy]*) nop= ;;
		*) exit 1
		;;
	esac
    fi
fi
if [ ! -d $workdir ]; then
    $action mkdir -p "$workdir"
fi

$action $rootcommand /bin/rm -rf "$pkgdir" "$pkgdir.orig"

if [ -f debian/changelog -a "X$forcetag" != "X" ]; then
    $action cvs rtag -d "$cvstag" "$cvsmodule"
    $action cvs tag -F "$cvstag"
fi

if [ "x$debian_version" != "x" -a ! -e $oversion -a  "X$get_orig_cmd"  != "X" ]; then
    $action cd $workdir
    $action eval "$get_orig_cmd"
fi

if [ "x$debian_version" != "x" -a ! -e $oversion -a "X$use_apt" = "Xyes" ]; then
    set dummy `apt-cache showsrc "$package" | awk '
        $1=="Version:" { v=$2 }
        /^ [0-9a-f]+ [0-9]+ '"${package}_${upstream_version}.orig.tar.gz"'/ { md5=$1 }
        NF==0 { if( md5 ) print v,md5 ; md5=""; }'`
    if [ "x$2" != "x" ]; then
        old_fullversion=$2
        apt_orig_md5sum=$3
        $action cd "$(dirname "$oversion")"
        $action apt-get --tar-only source "$package=$old_fullversion"
    else
        echo "WARNING: Apt does not know ${package}_${upstream_version}.orig.tar.gz"
    fi
fi

$action cd "$(dirname "$pkgdir")"
if [ \( "x$fullexport" = "xNO" -o "x$fullexport" = "xno" \) -a -e "$oversion" -a "x$debian_version" != "x" ]; then
    $action tar zxvf "$oversion"
    $action pushd "$(basename "$pkgdir")"
    $action cvs -q rdiff -u -r "$cvs_upstream_tag" -r "$cvstag" "$cvsmodule" | patch -p2
    $action chmod +x debian/rules
    if [ "X$fix_script" != "X" ]; then
	$action $fix_script "$package" "$version" 
    fi
    $action popd 
else
    if [ "x$WORKINGCVS" = "x" ]; then
      $action cvs -q export -d $(basename $pkgdir) -r "$cvstag" "$cvsmodule"
      if [ "x$debian_version" != "x" -a ! -e "$oversion"  ]; then
	$action cvs -q export -d "$(basename $pkgdir).orig" -r "$cvs_upstream_tag" "$cvsmodule"
      fi
    else
      $action cvs -q export -d $package-$upstream_version -r "$cvstag" "$cvsmodule"
      if [ "x$debian_version" != "x"  -a ! -e "$oversion" ]; then
	$action cvs -q export -d "$package-$upstream_version.orig" -r "$cvs_upstream_tag" "$cvsmodule"
      fi
    fi
fi

$action cd "$pkgdir"
if [ "X$hook_script" != "X" ]; then
    $action $hook_script "$package" "$version" 
fi

if [ "X$cvsdeb_packageopts" != "X" ]; then
	$action $buildpackage "${dpkg_options[@]}" $cvsdeb_packageopts
else
	$action $buildpackage "${dpkg_options[@]}"
fi

# Clean up if asked to do so
if [ $cleansource -eq 1 ]; then
    $action cd "$workdir"
    $action $rootcommand /bin/rm -rf "$pkgdir" "$pkgdir.orig" 
fi

exit 0