Bug 17301 - Add callnumber to label-edit-batch.pl
[koha.git] / debian / scripts / koha-sitemap
blobc42ab345a643ccdfe80f730040f4c7289c2d04aa
1 #!/bin/bash
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/>.
20 set -e
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"
30 else
31 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
32 exit 1
35 usage()
37 local scriptname=$(basename $0)
39 cat <<EOF
40 $scriptname
42 This script lets you manage sitemaps for your Koha instances.
44 Usage:
45 $scriptname --enable|--disable instancename1 [instancename2]
46 $scriptname --generate instancename1 [instancename2]
47 $scriptname -h|--help
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
56 EOF
59 enable_sitemap()
61 local instance=$1
62 local libdir="/var/lib/koha"
64 if is_sitemap_enabled $instance; then
65 [ "$quiet" = "no" ] && \
66 warn "Sitemap already enabled for ${instance}"
67 else
69 sudo -u "$instance-koha" \
70 touch $libdir/$instance/sitemap.enabled
72 [ "$quiet" = "no" ] && \
73 warn "Sitemap enabled for ${instance}"
77 disable_sitemap()
79 local instance=$1
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}"
87 else
88 [ "$quiet" = "no" ] && \
89 warn "Sitemap already disabled for ${instance}"
93 generate_sitemap()
95 local instance=$1
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}."
101 else
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=/usr/share/koha/lib \
112 KOHA_CONF="/etc/koha/sites/$instance/koha-conf.xml" \
113 /usr/share/koha/bin/cronjobs/sitemap.pl \
114 --dir $sitemapdir ; then
115 return 0
116 else
117 return 1
122 check_env_and_warn()
124 local apache_version_ok="no"
126 if /usr/sbin/apache2ctl -v | grep -q -v "Server version: Apache/2.4"; then
127 [ "$quiet" = "no" ] && \
128 cat 1>&2 <<EOM
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.
135 set_action()
137 if [ "$op" = "" ]; then
138 op=$1
139 else
140 die "Error: only one action can be specified."
144 op=""
145 quiet="no"
147 # Read command line parameters
148 while [ $# -gt 0 ]; do
150 case "$1" in
151 -h|--help)
152 usage ; exit 0 ;;
153 -q|--quiet)
154 quiet="yes"
155 shift ;;
156 --enable)
157 set_action "enable"
158 shift ;;
159 --disable)
160 set_action "disable"
161 shift ;;
162 --generate)
163 set_action "generate"
164 shift ;;
166 die "Error: invalid option switch ($1)" ;;
168 # We expect the remaining stuff are the instance names
169 break ;;
170 esac
172 done
174 if [ $# -gt 0 ]; then
175 # We have at least one instance name
176 for name in "$@"; do
178 if is_instance $name; then
180 case $op in
181 "generate")
182 generate_sitemap $name
184 "enable")
185 enable_sitemap $name
187 "disable")
188 disable_sitemap $name
191 usage
193 esac
195 else
196 if [ "$quiet" = "no" ]; then
197 warn "Error: Invalid instance name $name"
201 done
202 else
203 if [ "$quiet" = "no" ]; then
204 warn "Error: you must provide at least one instance name"
208 exit 0