#!/bin/sh
# TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
# reconfigure - TazPkg module
# Replay post_install from receipt


# Connect function libraries
. /lib/libtaz.sh

# Get TazPkg working environment
. @@MODULES@@/getenv




# Log TazPkg activity

log_pkg() {
	local extra
	[ -e "$LOG" ] || touch $LOG
	[ -w "$LOG" ] &&
	echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
}




PACKAGE="$1"

# Receipt function caller
# Why? "Bad" receipt sourcing can redefine some vital TazPkg variables.
# Few receipts functions should be patched now.

# Check for post_install function
if grep -q '^post_install()' "$INSTALLED/$PACKAGE/receipt"; then
	action 'Execute post-install commands...'
	tmp="$(mktemp)"
	cp "$INSTALLED/$PACKAGE/receipt" "$tmp"
	sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
	( . "$tmp"; post_install "$root" )
	status
	rm "$tmp"
	# Log this activity
	log_pkg Reconfigured
else
	newline
	_ 'Nothing to do for package "%s".' "$PACKAGE"
fi
