#!/bin/sh
#
# Generic INSTALL/REMOVE script. Arguments passed to this script:
#
# $1 = ACTION	[pre/post]
# $2 = PKGNAME
# $3 = VERSION
# $4 = UPDATE	[yes/no]
# $5 = CONF_FILE (path to xbps.conf)
# $6 = ARCH (uname -m)
#
# Note that paths must be relative to CWD, to avoid calling
# host commands if /bin/sh (dash) is not installed and it's
# not possible to chroot(3).
#

export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"

TRIGGERSDIR="./usr/libexec/xbps-triggers"
ACTION="$1"
PKGNAME="$2"
VERSION="$3"
UPDATE="$4"
CONF_FILE="$5"
ARCH="$6"

#
# The following code will run the triggers.
#

case ${ACTION} in
pre)
	# clean up certificates
	backup=etc/ca-certificates.conf.tmp
	mv etc/ca-certificates.conf $backup
	echo > etc/ca-certificates.conf
	env DESTDIR="$(pwd -P)" usr/sbin/update-ca-certificates --fresh >/dev/null 2>&1
	mv $backup etc/ca-certificates.conf
	;;
post)
	[ -s etc/ssl/certs/ca-certificates.crt ] || \
		rm -f etc/ssl/certs/ca-certificates.crt
	;;
esac

exit 0
