#! /bin/sh
set -e

if [ "$1" = configure ]
then
    if dpkg --compare-versions "$2" lt 2.6.90 && [ ! -f /etc/devscripts.conf ]
    then
	cp /usr/share/devscripts/conf.default /etc/devscripts.conf
    elif [ -f /etc/devscripts.conf ]
    then
	# Are we dealing with an upgrade from pre-sarge?
	if dpkg --compare-versions "$2" lt 2.8.14
	then
	    if dpkg --compare-versions "$2" lt 2.7.1
	    then
		# This is for bug #149712.  Oops.
		perl -i -pe 's/DEBDIFF_SHOWMOVED/DEBDIFF_SHOW_MOVED/g' \
		    /etc/devscripts.conf
	    fi

	    if dpkg --compare-versions "$2" lt 2.7.90
	    then
		# Added in devscripts 2.7.90:
		cat >> /etc/devscripts.conf <<EOF

# debchange/dch option added in version 2.7.90:
#
# Query the BTS when --closes is being used?
# DEBCHANGE_QUERY_BTS=yes
#
# uupdate option added in version 2.7.90:
#
# Should we symlink the .orig.tar.gz file to its new name or
# copy it instead?  yes=symlink, no=copy
# UUPDATE_SYMLINK_ORIG=yes
EOF
	    fi

	    if dpkg --compare-versions "$2" lt 2.7.93
	    then
		# Added in devscripts 2.7.93:
		cat >> /etc/devscripts.conf <<EOF

# debuild options added in version 2.7.93:
#
# Do we run linda at the end of a full run?
# DEBUILD_LINDA=no
#
# Extra options given to linda before any command-line options
# specified.
# DEBUILD_LINDA_OPTS=""

##### Package-wide variables first introduced in version 2.7.93:
#
# Lists of which scripts are affected by these package-wide variables
# can be found in the devscripts.conf(5) manpage.
#
#
# Directory Name Checking
#
# Several programs check the directory name and refuse to function if
# it does not match the name of the package being worked on.  (The
# details are described in the individual manpages.)
# These two variables control this behaviour, corresponding to the
# --check-dirname-level and --check-dirname-regex command line options.
# The possible values of DEVSCRIPTS_CHECK_DIRNAME_LEVEL are:
#   0    never check the directory name
#   1    check the directory name only if the program has changed directory
#   2    always check the directory name
# The variable DEVSCRIPTS_DIRNAME_REGEXP is a Perl regex which
# defines what is considered a valid directory name for the source
# package PACKAGE; if it includes a '/', then it must match the full
# directory path, otherwise it must match the full directory name.
#
# The default settings are:
# DEVSCRIPTS_CHECK_DIRNAME_LEVEL=1
# DEVSCRIPTS_CHECK_DIRNAME_REGEX='PACKAGE(-.+)?'
EOF
	    fi

	    if [ "$2" = "2.8.6" ]
	    then
		# Added in devscripts 2.8.6:
		cat >> /etc/devscripts.conf <<EOF

##### bts options changes between version 2.8.6 and version 2.8.7:
#
# The following option replaces the previous BTS_FULL_MIRROR option.
# How much to mirror when caching?  The minimal amount (min), the mbox
# version as well (mbox) or the whole works (full)?
# BTS_CACHE_MODE=min
#
# The following is a new option
# How do we read an mbox?  This will be split on whitespace, then
# %s is replaced by the mbox name and %% by a single %.
# BTS_MAIL_READER='mutt -f %s'
EOF
	    elif dpkg --compare-versions "$2" lt 2.8.7
	    then
		# Added in devscripts 2.8.6 and 2.8.7:
		cat >> /etc/devscripts.conf <<EOF

##### bts options added in versions 2.8.6 and 2.8.7:
#
# Default bts show/bugs to run in offline mode?
# BTS_OFFLINE=no
#
# Cache all visited bug reports once a cache has been established
# for the first time?
# BTS_CACHE=yes
#
# How much to mirror when caching?  The minimal amount (min), the mbox
# version as well (mbox) or the whole works (full)?
# BTS_CACHE_MODE=min
#
# Always refresh the cache, even if nothing's changed?
# BTS_FORCE_REFRESH=no
#
# How do we read an mbox?  This will be split on whitespace, then
# %s is replaced by the mbox name and %% by a single %.
# BTS_MAIL_READER='mutt -f %s'
EOF
	    fi

	    if dpkg --compare-versions "$2" lt 2.8.12
	    then
		# Added in devscripts 2.8.12:
		cat >> /etc/devscripts.conf <<EOF

