3 # Copyright 2016 Theke Solutions
5 # This file is part of Koha.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 .
/lib
/lsb
/init-functions
24 # Read configuration variable file if it is present
25 [ -r /etc
/default
/koha-common
] && .
/etc
/default
/koha-common
27 # include helper functions
28 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
29 .
"/usr/share/koha/bin/koha-functions.sh"
31 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
37 local scriptname
=$
(basename $0)
42 This script lets you manage sitemaps for your Koha instances.
45 $scriptname --enable|--disable instancename1 [instancename2]
46 $scriptname --generate instancename1 [instancename2]
49 --enable Enable sitemap generation for the specified instances
50 --disable Disable sitemap generation for the specified instances
51 --generate (Re)generate stiemap for the specified instances
52 --quiet|-q Make the script quiet about non existent instance names
53 (useful for calling from another scripts).
54 --help|-h Display this help message
62 local libdir
="/var/lib/koha"
64 if is_sitemap_enabled
$instance; then
65 [ "$quiet" = "no" ] && \
66 warn
"Sitemap already enabled for ${instance}"
69 sudo
-u "$instance-koha" \
70 touch $libdir/$instance/sitemap.enabled
72 [ "$quiet" = "no" ] && \
73 warn
"Sitemap enabled for ${instance}"
80 local libdir
="/var/lib/koha"
82 if is_sitemap_enabled
$instance; then
83 sudo
-u "$instance-koha" \
84 rm -f $libdir/$instance/sitemap.enabled
85 [ "$quiet" = "no" ] && \
86 warn
"Sitemap disabled for ${instance}"
88 [ "$quiet" = "no" ] && \
89 warn
"Sitemap already disabled for ${instance}"
96 local sitemapdir
="/var/lib/koha/$instance/sitemap"
98 if ! is_sitemap_enabled
$instance; then
99 [ "$quiet" = "no" ] && \
100 warn
"Sitemap not enabled for ${instance}."
102 if [ ! -d "$sitemapdir" ]; then
103 # Need to create directory
104 [ "$quiet" = "no" ] && \
105 warn
"Sitemap directory for ${instance} doesn't exist. Creating."
106 sudo
-u "$instance-koha" \
107 mkdir
-p "$sitemapdir"
110 if sudo
-u "$instance-koha" -H \
111 env PERL5LIB
=$PERL5LIB \
112 KOHA_CONF
="/etc/koha/sites/$instance/koha-conf.xml" \
113 $KOHA_BINDIR/cronjobs
/sitemap.pl \
114 --dir $sitemapdir ; then
124 local apache_version_ok
="no"
126 if /usr
/sbin
/apache2ctl
-v |
grep -q -v "Server version: Apache/2.4"; then
127 [ "$quiet" = "no" ] && \
129 WARNING: the shipped Apache configuration requires version 2.4.x and you don't have that.
130 Sitemap files will be generated, but refer to the docs to make them publicly available.
137 if [ "$op" = "" ]; then
140 die
"Error: only one action can be specified."
147 # Read command line parameters
148 while [ $# -gt 0 ]; do
163 set_action
"generate"
166 die
"Error: invalid option switch ($1)" ;;
168 # We expect the remaining stuff are the instance names
174 # Optionally use alternative paths for a dev install
175 adjust_paths_dev_install
$1
176 if [ "$DEV_INSTALL" = "" ]; then
177 KOHA_BINDIR
=$KOHA_HOME/bin
179 KOHA_BINDIR
=$KOHA_HOME/misc
182 if [ $# -gt 0 ]; then
183 # We have at least one instance name
186 if is_instance
$name; then
190 generate_sitemap
$name
196 disable_sitemap
$name
204 if [ "$quiet" = "no" ]; then
205 warn
"Error: Invalid instance name $name"
211 if [ "$quiet" = "no" ]; then
212 warn
"Error: you must provide at least one instance name"