This file is indexed.

/usr/bin/dpatch-edit-patch is in dpatch 2.0.34ubuntu1.

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
#!/bin/bash

set -e

# Populate configuration variables. First check for a pre-existing environment
# variable which we support; that should override the configuration variable,
# which in turn overrides the default. Some configuration variables are only
# allowed in ~/.dpatch.conf, some only in debian/patches/00dpatch.conf.

# CLI option parsing comes later, and
# will blindly set it to the option given therein; CLI options trump all.

# Defining these vaiables here, allows users to set e.g.
# conf_origtargzpath="/usr/local/src/packages/${PACKAGENAME}"
PACKAGENAME="$(dpkg-parsechangelog | sed -n '/^Source:/{s/^Source:[[:space:]]\+\(.*\)/\1/;p;q}')"
UPSTREAMVERSION="$(dpkg-parsechangelog | sed -n '/\(Version:\)/{s/^Version:[[:space:]]\+\([0-9]\+:\)\?\(.*\)/\2/p}' | rev | cut -d- -f 2- | rev)"

# Read in the package's configuration file, should it exist.
[[ -f debian/patches/00dpatch.conf ]] && . debian/patches/00dpatch.conf
unset conf_sourcedir
unset conf_outdir
unset conf_clean
DPEP_DEBIANONLY="${DPEP_DEBIANONLY:-${conf_debianonly:-}}"
unset conf_newdesc
unset conf_keeptemp
unset conf_tmpdir
unset conf_shell
unset conf_stampdir

# Read in the user's configuration file, should it exist.
[[ -f ~/.dpatch.conf ]] && . ~/.dpatch.conf

DPEP_SOURCEDIR="${DPEP_SOURCEDIR:-${conf_sourcedir:-$(pwd)}}"
DPEP_OUTDIR="${DPEP_OUTDIR:-${conf_outdir:-$DPEP_SOURCEDIR/debian/patches}}"
DPEP_STAMPDIR="${DPEP_STAMPDIR:-${conf_stampdir:-$DPEP_SOURCEDIR/debian/patched}}"
DPEP_CLEAN="${DPEP_CLEAN:-${conf_clean:-}}"
DPEP_ORIGTARGZ="${DPEP_ORIGTARGZ:-${conf_origtargz:-}}"
DPEP_GETORIGTARGZ="${DPEP_GETORIGTARGZ:-${conf_getorigtargz:-}}"
DPEP_DESC="${DPEP_NEWDESC:-${conf_newdesc:-No description.}}"
DPEP_KEEPTEMP="${DPEP_KEEPTEMP:-${conf_keeptemp:-0}}"
DPEP_TMPDIR="${DPEP_TMPDIR:-${conf_tmpdir:-${TMPDIR:-/tmp}}}"
DPEP_SHELL="${DPEP_SHELL:-${conf_shell:-${SHELL:-$(getent passwd $(id -un) | cut -f7- -d:)}}}"
DPEP_EXCLUDE="${DPEP_EXCLUDE:-${conf_exclude:-CVS .svn .git .arch .hg _darcs .bzr}}"
DPEP_DIFF_OPTIONS="${DPEP_DIFF_OPTIONS:-${conf_diffopts:-}}"
DPEP_ORIGTARGZPATH="${DPEP_ORIGTARGZPATH:-${conf_origtargzpath:-}}"

# We special-case $DPEP_ROOTCMD later, after dpep_parse_options()

VERBOSITY=0

# Import functions dpep_usage(), dpep_template(), dpep_parse_options(),
# dpep_message(), dpep_parse_longopt_value() 
. /usr/share/dpatch/dpatch-edit-patch.functions

dpep_parse_options "$@" || true

# We special-case $DPEP_ROOTCMD here; if fakeroot doesn't exist and we haven't
# been told explicitly what it should be, error out. (I refuse to use sudo as
# any kind of default, even a fallback if fakeroot doesn't exist - way too
# dangerous). We do this after option parsing, to ensure that they can supply a
# ROOTCMD on the CLI.
if [[ -z "$DPEP_ROOTCMD" ]]; then
    # We're only here if $DPEP_ROOTCMD hasn't already been set via either a CLI
    # argument or the environment variable itself.
    if [[ ! -z "$conf_rootcmd" ]]; then
	# If we're here, the configuration variable has been set
	DPEP_ROOTCMD="$conf_rootcmd"
    elif command -v fakeroot > /dev/null 2>&1; then
	# If we're here, nothing's been set, but fakeroot exists.
	DPEP_ROOTCMD="fakeroot"
    else
	# We're here, nothing's set, fakeroot's not found. Bail.
	dpep_message error " "
	printf "fakeroot is not installed, nor has the option --rootcmd been given, nor has the\n"
	printf "environment variable \$DPEP_ROOTCMD been set, nor has the configuration file\n"
	printf "variable conf_rootcmd been set. Please see the manual page for more details.\n"
	exit 1
    fi