##### uscan option added in version 2.8.12:
#
# Should we use DEHS style output (XML format)?
# USCAN_DEHS_OUTPUT=no
#
EOF
	    fi
	fi

	# The next section is all post-sarge updates
	if dpkg --compare-versions "$2" lt 2.8.15
	then
	# Added in devscripts 2.8.15:
	    cat >> /etc/devscripts.conf <<EOF

##### debchange option added in version 2.8.15:
#
# Select a heuristic to use to determine whether the package has released.
# See the debchange man page for details.
# DEBCHANGE_RELEASE_HEURISTIC=log
# DEBCHANGE_RELEASE_HEURISTIC=changelog
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.9.5
	then
	# Added in devscripts 2.9.5:
	    cat >> /etc/devscripts.conf <<EOF

##### debchange option added in version 2.9.5:
#
# Introduce multiple-maintainer markers in changelog sections?
# DEBCHANGE_MULTIMAINT=yes
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.9.15
	then
	# Added in devscripts 2.9.15:
	    cat >> /etc/devscripts.conf <<EOF

##### bts option added in version 2.9.15
#
# What sendmail command do we use?  This will be split on whitespace.
# BTS_SENDMAIL_COMMAND='/usr/sbin/sendmail'

##### dpkg-sig options added in version 2.9.15
#
# dpkg-sig is not a part of devscripts, but shares this configuration file.
# It pays attention to the values of DEBSIGN_MAINT and DEBSIGN_KEY in
# addition to the following.
#
# This key ID takes precedence over the rest
# DPKGSIG_KEYID=
#
# Do we sign the .changes and .dsc files?  See the manpage for more
# info.  Valid options are no, auto, yes, full and force_full.
# DPKGSIG_SIGN_CHANGES=auto
#
# Do we cache the gpg passphrase by default?  This can be dangerous!
# DPKGSIG_CACHE_PASS=no

##### pts-subscribe added in version 2.9.15
#
# How long will we subscribe for by default?  The default is 30 days.
# Setting this to 'forever' means that no unsubscription request will
# be scheduled.
# PTS_UNTIL='now + 30 days'
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.9.17
	then
	# Added in devscripts 2.9.17:
	    cat >> /etc/devscripts.conf <<EOF

##### debdiff option added in version 2.9.17
#
# Which control files to compare?  A comma-separated list, with
# possibilities such as postinst, config and so on; ALL means compare
# all control files.
# DEBDIFF_CONTROLFILES=control

##### debrelease/debc/debi option added in version 2.9.17
#
# This specifies the directory, relative to the top of the source
# tree, in which the .changes and .debs files are to be found.  Note
# that this option affects all of debrelease, debc and debi.
# DEBRELEASE_DEBS_DIR=..

##### debuild options added in version 2.9.17
#
# Do we check for the existence of the .orig.tar.gz before calling
# dpkg-buildpackage?
# DEBUILD_TGZ_CHECK=yes
#
# Hooks; see the manpage for details of these
# DEBUILD_DPKG_BUILDPACKAGE_HOOK=""
# DEBUILD_CLEAN_HOOK=""
# DEBUILD_DPKG_SOURCE_HOOK=""
# DEBUILD_BUILD_HOOK=""
# DEBUILD_BINARY_HOOK=""
# DEBUILD_FINAL_CLEAN_HOOK=""
# DEBUILD_LINTIAN_HOOK=""
# DEBUILD_SIGNING_HOOK=""
# DEBUILD_POST_DPKG_BUILDPACKAGE_HOOK=""

##### who-uploads options added in version 2.9.17
#
# Maximum number of uploads to display per package
# WHOUPLOADS_MAXUPLOADS=3
#
# Colon-separated list of keyrings to examine by default
# WHOUPLOADS_KEYRINGS=/usr/share/keyrings/debian-keyring.gpg:/usr/share/keyrings/debian-keyring.pgp
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.9.26
	then
	    # Added in devscripts 2.9.25/26, but version comparison test was
	    # incorrect in version 2.9.25:
	    cat >> /etc/devscripts.conf <<EOF

