#!/bin/sh

PKG_METADIR=$1
PKG_NAME=$2
PKG_VERSION=$3
PKG_ORIGIN=$4
PKG_COMMENT=$5
PKG_PREFIX=$6
PKG_DEPENDS=$7
PKG_DESCR=$8
PKG_PREINS=$9
PKG_POSTINS=${10}

#echo "Create meta.... metadir pkg_name pkg_version origin comment prefix depends description preinstall postinstall"
echo "### meta : $PKG_METADIR,$PKG_NAME,$PKG_VERSION,$PKG_ORIGIN,$PKG_COMMENT,$PKG_PREFIX,$PKG_DEPENDS,$PKG_DESCR,$PKG_PREINS,$PKG_POSTINS"

PKG_MANIFESTF="$PKG_METADIR/+MANIFEST"
PKG_DESC="$PKG_METADIR/+DESC"
PKG_MENT="$PKG_METADIR/COMMENT"
PKG_PREINSTALL="$PKG_METADIR/+PRE_INSTALL"
PKG_POSTINSTALL="$PKG_METADIR/+POST_INSTALL"


# 2020-12-28 FreeBSD 12.2 code add (#33367)
OS=`uname -r | cut -c1-2 | bc`


## create-manifes
mkdir -p $PKG_METADIR

echo "name: $PKG_NAME" >> ${PKG_MANIFESTF}
echo "version: $PKG_VERSION" >> ${PKG_MANIFESTF}
echo "origin: $PKG_ORIGIN" >> ${PKG_MANIFESTF}

if [ $OS -ge 12 ]; then
	echo "comment: " >> ${PKG_MANIFESTF}
	echo "  \""`cat $PKG_COMMENT`"\"" >> ${PKG_MANIFESTF}
else
	echo "comment: |" >> ${PKG_MANIFESTF}
	echo "   "`cat $PKG_COMMENT` >> ${PKG_MANIFESTF}
fi


echo "prefix: $PKG_PREFIX" >> ${PKG_MANIFESTF}
echo "maintainer: service.storage@solbox.com" >> ${PKG_MANIFESTF}
echo "deps: "  >> ${PKG_MANIFESTF}
#echo "$PKG_DEPENDS" | sed  's/^/  /' >>  ${PKG_MANIFESTF}
echo "$PKG_DEPENDS" | sed  's/\^/\
/g' >>  ${PKG_MANIFESTF}

if [ $OS -ge 12 ]; then
	#echo "categories: " >> ${PKG_MANIFESTF}
else
	echo "categories: " >> ${PKG_MANIFESTF}
fi

echo "licenselogic: single" >> ${PKG_MANIFESTF}
echo "licenses: []" >> ${PKG_MANIFESTF}

cp -f $PKG_COMMENT $PKG_MENT
cp -f $PKG_DESCR $PKG_DESC
cp -f $PKG_PREINS $PKG_PREINSTALL
cp -f $PKG_POSTINS $PKG_POSTINSTALL