fi

# All argument and option parsing has been done. Time to accomplish something.
# Change to source directory
cd "$DPEP_SOURCEDIR"

# $PWD: $DPEP_SOURCEDIR
if [[ ! -e "debian/rules" ]]; then
# Check to make sure we're in the toplevel directory of a Debian package;
# if not, error out.
    dpep_message error "\"$DPEP_SOURCEDIR\" is not the toplevel directory of a Debian package, aborting."
    exit 1
fi

# Source 00options, currently known options are DPATCH_OPTION_CPP
# and DPEP_OPTION_EXEC_TEMPLATE
[ -r "debian/patches/00options" ] && . debian/patches/00options

# Check to see $DPEP_PATCH is empty, and fail now.
if [[ "${DPEP_PATCH}" = "" ]]; then
    # If it doesn't have .dpatch, append it.
    dpep_message error "patchname is empty, please specify, aborting."
    exit 1
fi

## canonicalize DPATCH name here.
## DPEP_PATCH == xxx.dpatch
## DPEP_PATCHSIMPLENAME == xxx (without .dpatch)

if [[ "${DPEP_PATCH}" = "${DPEP_PATCH%%.dpatch}" ]]; then
    # If it doesn't have .dpatch, append it.
    DPEP_PATCH="${DPEP_PATCH}.dpatch"
fi

# define the simple name without .dpatch.
DPEP_PATCHSIMPLENAME=${DPEP_PATCH%%.dpatch}

# $PWD: $DPEP_SOURCEDIR
if [[ -e "$DPEP_OUTDIR/$DPEP_PATCH" ]]; then
# Check to see if the patch we're told to edit exists; if not, we'll be
# creating it.
    # The patch does already exist, let them know this.
    dpep_message norm "* $DPEP_OUTDIR/$DPEP_PATCH exists, this patch will be updated."
    # Also set this ... later on, we'll need to differentiate between editing
    # an existing patch, and creating a new one.
    DPEP_EDITPATCH=1
    if [[ ! -z "$DPEP_BASEPATCH" ]]; then
	# Even though we're editing an already-existing patch, the user has
	# supplied a base-patch. Warn them that we will be ignoring this.
	dpep_message warn "We are editing an already-existing patch, but a base-patch of $DPEP_BASEPATCH has been supplied - ignoring."
	# We patch up to $DPEP_BASEPATCH in the workdir later, so we assign to
	# it the patch we'll be editing
	DPEP_BASEPATCH="$DPEP_PATCH"
    else
	# They haven't supplied a base-patch, which is nice and sane, so we
	# assign to it the patch we'll be editing, for the same reason as
	# above; we'll be applying it to the working directory.
	DPEP_BASEPATCH="$DPEP_PATCH"
    fi
else
    # Patch doesn't exist, we aren't editing it.
    DPEP_EDITPATCH=0
    dpep_message norm "* $DPEP_OUTDIR/$DPEP_PATCH does not exist, it will be created as a new dpatch."
    # Check to ensure that, if we've been given a base-patch, it exists;
    # otherwise we really need to abort. If we haven't been supplied one,
    # that's fine
    if [[ ! -z "$DPEP_BASEPATCH" ]]; then
	if [[ "$DPEP_BASEPATCH" = "${DPEP_BASEPATCH%%.dpatch}" ]]; then
	    # The user didn't supply a .dpatch extension, so we supply it.
	    DPEP_BASEPATCH="$DPEP_BASEPATCH.dpatch"
	fi
	if [[ ! -e "debian/patches/$DPEP_BASEPATCH" ]]; then
	    dpep_message error "Base-patch $(pwd)/debian/patches/$DPEP_BASEPATCH does not exist, aborting."
	fi
    fi
fi

# built appropriate options for tar and diff to exclude files
# is DPEP_EXCLUDE is empty, this will be empty as well.
DPEP_TAR_EXCLUDE="$(echo $DPEP_EXCLUDE | sed 's/\([^[:space:]]\+\)/--exclude \1/g')"
DPEP_DIFF_EXCLUDE="$(echo $DPEP_EXCLUDE | sed 's/\([^[:space:]]\+\)/--exclude=\1/g')"