##### nmudiff options added in versions 2.9.25 and 2.9.26
#
# Should we use mutt to edit and send the message or just a plain old
# editor?
# NMUDIFF_MUTT=yes
#
# Should we always submit a new report (yes), always send to the bugs
# which are being closed (no), or send to the bug being closed if
# there is only one of them, otherwise send a new report (maybe)?
# NMUDIFF_NEWREPORT=maybe
#
# nmudiff also uses the value of BTS_SENDMAIL_COMMAND if NMUDIFF_MUTT=no

##### dget option added in version 2.9.26
#
# Extra directories to search for files in addition to
# /var/cache/apt/archives.  This is a colon-separated list of directories.
# DGET_PATH=""
EOF

	fi

  	if dpkg --compare-versions "$2" lt 2.10.3
        then
            # Added in devscripts 2.10.3
            cat >> /etc/devscripts.conf <<EOF

##### licensecheck options added in version 2.10.3
#
# Print the file header being parsed before the corresponding license
# information?
# LICENSECHECK_VERBOSE=no
#
# How many lines of each file should be parsed for license information?
# LICENSECHECK_PARSELINES=60

##### debchange option added in version 2.10.3
#
# Use a fixed timezone in changelog entries?
# DEBCHANGE_TZ=UTC
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.4
	then
	    # Added in devscripts 2.10.4
	    cat >> /etc/devscripts.conf <<EOF

##### debchange option added in version 2.10.4
#
# When appending to a multiple-maintainer changelog, if there are
# existing changes made by the current maintainer, should new
# changelog entries be appended to the existing entries?
# DEBCHANGE_MULTIMAINT_MERGE=no
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.5
	then
	    # Added in devscripts 2.10.5
	    # BTS_ONLY_NEW was added in 2.10.2 but not added to the
	    # configuration files
	    cat >> /etc/devscripts.conf <<EOF

##### bts option added in version 2.10.2
# Download only new bugs when caching?  If set to yes, don't check for
# updates in bugs we already have.
# BTS_ONLY_NEW=no

##### bts options added in version 2.10.5
#
# Which SMTP host should be used?  Note that if both an SMTP host and
# sendmail command are specified in the configuration file(s), the SMTP
# host will be used unless overridden by --sendmail on the command line
# BTS_SMTP_HOST=bugs.debian.org
#
# Include resolved bugs when caching?
# BTS_INCLUDE_RESOLVED=yes
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.7
	then
	    # Added in devscripts 2.10.7
	    cat >> /etc/devscripts.conf <<EOF

##### uscan option added in version 2.10.7
#
# What user agent string should we send with requests?
# (Default is 'Debian uscan X.Y.Z')
# USCAN_USER_AGENT=''
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.8
	then
	    # Added in devscripts 2.10.8
	    cat >> /etc/devscripts.conf <<EOF

##### debcommit option added in version 2.10.8
#
# Strip a leading "* " from commit messages taken from changelogs?
# DEBCOMMIT_STRIP_MESSAGE=no
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.10
	then
	    # Added in devscripts 2.10.10
	    cat >> /etc/devscripts.conf <<EOF

##### debcommit option added in version 2.10.10
#
# Sign created tags using gnupg?
# DEBCOMMIT_SIGN_TAGS=no
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.12
	then
	    # Added in devscripts 2.10.12
	    cat >> /etc/devscripts.conf <<EOF
##### debchange option added in version 2.10.12
#
# When appending entries to the changelog, should the trailer line
# be maintained as-is?
# DEBCHANGE_MAINTTRAILER=yes
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.14
	then
	    # Actually added in devscrips 2.10.9
	    # but not added to the configuration file
	    cat >> /etc/devscripts.conf <<EOF

##### uscan option added in version 2.10.9
#
# Where should downloaded files be placed?
# USCAN_DESTDIR=..
EOF
	    # Added in devscripts 2.10.14
	    cat >> /etc/devscripts.conf <<EOF

##### bts option added in version 2.10.14
#
# Suppress BTS acknowledgment e-mails (ignored by the control bot)
# BTS_SUPPRESS_ACKS=no
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.17
	then
	    # Added in devscripts 2.10.17
	    cat >> /etc/devscripts.conf <<EOF

