#!/bin/bash

set -e

###
### postinst script
###
### immitate dir_to_symlink functionality of dpkg-maintscript-helper
### for Debian wheezy-backport upload.
###

PATHNAME="/usr/share/php/AWSSDKforPHP"
SYMLINK_TARGET="."
LASTVERSION="2.5.1-1~"
PACKAGE="php-aws-sdk"

# taken from dpkg-maintscript-helper in dpkg 1.17.8 and shortened

finish_dir_to_symlink()
{
	local PATHNAME="$1"
	local SYMLINK_TARGET="$2"

	rm "$PATHNAME/.dpkg-staging-dir"
	find "$PATHNAME" -mindepth 1 -print0 | \
	        xargs -0 -i% mv -f "%" "$SYMLINK_TARGET/"
	rmdir "$PATHNAME"
	ln -s "$SYMLINK_TARGET" "$PATHNAME"
	rm -rf "${PATHNAME}.dpkg-backup"
}


# We cannot bail depending on the version, as here we only
# know what was the last configured version, and we might
# have been unpacked, then upgraded with an unpack and thus
# never been configured before.
if [ "$1" = "configure" ] &&
   [ -d "${PATHNAME}.dpkg-backup" ] &&
   [ ! -h "$PATHNAME" ] && [ -d "$PATHNAME" ] &&
   [ -f "$PATHNAME/.dpkg-staging-dir" ]; then
	finish_dir_to_symlink "$PATHNAME" "$SYMLINK_TARGET"
fi

#DEBHELPER#

exit 0