# Start preparing the working copy.
# $PWD: $DPEP_SOURCEDIR
# Sanity checking to ensure that our temporary directory exists and is
# writable.
if [[ ! -d "$DPEP_TMPDIR" ]]; then
    dpep_message error "Temporary directory $DPEP_TMPDIR does not exist, aborting."
    exit 1
elif [[ ! -w "$DPEP_TMPDIR" ]]; then
    dpep_message error "Temporary directory $DPEP_TMPDIR is not writable, aborting."
    exit 1
fi

# $PWD: $DPEP_SOURCEDIR
# Hopefully mktemp(1), part of debianutils, does the Right Thing :) We're
# pretty sure it does :)
WORKDIR="$(mktemp -d ${DPEP_TMPDIR}/dpep-work.XXXXXX)"
dpep_message debug1 "Working directory is $WORKDIR"

if [ -n "$DPEP_CLEAN" ]; then
    REFDIR="$DPEP_SOURCEDIR"
    dpep_message debug1 "Using source directory $DPEP_SOURCEDIR as reference directory"
else
    if [ -f "$DPEP_STAMPDIR/$DPEP_PATCH" ]; then
	dpep_message error "Patch $DPEP_PATCH is applied on working directory, use --clean option"
	exit 1
    fi
    REFPDIR="$(mktemp -d ${DPEP_TMPDIR}/dpep-ref.XXXXXX)"
    dpep_message debug1 "Reference directory is $REFPDIR"
    if [ -n "$DPEP_DEBIANONLY" ]; then
        dpep_message norm "* debian/-only layout selected"
	if [ -z "$DPEP_ORIGTARGZ" ]; then
            ORIGTARGZ="${PACKAGENAME}_${UPSTREAMVERSION}.orig.tar.gz"
	    export DPGO_ORIGTARGZPATH="$DPEP_ORIGTARGZPATH"
	    if [ -z "$DPEP_GETORIGTARGZ" ]; then
		dpep_message error "unable to obtain upstream tarball, DPEP_GETORIGTARGZ is unset"
		exit 1
	    fi
	    if ! eval "$DPEP_GETORIGTARGZ $REFPDIR"; then
	        dpep_message error "unable to obtain upstream tarball, $DPEP_GETORIGTARGZ failed"
		exit 1
	    fi
	else
	    if [ -e "$DPEP_ORIGTARGZ" ]; then
		ORIGTARGZ="$(readlink -f "$DPEP_ORIGTARGZ")"
	    else
		dpep_message error "$DPEP_ORIGTARGZ, given on command line, does not exist"
		exit 1
	    fi
	fi
	cd "$REFPDIR"
	dpep_message norm "* unpacking $ORIGTARGZ"
	tar --extract --gzip --file $ORIGTARGZ
	# this heuristic is stolen from dpkg-source
	if [ "$(find . -maxdepth 1 -mindepth 1 -type d -print | wc -l)" -eq 1 ]; then
	  if [ "$(readlink -f "$(find . -maxdepth 1 -mindepth 1 -type d -print)")" != "$(readlink -f "$(basename "$DPEP_SOURCEDIR")")" ]; then
	    mv "$(find . -maxdepth 1 -mindepth 1 -type d -print)" "$(basename "$DPEP_SOURCEDIR")"
	  fi
	else
	  mkdir "$(basename "$DPEP_SOURCEDIR")"
	  find . -maxdepth 1 -mindepth 1 -type d -name "$(basename "$DPEP_SOURCEDIR")" -prune -o -print0 | \
	    xargs --null mv --target-directory="$(basename "$DPEP_SOURCEDIR")"
	fi
    fi
    cd "$REFPDIR"
    dpep_message norm "* Copying $DPEP_SOURCEDIR to reference directory."
    mkdir -p "$(basename "$DPEP_SOURCEDIR")"
    tar --create --file - --dereference $DPEP_TAR_EXCLUDE --directory "$DPEP_SOURCEDIR" .  | \
       tar --extract --file - --directory "$(basename "$DPEP_SOURCEDIR")"
    REFDIR="$REFPDIR/$(basename $DPEP_SOURCEDIR)"
fi    
cd "$REFDIR"

# $PWD: reference directory
# Copy, clean, and clone $DPEP_SOURCEDIR
dpep_message norm "* Cleaning $REFDIR"
$DPEP_ROOTCMD debian/rules clean unpatch
dpatch deapply-all

if [ "$DPEP_APPLYALL" = 1 ]; then
    # check for error condition: if add2list is also specified, the patch name should not exist.
    if [ "$DPEP_ADD2LIST" = 1 ]; then
	if ! dpatch list-all | grep -F "$DPEP_PATCHSIMPLENAME" > /dev/null 2>&1; then
	    # the patch is not in 00list, we are safe
	    :
	else
	    # the patch is in 00list, we are unsafe
	    dpep_message error "--applyall and --add2list is specified, but the patch already exists, aborting."
	    exit 1
	fi
    fi

    # applying all patches listed in debian/patches/00list
    dpep_message norm "Applying all patches"
    dpatch apply-all

else
    # here we have to check if to apply some patches, up to "base patch" or whatever
    if [[ ! -z "$DPEP_BASEPATCH" ]]; then
        if ! dpatch list-all | grep -F "${DPEP_BASEPATCH%%.dpatch}" > /dev/null 2>&1; then
	    if [[ "$DPEP_EDITPATCH" = 1 ]]; then
	        dpep_message warn "$DPEP_PATCH is not listed in debian/patches/00list, no other patches will be applied to the working directory."
            else
	        dpep_message error "Base-patch is not listed in debian/patches/00list, aborting."
	        exit 1
	    fi
        else
	    dpep_message norm "* Applying patches"
	    if [ "$DPEP_EDITPATCH" = 1 ]; then
	        DPEP_apply_until="$(dpatch list-all | grep -B1 -F "${DPEP_PATCH%%.dpatch}" | head -n 1)"
	        # Check below to see if our "apply-until" patch is the same as
	        # the one we're editing. If it is, it happens to be the first in
	        # 00list. That's a bug, we'll hack around it by explicitly
	        # checking for it, and if we find it, we'll do nothing here
	        if [ ! "$DPEP_apply_until" = "${DPEP_PATCH%%.dpatch}" ]; then
		    dpatch apply-until "$DPEP_apply_until"
	        fi
	    else
	        dpatch apply-until "${DPEP_BASEPATCH%%.dpatch}"
	    fi
        fi
    else
        dpep_message warn "* No base-patch supplied, not applying any patches."
    fi
fi

dpep_message norm "* Copying reference directory $REFDIR to work directory."
cd "$WORKDIR"
mkdir "$(basename "$DPEP_SOURCEDIR")"
tar --create --file - --dereference $DPEP_TAR_EXCLUDE --directory "$REFDIR" .  | \
  tar --extract --file - --directory "$(basename "$DPEP_SOURCEDIR")"
# this was previously cp --dereference --archive "$REFDIR" $(basename "$DPEP_SOURCEDIR")

# Change to the workdirectory, apply the patch we're editing if we're
# editing one, and launch an interactive shell.
cd "$WORKDIR/$(basename "$DPEP_SOURCEDIR")"
if [[ "$DPEP_EDITPATCH" = "1" ]]; then
    dpep_message norm "* Applying current $DPEP_PATCH for editing."
    if ! dpatch apply --no-stamp "$DPEP_PATCH"; then
       dpep_message warn "Could not apply the patch we want to edit -- not aborting, as you may want to work with the .rejs."
    fi
fi
cat <<EOF

$(basename $0):

Now launching an interactive shell in your work directory. Edit your files.
When you are done, exit the shell. When you exit the shell, your patch will be
automatically updated based on the changes in your work directory.

If you wish to abort the process, exit the shell such that it returns an exit
code of "230". This is typically done by exiting the shell with the command
'exit 230'.
EOF

export DPEP_SHELL_REFDIR="$REFDIR"
export DPEP_SHELL_WORKDIR="$WORKDIR/$(basename "$DPEP_SOURCEDIR")"

$DPEP_SHELL && EXITVAL=0 || EXITVAL="$?"
if [[ "$EXITVAL" = "230" ]]; then
    dpep_message error "Shell exited with an exit value of 230, aborting."
    dpep_cleanup
    exit 1
elif [[ "$EXITVAL" != "0" ]]; then
    dpep_message warn "Shell exited with an exit value other than 0."
fi
cd "$WORKDIR"

# Okay, they've exited the shell in a reasonable manner, and as such we're
# free to create or update the patch.
DIFFHOLDER="$(tempfile -d "$WORKDIR" -p "dpep." -s ".diff")"
dpep_message debug1 "Diff temporary file is $DIFFHOLDER"
cd "$REFDIR"
LC_ALL=C diff -urNad $DPEP_DIFF_OPTIONS $DPEP_DIFF_EXCLUDE . "$WORKDIR/$(basename "$DPEP_SOURCEDIR")" |
  sed -e "/^--- \|^diff /s| \./| $(basename "$DPEP_SOURCEDIR")~/|" \
      -e "/^+++ \|^diff /s| $WORKDIR/| |" \
      -e "/^--- \|^+++ /s:${DPEP_OMIT_TIMESTAMPS+\t[^\t]*}\$::" \
      -e "/^diff /s| $DPEP_DIFF_EXCLUDE||" > "$DIFFHOLDER" || true

# Diff created, let's switch back to the original directory, and start the
# process of updating or creating the patch.
cd "$DPEP_SOURCEDIR"
if [[ "$DPEP_EDITPATCH" = "0" ]]; then
    # We're creating a new patch, so this is relatively easy.
    dpep_message norm "* Creating new patch $DPEP_OUTDIR/$DPEP_PATCH"
    # We don't know for sure that any directories are created, so let's create
    # them now.

    PATCHDIR="$DPEP_OUTDIR/$(dirname "$DPEP_PATCH")"
    NEWPATCH="$DPEP_OUTDIR/$DPEP_PATCH"

    [[ ! -d "$PATCHDIR" ]] && mkdir -p "$PATCHDIR"
    if [[ ! -e "debian/patches/00template" ]]; then
	dpep_message warn "debian/patches/00template not exist, using hardcoded default."
	dpep_template_hardcoded "$NEWPATCH" "$NEWPATCH" "$DPEP_DESC"
    else
	dpep_message norm "Using debian/patches/00template"
	dpep_template_apply "$NEWPATCH" "$DPEP_DESC"
    fi
    # Okay, headers and shell snippets all set up. Now copy the actual patch text.
    cat "$DIFFHOLDER" >> "$NEWPATCH"
    dpep_message norm "$NEWPATCH created."
else
    # Damnit, we're editing a patch. This is _never_ fun :)
    OLDPATCH="$DPEP_OUTDIR/$DPEP_PATCH"
    dpep_message norm "Updating patch $OLDPATCH"
    # Need another temporary file.
    NEWPATCH="$(tempfile -m 666 -d "$WORKDIR")"
    DPEP_TAGLINENUM="$(grep -an '^@DPATCH@$' "$OLDPATCH" | head -n1 | cut -f1 -d:)"
    if [ "$DPEP_TAGLINENUM" ]; then
	# They have our tag, so we can preserve their headers.
	dpep_message norm "@DPATCH@ tag found, preserving dpatch header."
	head -n "$DPEP_TAGLINENUM" "$OLDPATCH" > "$NEWPATCH"
    elif [[ -e "debian/patches/00template" ]]; then
	# Okay, they don't have a tag - damn them. But they at least have a
	# template.
	dpep_message warn "@DPATCH@ tag not found, using debian/patches/00template"
	dpep_template_apply "$OLDPATCH" "$DPEP_DESC"
    else
	# They have neither a @DPATCH@ tag, *NOR* a template. Damn, they just suck.
	dpep_message warn "@DPATCH@ tag not found, debian/patches/00template not found. Using hardcoded default."
	dpep_template_hardcoded "$NEWPATCH" "$OLDPATCH" "$DPEP_DESC"
    fi
    # Okay, the headers and shell snippets are in place. Move the diff there now.
    cat "$DIFFHOLDER" >> "$NEWPATCH"
    mv "$NEWPATCH" "$OLDPATCH"
    dpep_message norm "$OLDPATCH updated."
fi
# chmod +x the dpatch, just in case.
chmod +x "$DPEP_OUTDIR/$DPEP_PATCH"

# Check to see if we have to add the newly created patch into 00list
if [[ $DPEP_ADD2LIST = "1" ]]; then
    # ok we have to add it; let's first check if the file exists or not
    if [[ ! -e "debian/patches/00list" ]]; then
        # 00list file missing, easier situation: we create it with just the new patch inside
	echo "$DPEP_PATCHSIMPLENAME" > debian/patches/00list
	dpep_message norm "File $(pwd)/debian/patches/00list created and patch added to it"
    else
        # 00list exists; we have to check if the current patch is already in the list or not
	# if it's already in 00list we do nothing, otherwise we add it at the end of the file
	if ! dpatch list-all | grep -F "$DPEP_PATCHSIMPLENAME" > /dev/null 2>&1; then
	    # the patch is not in 00list, so we can add it at the end of the file
	    echo "$DPEP_PATCHSIMPLENAME" >> debian/patches/00list
	    dpep_message norm "Patch added at the end of file $(pwd)/debian/patches/00list"
	fi
    fi
fi


# Okay, we're all done. Do the cleanup.
dpep_cleanup

# arch-tag: ef9b2d2d-2026-4f10-b88d-330ea9039b14