##### dget options added in version 2.10.17
#
# Unpack downloaded source packages
# DGET_UNPACK=yes
# Verify source package signatures using dscverify
# DGET_VERIFY=yes
#
##### bts options added in version 2.10.17
#
# Allow the generated message to be edited and, if necessary, abandoned
# before sending it to the control bot?
#
# If set to yes, prompt for confirmation / edit / abandonment.
# If set to force, spawn an editor and then proceed as if set to yes
# BTS_INTERACTIVE=no

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.19
	then
	    # Added in devscripts 2.10.19
	    cat >> /etc/devscripts.conf <<EOF
##### debchange option added in version 2.10.19
#
# Allow a new version to be lower than the current package version
# if the new version matches the specified regular expression
# DEBCHANGE_LOWER_VERSION_PATTERN=bpo

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.20
	then
	    # Added in devscripts 2.10.20
	    cat >> /etc/devscripts.conf <<EOF
##### debcommit option added in version 2.10.20
#
# Take any uncommitted changes in the changelog in
# to account when determining the commit message
# for a release?
# DEBCOMMIT_RELEASE_USE_CHANGELOG=no

##### debuild options added in version 2.10.20
#
# Colon-separated list of options to be added to the beginning
# of PATH once it has been sanitised
# DEBUILD_PREPEND_PATH="/usr/lib/ccache"
#
# Credentials to pass to debrsign when signing dsc / changes files
# Setting this option to a non-blank string implies using debrsign
# DEBUILD_SIGNING_USERNAME="user@host"

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.21
	then
	    # Added in devscripts 2.10.21
	    cat >> /etc/devscripts.conf <<EOF
##### bts options added in version 2.10.21
#
# If the SMTP host specified above requires authentication, the following
# options may be used to specify the username and password to use.
# If only a username is provided then the password will be prompted for
# before sending the e-mail
# BTS_SMTP_AUTH_USERNAME=user
# BTS_SMTP_AUTH_PASSWORD=pass

##### debdiff option added in version 2.10.21
# Include the output of diffstat?
# DEBDIFF_SHOW_DIFFSTAT=no

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.22
	then
	    # Added in devscripts 2.10.22
	    cat >> /etc/devscripts.conf <<EOF
##### bts option added in version 2.10.22
#
# Specify a list of e-mail addresses to which a carbon copy of the
# generated e-mail to the control bot should automatically be sent.
# BTS_DEFAULT_CC=example@example.com

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.24
	then
	    # Added in devscripts 2.10.24
	    cat >> /etc/devscripts.conf <<EOF
##### debchange option added in version 2.10.24
#
# Attempt to automatically determine whether the current changelog
# stanza represents an NMU?
# DEBCHANGE_AUTO_NMU=yes

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.26
	then
	    # Added in devscripts 2.10.26
	    cat >> /etc/devscripts.conf <<EOF
##### rmadison option added in version 2.10.26
#
# Add a custom URL to the default list of shorthands so one
# can use it with -u without having to specify the full URL
#
# RMADISON_URL_MAP_EXAMPLE=http://example.com/madison.cgi

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.30
	then
	    # Added in devscripts 2.10.30
	    cat >> /etc/devscripts.conf <<EOF
##### who-uploads option added in version 2.10.30
#
# Display the date of the upload?
#
# WHOUPLOADS_DATE=no

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.36
	then
	    # Added in devscripts 2.10.36
	    cat >> /etc/devscripts.conf <<EOF
##### debdiff option added in version 2.10.36
#
# Compare control files in source packages using widff?
#
# DEBDIFF_WDIFF_SOURCE_CONTROL=no

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.38
	then
	    if [ -f "/etc/devscripts.con" ] &&
	      [ "10cabcba2772fc97064bf2f51b39bf25" = \
	      "$(md5sum /etc/devscripts.con | cut -d" " -f1)" ]
	    then
		rm /etc/devscripts.con

		# Added in devscripts 2.10.36 but to the wrong file
		cat >> /etc/devscripts.conf <<EOF
##### debdiff option added in version 2.10.36
#
# Compare control files in source packages using widff?
#
# DEBDIFF_WDIFF_SOURCE_CONTROL=no

EOF
	    fi
	    cat >> /etc/devscripts.conf << EOF
