[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Installing PEAR packages in an idempotent fashion



On Fri, Apr 18, 2008 at 05:13:29PM +0100, Colin Turner wrote:
> Hi,
>
> My package needs a Pear package, specifically Pear Log, it has php-pear  
> in its dependencies.
>
> The big problem is installing the package itself in, I presume, the  
> postinst script. My early tests were simply:
>
> pear -q install log
>
> but I found that when the package was installed this process would quit  
> with an error second time around, stopping the script from being  
> idempotent. At some stage this problem seemed to evaporate (maybe with  
> lenny).

> Has anybody any words of wisdom to offer on how to handle pear module  
> installations in an idempotent fashion?
You could read the source for "pear" and figure out under what
conditions it exits with an error, and avoid calling it in that case:
grep 'something' /path/somefile || pear -q install log.

You could also (perhaps) test in postinst the $2 value to see if the
package has been configured before (the earlier solution is better
IMO).

You could also test that, if it fails, it fails for that reason, and
allow that failure.

t=`tempfile`
trap 'rm -fv -- "$t"' EXIT
pear -q install log 2>"$tempfile" || {
	ret=$?
	grep -Fx "$the_error_message" >/dev/null "$t" || {
		cat "$t"
		exit $ret
	}
}

rm -f -- "$t"
trap - EXIT

#Justin


Reply to: