#!/bin/sh

#############################################################################
## 
##   Logtalk Debian package auxiliary script
##   Last updated on September 29, 2016
## 
##   This file is part of Logtalk <https://logtalk.org/>  
##   Copyright 1998-2019 Paulo Moura <pmoura@logtalk.org>
##   
##   Licensed under the Apache License, Version 2.0 (the "License");
##   you may not use this file except in compliance with the License.
##   You may obtain a copy of the License at
##   
##       http://www.apache.org/licenses/LICENSE-2.0
##   
##   Unless required by applicable law or agreed to in writing, software
##   distributed under the License is distributed on an "AS IS" BASIS,
##   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##   See the License for the specific language governing permissions and
##   limitations under the License.
## 
#############################################################################


echo ""
echo "Installed Logtalk on \"/usr/share\"."

chown -f -R -L root:root /usr/share/logtalk

echo ""
echo "Installing and registering Logtalk online documentation..."

if [ "$1" = "configure" ] ; then
	if which install-docs > /dev/null 2>&1 ; then
		install-docs -i /usr/share/doc-base/logtalk-docs
	fi
fi

chown -f -R -L root:root /usr/share/doc/logtalk

echo "Adding menu entries for some of the Logtalk integration scripts..."

if [ -x /usr/bin/update-menus ] ; then
	update-menus
fi

echo
echo "Links to the \"logtalk_user_setup\", \"logtalk_backend_select\","
echo "\"logtalk_version_select\", \"logtalk_tester\", \"logtalk_doclet\","
echo "\"lgt2pdf\", \"lgt2html\", \"lgt2xml\", \"lgt2md\", and \"lgt2txt\""
echo "scripts have been created on \"/usr/bin\"."
echo
echo "The following integration scripts are installed for running Logtalk"
echo "with selected backend Prolog compilers:"
echo
echo "* B-Prolog (version 7.8 or later):         bplgt"
echo "* CxProlog (version 0.98.1 or later):      cxlgt"
echo "* ECLiPSe (version 6.1#143 or later):      eclipselgt"
echo "* GNU Prolog (version 1.4.5 or later):     gplgt"
echo "* JIProlog (version 4.1.6.1 or later):     jiplgt      (first run may require sudo)"
echo "* Lean Prolog (version 4.5.4 or later):    lplgt       (experimental)"
echo "* Qu-Prolog (version 9.7 or later):        qplgt"
echo "* Quintus Prolog (version 3.3 or later):   quintuslgt  (experimental)"
echo "* SICStus Prolog (version 4.1.0 or later): sicstuslgt"
echo "* SWI-Prolog (version 6.6.0 or later):     swilgt"
echo "* XSB (version 3.8.0 or later):            xsblgt      (first run may require sudo)"
echo "* XSB MT (version 3.8.0 or later):         xsbmtlgt    (first run may require sudo)"
echo "* YAP (version 6.3.4 or later):            yaplgt"
echo
echo "Links to the Prolog integration scripts can be found on \"/usr/bin\"."
echo "Make sure that the Prolog compilers are properly installed and available"
echo "on your execution path."
echo
echo "Users should run the \"logtalk_user_setup\" shell script once before using"
echo "the integration scripts."
echo
echo "If you get an unexpected failure when using one of the Prolog integration"
echo "scripts, consult see the \"/usr/share/logtalk/adapters/NOTES.md\" file"
echo "for compatibility notes or consult the integration script man page."
echo

if [ -x /usr/bin/update-mime-database ] ; then
	mkdir -p /usr/share/mime/packages
	rm -f /usr/share/mime/packages/logtalk.xml
	cp /usr/share/logtalk/scripts/freedesktop/logtalk.xml /usr/share/mime/packages/logtalk.xml
	update-mime-database /usr/share/mime
	echo "Added the Logtalk mime-type to the Shared MIME-info Database."
	echo
fi

echo "Logtalk basic installation completed."
echo
exit 0