##### mk-build-deps options added in version 2.10.38
#
# Which tool to use for installing build depends?
# MKBUILDDEPS_TOOL=/usr/bin/apt-get
#
# Remove package files after install?
# MKBUILDDEPS_REMOVE_AFTER_INSTALL=yes
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.39
	then
	    cat >> /etc/devscripts.conf << EOF
##### bts option added in version 2.10.39
#
# Specify a HELO to use when connecting to the SMTP host. If not supplied
# and the file /etc/mailname exists, its contents will be used as the HELO
# BTS_SMTP_HELO=foo.example.com

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.40
	then
	    cat >> /etc/devscripts.conf << EOF
##### debcheckout option added in version 2.10.40
#
# List of space-separated pairs REGEXP/REPLACEMENT_TEXT to define
# custom rules to enable authenticated mode.
# See debcheckout(1) for a more precise description of syntax and
# semantics of this setting.
# DEBCHECKOUT_AUTH_URLS=''

##### uscan option added in version 2.10.40
#
# Automatically repack bzipped tar or zip archives to gzipped tars?
# USCAN_REPACK=no
EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.44
	then
	    cat >> /etc/devscripts.conf << EOF
##### bts option added in 2.10.44
#
# Which debbugs server should be used?
# BTS_SERVER=bugs.debian.org

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.45
	then
	    cat >> /etc/devscripts.conf << EOF
##### debsnap options added in 2.10.45
#
# Where to put the directory named <prefix>-<package>/
# default: source-$package_name if unset
# DEBSNAP_DESTDIR=
#
# Verbosely show messages (yes/no)
# default: no
# DEBSNAP_VERBOSE=no
#
# The base URL of the archive to download from
# DEBSNAP_BASE_URL=http://snapshot-dev.debian.org

##### debdiff option added in 2.10.45
#
# Always compare package in version order, rather than the order specified
# on the command line?
# DEBDIFF_AUTO_VER_SORT=no

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.47
	then
	    cat >> /etc/devscripts.conf << EOF
##### dcontrol option added in 2.10.47
#
# URL to query
# DCONTROL_URL="http://qa.debian.org/cgi-bin/dcontrol"

#### nmudiff option added in 2.10.47
#
# Number of days to indicate that an NMU upload has been delayed by
# using the DELAYED upload queue. 0 indicates no delay.
# Defaults to "XX" which adds a placeholder to the e-mail.
# NMUDIFF_DELAY=3

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.49
	then
	    cat >> /etc/devscripts.conf << EOF
#### rmadison option added in 2.10.49
#
# Default URL to use if none is specified on the command line.
# RMADISON_DEFAULT_URL=debian

#### debchange option added in 2.10.49
#
# When --release was used and an editor presented, force the changelog
# to be explicitly saved in the editor?  If this is set to "no" then
# the changes made by --release will be automatically saved.
# DEBCHANGE_FORCE_SAVE_ON_RELEASE=yes

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.54
	then
	    cat >> /etc/devscripts.conf << EOF
#### debdiff option added in 2.10.54
#
# Unpack tarballs found in the top level source directory.
# DEBDIFF_UNPACK_TARBALLS=yes

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.70
	then
	    cat >> /etc/devscripts.conf << EOF
#### debcheckout option added in 2.10.70
#
# For debian-dir-only repositories, also retrieve the source
# package, unpack it, and move the missing files over.
# (never auto download-only always)
# DEBCHECKOUT_SOURCE=auto

#### rmadison option added in 2.10.70
#
# Default architecture to use if none is specified on the command line.
# use --architecture='*' to override RMADISON_ARCHITECTURE
# RMADISON_ARCHITECTURE=source,i386,amd64,all

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.10.72
	then
	    cat >> /etc/devscripts.conf << EOF
#### mk-build-deps option added in 2.10.72
#
# Tool used to gain root privileges to install the deb
# MKBUILDDEPS_ROOTCMD=''

EOF
	fi

	if dpkg --compare-versions "$2" lt 2.11.0
	then
	    cat >> /etc/devscripts.conf << EOF
#### debsign option added in 2.11.0
#
# Always re-sign files even if they are already signed, without prompting.
# DEBSIGN_ALWAYS_RESIGN=yes

EOF
	fi
    fi
fi

#DEBHELPER#
