#!/bin/sh
#
# $NetBSD: header,v 1.3 2014/12/30 15:13:20 wiz Exp $

SELF="$0"
PKGNAME="$1"
STAGE="$2"
shift 2

AWK="/usr/bin/awk"
BASENAME="/usr/bin/basename"
CAT="/bin/cat"
CHGRP="/usr/bin/chgrp"
CHMOD="/bin/chmod"
CHOWN="/usr/sbin/chown"
CMP="/usr/bin/cmp"
CP="/bin/cp"
DIRNAME="/usr/bin/dirname"
ECHO="echo"
ECHO_N="echo -n"
EGREP="/usr/bin/egrep"
EXPR="/bin/expr"
FALSE="false"
FIND="/usr/bin/find"
GREP="/usr/bin/grep"
GTAR=""
HEAD="/usr/bin/head"
ID="/usr/bin/id"
LINKFARM="/usr/sbin/linkfarm"
LN="/bin/ln"
LS="/bin/ls"
MKDIR="/bin/mkdir -p"
MV="mv -f"
PERL5="/usr/pkg/bin/perl"
PKG_ADMIN="/usr/sbin/pkg_admin"
PKG_INFO="/usr/sbin/pkg_info"
PWD_CMD="/bin/pwd"
RM="/bin/rm"
RMDIR="/bin/rmdir"
SED="/usr/bin/sed"
SETENV="/usr/bin/env"
SH="/bin/sh"
SORT="/usr/bin/sort"
SU="/usr/bin/su"
TEST="test"
TOUCH="/usr/bin/touch"
TR="/usr/bin/tr"
TRUE="true"
XARGS="/usr/bin/xargs"

CURDIR=`${PWD_CMD}`
: ${PKG_METADATA_DIR=${CURDIR}}
PKGBASE="ja-elisat"

LOCALBASE="/usr/pkg"
X11BASE="/usr/X11R7"
PREFIX="/usr/pkg"

PKG_SYSCONFBASE="/usr/pkg/etc"
PKG_SYSCONFBASEDIR="/usr/pkg/etc"
PKG_SYSCONFDIR="/usr/pkg/etc"
CONF_DEPENDS=""

CONF_IGNORE_FILES="*[~#] *.OLD *.orig *,v .pkgsrc */.pkgsrc"

case "${PKG_CONFIG:-YES}" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
	_PKG_CONFIG=yes
	;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
	_PKG_CONFIG=yes
	;;
esac

# $NetBSD: fonts,v 1.7 2014/06/01 16:57:27 wiz Exp $
#
# Generate a +FONTS script that updates font databases for the package.
#
case "${STAGE},$1" in
UNPACK,|UNPACK,+FONTS)
	${CAT} > ./+FONTS << 'EOF'
#!/bin/sh
#
# +FONTS - font database management script
#
# Usage: ./+FONTS [metadatadir]
#
# This scripts rebuilds font databases needed by the package associated
# with <metadatadir>.
#
# Lines starting with "# FONTS: " are data read by this script that name
# the directories in which the font database will be rebuilt.
#
#	# FONTS: /usr/pkg/share/fonts/X11/TTF ttf
#	# FONTS: /usr/pkg/share/fonts/X11/Type1 type1
#	# FONTS: /usr/pkg/share/fonts/X11/misc x11
#
# For each FONTS entry, if the path is relative, that it is taken to be
# relative to ${PKG_PREFIX}.
#

ECHO="echo"
FIND="/usr/bin/find"
GREP="/usr/bin/grep"
MKFONTDIR="/usr/X11R7/bin/mkfontdir"
PWD_CMD="/bin/pwd"
RM="/bin/rm"
RMDIR="/bin/rmdir"
SED="/usr/bin/sed"
SORT="/usr/bin/sort"
TEST="test"
TRUE="true"
TTF_INDEX_CMD="@TTF_INDEX_CMD@"
TYPE1_INDEX_CMD="@TYPE1_INDEX_CMD@"
TYPE1_POSTINDEX_CMD="@TYPE1_POSTINDEX_CMD@"
X11_ENCODINGSDIR="/usr/X11R7/lib/X11/fonts/encodings"

SELF=$0

CURDIR=`${PWD_CMD}`
PKG_METADATA_DIR="${1-${CURDIR}}"
: ${PKGNAME=${PKG_METADATA_DIR##*/}}
: ${PKG_PREFIX=/usr/pkg}

case "${PKG_UPDATE_FONTS_DB:-YES}" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
	_PKG_UPDATE_FONTS_DB=yes
	;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
	_PKG_UPDATE_FONTS_DB=no
	;;
esac

case "${FONTS_VERBOSE:-NO}" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
	echo="${ECHO}"
	;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
	echo=":"
	;;
esac

${SED} -n "/^\# FONTS: /{s/^\# FONTS: //;p;}" ${SELF} | ${SORT} -u |
while read dir font_type; do
	case ${_PKG_UPDATE_FONTS_DB} in
	no)	continue ;;
	esac
	case $dir in
	"")	continue ;;
	[!/]*)	dir="${PKG_PREFIX}/$dir" ;;
	esac
	${TEST} -d "$dir" || continue
	( $echo "${PKGNAME}: updating font database in $dir ($font_type)"
	  cd $dir
	  update_args=
	  post_update_cmd=
	  case $font_type in
	  [tT][tT][fF])		update_cmd="${TTF_INDEX_CMD}" ;;
	  [tT][yY][pP][eE]1)	update_cmd="${TYPE1_INDEX_CMD}"
				post_update_cmd="${TYPE1_POSTINDEX_CMD}" ;;
	  [xX]11)		update_cmd="${MKFONTDIR}"
				[ ! -z "${X11_ENCODINGSDIR}" ] && update_args="-e ${X11_ENCODINGSDIR}" ;;
	  esac
	  ${TEST} -f "$update_cmd" || update_cmd="${TRUE}"
	  $update_cmd $update_args >/dev/null
	  $post_update_cmd
	  #
	  # Remove fonts databases if there are no fonts in the directory.
	  # We filter out the encodings.dir, fonts.{dirs,scale}, and
	  # Fontmap database files from the directory listing.  Also remove
	  # the directory if it turns out to be empty.
	  #
	  if ${FIND} . -type f | ${GREP} -v "/encodings.dir" | ${GREP} -v "/fonts\.scale" | \
	     ${GREP} -v "/fonts\.dir" | ${GREP} -v "/Fontmap" >/dev/null
	  then
	      : # Directory not empty; do nothing.
	  else
	      ${RM} -f fonts.dir fonts.scale Fontmap* encodings.dir
	      ${RMDIR} -p $dir 2>/dev/null
	  fi
	)
done

EOF
	${SED} -n "/^\# FONTS: /p" ${SELF} >> ./+FONTS
	${CHMOD} +x ./+FONTS
	;;
esac

# $NetBSD: install,v 1.5 2017/06/14 16:23:09 prlw1 Exp $

case ${STAGE} in
PRE-INSTALL)
	#
	# Unpack the helper scriptlets.
	#
	${SH} ${SELF} ${PKGNAME} UNPACK
	#
	# Require that necessary users and groups exist or else fail the
	# installation of the package.
	#
	${TEST} ! -x ./+USERGROUP ||
		{ ./+USERGROUP ADD ${PKG_METADATA_DIR}
		  if ./+USERGROUP CHECK-ADD ${PKG_METADATA_DIR}; then
			:
		  else
			exit 1
		  fi; }
	${TEST} ! -x ./+DIRS ||
		./+DIRS ADD ${PKG_METADATA_DIR}
	${TEST} ! -x ./+DIRS ||
		./+DIRS PERMS ${PKG_METADATA_DIR}
        ;;

POST-INSTALL)
	#
	# Rebuild the system run-time library search path database.
	#
	${TEST} ! -x ./+SHLIBS ||
		./+SHLIBS ADD ${PKG_METADATA_DIR}
	#
	# Copy configuration/support files into place.
	#
        ${TEST} ! -x ./+FILES ||
		./+FILES ADD ${PKG_METADATA_DIR}
        ${TEST} ! -x ./+FILES ||
		./+FILES PERMS ${PKG_METADATA_DIR}
	#
	# Set special permissions on any files/directories that need them.
	#
	${TEST} ! -x ./+PERMS ||
		./+PERMS ${PKG_METADATA_DIR}
	#
	# Update any fonts databases.
	#
	${TEST} ! -x ./+FONTS ||
		./+FONTS ${PKG_METADATA_DIR}

	#
	# Update any icon theme caches.
	#
	${TEST} ! -x ./+ICON_THEMES ||
		./+ICON_THEMES UPDATE ${PKG_METADATA_DIR}

	# Check for any missing bits after we're finished installing.
	#
	${TEST} ! -x ./+DIRS ||
		./+DIRS CHECK-ADD ${PKG_METADATA_DIR}
	${TEST} ! -x ./+DIRS ||
		./+DIRS CHECK-PERMS ${PKG_METADATA_DIR}
	${TEST} ! -x ./+FILES ||
		./+FILES CHECK-ADD ${PKG_METADATA_DIR}
	${TEST} ! -x ./+FILES ||
		./+FILES CHECK-PERMS ${PKG_METADATA_DIR}

	#
	# Register shells in /etc/shells.
	#
	${TEST} ! -x ./+SHELL ||
		./+SHELL ADD ${PKG_METADATA_DIR}
	${TEST} ! -x ./+SHELL ||
		./+SHELL CHECK-ADD ${PKG_METADATA_DIR}
	#
	# Register info files.
	#
	${TEST} ! -x ./+INFO_FILES ||
		./+INFO_FILES ADD ${PKG_METADATA_DIR}

  #
  # Register package into ocaml-findlib.
  #
  ${TEST} ! -x ./+OCAML_FINDLIB_REGISTER ||
    ./+OCAML_FINDLIB_REGISTER ADD ${PKG_METADATA_DIR}
	;;
esac

# $NetBSD: footer,v 1.1 2006/05/21 23:50:15 jlam Exp $

exit 0

# FONTS: share/fonts/X11/local x11
