Koha/debian/scripts/koha-functions.sh
Tomas Cohen Arazi 4e7734ce33 Bug 16016: Sitemap handling scripts for packages
This patch introduces the koha-sitemap script. This script wraps calls to
the misc/cronjobs/sitemap.pl script so it can be done easily instance-wise.

It sets /var/lib/koha/${instance}/sitemap as the destination directory for
the sitemap files. A followup will make them available through an Apache
configuration entry.

koha-functions.sh is provided with a handy is_sitemap_enabled function so
we can later add filters to other commands (koha-list, koha-foreach, etc).

Exposes sitemap files to apache. This is suitable for including the sitemap in
the robots.txt file as proposed in

  http://www.sitemaps.org/protocol.html#submit_robots

Note: it depends on Apache 2.4+ so we can patch the file as needed. Older
Apache users will be warned that they need to tweak the apache files on their
own.

To test:
- You can build a package out of this patchset, or do the following on a kohadevbox
  cp debian/scripts/koha-functions.sh /usr/share/koha/bin
- Run
  $ debian/scripts/koha-sitemap --help
- Go through all the options (--enable, --disable, generate).
(a) --enable:
  - debian/scripts/koha-sitemap --enable kohadev
=> SUCCESS: /var/lib/koha/kohadev/sitemap.enabled is created
  - call it again, a suitable warning is raised and the file is still there
(b) debian/scripts/koha-sitemap --disable kohadev
=> SUCCESS: /var/lib/koha/kohadev/sitemap.enabled is deleted
  - call it again, a suitable warning is raised and the file does not exist
(c) --generate:
  - debian/scripts/koha-sitemap --generate kohadev
=> SUCCESS: sitemapindex.xml and sitemap000X.xml files are generated in
            /var/lib/koha/kohadev/sitemap/
- Sign off :-D

Sponsored-by: Orex Digital
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2016-05-04 13:34:21 +00:00

235 lines
4.8 KiB
Bash
Executable file

#!/bin/sh
#
# koha-functions.sh -- shared library of helper functions for koha-* scripts
# Copyright 2014 - Tomas Cohen Arazi
# Universidad Nacional de Cordoba
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
die()
{
echo "$@" 1>&2
exit 1
}
warn()
{
echo "$@" 1>&2
}
get_apache_config_for()
{
local site=$1
local sitefile="/etc/apache2/sites-available/$site"
if is_instance $site; then
if [ -f "$sitefile.conf" ]; then
echo "$sitefile.conf"
elif [ -f "$sitefile" ]; then
echo "$sitefile"
fi
fi
}
get_opacdomain_for()
{
local site=$1
if [ -e /etc/koha/koha-sites.conf ]; then
. /etc/koha/koha-sites.conf
else
echo "Error: /etc/koha/koha-sites.conf not present." 1>&2
exit 1
fi
local opacdomain="$OPACPREFIX$site$OPACSUFFIX$DOMAIN"
echo "$opacdomain"
}
get_intradomain_for()
{
local site=$1
if [ -e /etc/koha/koha-sites.conf ]; then
. /etc/koha/koha-sites.conf
else
echo "Error: /etc/koha/koha-sites.conf not present." 1>&2
exit 1
fi
local intradomain="$INTRAPREFIX$site$INTRASUFFIX$DOMAIN"
echo "$intradomain"
}
letsencrypt_get_opacdomain_for()
{
local site=$1
if [ -e /var/lib/koha/$site/letsencrypt.enabled ]; then
. /var/lib/koha/$site/letsencrypt.enabled
else
local opacdomain=$(get_opacdomain_for $site)
fi
echo "$opacdomain"
}
is_enabled()
{
local site=$1
local instancefile=$(get_apache_config_for $site)
if [ "$instancefile" = "" ]; then
return 1
fi
if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
"$instancefile" ; then
return 1
else
return 0
fi
}
is_instance()
{
local instancename=$1
if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
-type d -printf '%f\n'\
| grep -q -x "$instancename" ; then
return 0
else
return 1
fi
}
is_email_enabled()
{
local instancename=$1
if [ -e /var/lib/koha/$instancename/email.enabled ]; then
return 0
else
return 1
fi
}
is_letsencrypt_enabled()
{
local instancename=$1
if [ -e /var/lib/koha/$instancename/letsencrypt.enabled ]; then
return 0
else
return 1
fi
}
is_sip_enabled()
{
local instancename=$1
if [ -e /etc/koha/sites/$instancename/SIPconfig.xml ]; then
return 0
else
return 1
fi
}
is_sitemap_enabled()
{
local instancename=$1
if [ -e /var/lib/koha/$instancename/sitemap.enabled ]; then
return 0
else
return 1
fi
}
is_zebra_running()
{
local instancename=$1
if daemon --name="$instancename-koha-zebra" \
--pidfiles="/var/run/koha/$instancename/" \
--user="$instancename-koha.$instancename-koha" \
--running ; then
return 0
else
return 1
fi
}
is_indexer_running()
{
local instancename=$1
if daemon --name="$instancename-koha-indexer" \
--pidfiles="/var/run/koha/$instancename/" \
--user="$instancename-koha.$instancename-koha" \
--running ; then
return 0
else
return 1
fi
}
is_plack_enabled()
{
local site=$1
local instancefile=$(get_apache_config_for $site)
if [ "$instancefile" = "" ]; then
return 1
fi
if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-opac-plack.conf' \
"$instancefile" && \
grep -q '^[[:space:]]*Include /etc/koha/apache-shared-intranet-plack.conf' \
"$instancefile" ; then
return 0
else
return 1
fi
}
is_plack_running()
{
local instancename=$1
if start-stop-daemon --pidfile "/var/run/koha/${instancename}/plack.pid" \
--status ; then
return 0
else
return 1
fi
}
get_instances()
{
find /etc/koha/sites -mindepth 1 -maxdepth 1\
-type d -printf '%f\n' | sort
}
get_loglevels()
{
local instancename=$1
local retval=$(xmlstarlet sel -t -v 'yazgfs/config/zebra_loglevels' /etc/koha/sites/$instancename/koha-conf.xml)
if [ "$retval" != "" ]; then
echo "$retval"
else
echo "none,fatal,warn"
fi
}