#!/bin/sh
#
# This is the postinst script for the Debian GNU/Linux mirror package
#
# Written by Dirk Eddelbuettel <edd@debian.org>   

set -e 

#if [ "$1" = configure ] && command -v install-docs >/dev/null 2>&1; then
#	install-docs -i /usr/share/doc-base/mirror
#fi

patchdir=/usr/share/doc/mirror/applied-patches

case "$1" in
    configure)
	#
	# We have to patch mirror as Lee has disappeared from the face of the 
	# earth; see /usr/share/doc/mirror/applied-patches about the code
	echo  "** Patching mirror files, see /usr/share/doc/mirror/README.Debian.gz. **"
	cd /usr/bin
 	patch -p0 <$patchdir/mirror-master_2.9.dpat
 	patch -p0 <$patchdir/pkgs_to_mmin_2.9.dpat 
 	patch -p0 <$patchdir/do_unlinks_2.9.dpat
 	cd /usr/share/mirror/
 	zcat $patchdir/mirror.pl_2.9.dpat.gz | patch -p0 
	patch -p0 <$patchdir/ftp.pl_2.9.dpat
	patch -p0 <$patchdir/lchat.pl_2.9.dpat
	patch -p0 <$patchdir/dateconv.pl_2.9.dpat
	patch -p0 <$patchdir/lsparse.pl_2.9.dpat
 	cd /usr/share/doc/mirror
	gunzip mirror.txt
 	zcat $patchdir/mirror.txt_2.9.dpat.gz | patch -p0 
	gzip -9 mirror.txt
	cd html
 	patch -p0 <$patchdir/mirror.html_2.9.dpat
	#
	# mirror-master(8) doesn't like it if there is no mm.status file, 
	# but we don't want to overwrite an existing one
	if [ ! -f /var/log/mirror/mm.status ]
	then
	    touch /var/log/mirror/mm.status
	    chgrp adm /var/log/mirror/mm.status
	fi
	#
	## In some cases (#51023) an old directory seems to persist
	## Removed code for /usr/doc/mirror before 2.9-41
	;;
    abort-upgrade|abort-remove|abort-deconfigure)
	exit 0
	;;
    *)
	echo "postinst called with unknown argument \`$1'" >&2
	exit 0
	;;
esac


