[Koha-patches] [PATCH 3/3] Bug 12805 [ENH] Adding enable/disable scripts for Koha plugins and extending koha-list to accomodate --plugins and --noplugins listing
Indranil Das Gupta
indradg at gmail.com
Fri Aug 22 23:27:27 CEST 2014
Command-line koha-* script to toggle <enable_plugins> definition in
site specific koha-conf.xml; also to add plugins listing to existing
koha-list command. These files are expected to be used for a .deb
package based installation of Koha
Test plan:
1) Have a koha-common setup installed
2) Apply the patch and build a package for it.
3) Install it.
4) Verify that /yazgfz/config/enable_plugins is being toggled correctly
when koha-enable-plugins and koha-disable-plugins are being called
respectively.
-idg
---
debian/scripts/koha-disable-plugins | 77 +++++++++++++++++++++++++++++++++++++
debian/scripts/koha-enable-plugins | 77 +++++++++++++++++++++++++++++++++++++
debian/scripts/koha-functions.sh | 21 ++++++++++
debian/scripts/koha-list | 49 ++++++++++++++++++++---
4 files changed, 218 insertions(+), 6 deletions(-)
create mode 100755 debian/scripts/koha-disable-plugins
create mode 100755 debian/scripts/koha-enable-plugins
diff --git a/debian/scripts/koha-disable-plugins b/debian/scripts/koha-disable-plugins
new file mode 100755
index 0000000..5251d5b
--- /dev/null
+++ b/debian/scripts/koha-disable-plugins
@@ -0,0 +1,77 @@
+#!/bin/sh
+#
+# koha-disable-plugins -- Disable Koha's KPZ plugin system
+# Copyright (c) 2014 : Indranil Das Gupta / L2C2 Technologies
+#
+# 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/>.
+
+set -e
+
+# include helper functions
+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
+ . "/usr/share/koha/bin/koha-functions.sh"
+else
+ echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
+ exit 1
+fi
+
+disable_plugins()
+{
+ local instancename=$1
+ local kohaconf="/etc/koha/sites/${instancename}/koha-conf.xml"
+
+ local tmpfile=/tmp/${instancename}_koha-conf.xml
+
+ xmlstarlet ed -u '/yazgfs/config/enable_plugins' \
+ -v 0 /etc/koha/sites/${name}/koha-conf.xml > ${tmpfile}
+
+ cp -v ${tmpfile} /etc/koha/sites/${name}/koha-conf.xml
+
+ chmod 640 /etc/koha/sites/${name}/koha-conf.xml
+
+ chgrp ${instancename}-koha /etc/koha/sites/${name}/koha-conf.xml
+
+ rm ${tmpfile}
+
+ echo "Disabled Koha plugins for instance $instancename."
+}
+
+usage()
+{
+ local scriptname=$0
+ cat <<EOF
+Disables Koha plugins system for specified Koha instances.
+
+Usage: $scriptname instancename1 instancename2...
+
+EOF
+}
+
+# Parse command line.
+[ $# -ge 1 ] || ( usage ; die "Missing instance name..." )
+
+for name in "$@"
+do
+ if is_instance ${name}; then
+ if is_pluginsdir_enabled ${name}; then
+ disable_plugins ${name}
+ else
+ warn "Plugins already disabled for instance ${name}"
+ fi
+ else
+ warn "Unknown instance $name."
+ fi
+done
+
+exit 0
diff --git a/debian/scripts/koha-enable-plugins b/debian/scripts/koha-enable-plugins
new file mode 100755
index 0000000..3d6f74e
--- /dev/null
+++ b/debian/scripts/koha-enable-plugins
@@ -0,0 +1,77 @@
+#!/bin/sh
+#
+# koha-enable-plugins -- Enable Koha's KPZ plugin system
+# Copyright (c) 2014 : Indranil Das Gupta / L2C2 Technologies
+#
+# 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/>.
+
+set -e
+
+# include helper functions
+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
+ . "/usr/share/koha/bin/koha-functions.sh"
+else
+ echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
+ exit 1
+fi
+
+enable_plugins()
+{
+ local instancename=$1
+ local kohaconf="/etc/koha/sites/${instancename}/koha-conf.xml"
+
+ local tmpfile=/tmp/${instancename}_koha-conf.xml
+
+ xmlstarlet ed -u '/yazgfs/config/enable_plugins' \
+ -v 1 /etc/koha/sites/${name}/koha-conf.xml > ${tmpfile}
+
+ cp -v ${tmpfile} /etc/koha/sites/${name}/koha-conf.xml
+
+ chmod 640 /etc/koha/sites/${name}/koha-conf.xml
+
+ chgrp ${instancename}-koha /etc/koha/sites/${name}/koha-conf.xml
+
+ rm ${tmpfile}
+
+ echo "Enabled Koha plugins for instance $instancename."
+}
+
+usage()
+{
+ local scriptname=$0
+ cat <<EOF
+Enables Koha plugins system for specified Koha instances.
+
+Usage: $scriptname instancename1 instancename2...
+
+EOF
+}
+
+# Parse command line.
+[ $# -ge 1 ] || ( usage ; die "Missing instance name..." )
+
+for name in "$@"
+do
+ if is_instance ${name}; then
+ if ! is_pluginsdir_enabled ${name}; then
+ enable_plugins ${name}
+ else
+ warn "Plugins already enabled for instance ${name}"
+ fi
+ else
+ warn "Unknown instance $name."
+ fi
+done
+
+exit 0
diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh
index 8090fc5..715606a 100755
--- a/debian/scripts/koha-functions.sh
+++ b/debian/scripts/koha-functions.sh
@@ -17,6 +17,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# 2014-08-22 : Added is_pluginsdir_enabled() - Indranil Das Gupta /
+# L2C2 Technologies
die()
{
@@ -121,6 +123,25 @@ is_indexer_running()
fi
}
+is_pluginsdir_enabled()
+{
+ local instancename=$1
+
+ if [ -e /var/lib/koha/$instancename/plugins ]; then
+ local pluginsenabled=`xmlstarlet sel -t -m \
+ '/yazgfs/config/enable_plugins' \
+ -v . /etc/koha/sites/$instancename/koha-conf.xml`
+
+ if [ $pluginsenabled == "1" ]; then
+ return 0
+ else
+ return 1
+ fi
+ else
+ return 1
+ fi
+}
+
get_instances()
{
find /etc/koha/sites -mindepth 1 -maxdepth 1\
diff --git a/debian/scripts/koha-list b/debian/scripts/koha-list
index 848494b..ce0b072 100755
--- a/debian/scripts/koha-list
+++ b/debian/scripts/koha-list
@@ -32,25 +32,29 @@ show_instances()
local show=$1
local show_email=$2
local show_sip=$3
+ local show_plugins=$4
for instance in $( get_instances ); do
case $show in
"all")
if instance_filter_email $instance $show_email && \
- instance_filter_sip $instance $show_sip; then
+ instance_filter_sip $instance $show_sip && \
+ instance_filter_plugins; then
echo $instance
fi ;;
"enabled")
if is_enabled $instance; then
if instance_filter_email $instance $show_email && \
- instance_filter_sip $instance $show_sip; then
+ instance_filter_sip $instance $show_sip && \
+ instance_filter_plugins; then
echo $instance
fi
fi ;;
"disabled")
if ! is_enabled $instance; then
if instance_filter_email $instance $show_email && \
- instance_filter_sip $instance $show_sip; then
+ instance_filter_sip $instance $show_sip && \
+ instance_filter_plugins; then
echo $instance
fi
fi ;;
@@ -58,7 +62,6 @@ show_instances()
done
}
-
instance_filter_sip()
{
local instancename=$1
@@ -103,6 +106,25 @@ instance_filter_email()
return 1
}
+instance_filter_plugins()
+{
+ local instancename=$1
+ local show_plugins=$2;
+
+ case $show_plugins in
+ "all")
+ return 0 ;;
+ "enabled")
+ if is_pluginsdir_enabled $instancename; then
+ return 0
+ fi ;;
+ "disabled")
+ if ! is_pluginsdir_enabled $instancename; then
+ return 1
+ fi ;;
+ esac
+}
+
set_show()
{
local show_param=$1
@@ -136,6 +158,17 @@ set_show_sip()
fi
}
+set_show_plugins()
+{
+ local plugins_param=$1
+
+ if [ "$show_plugins" = "all" ]; then
+ show_plugins=$plugins_param
+ else
+ die "Error: --plugins and --noplugins are mutually exclusive."
+ fi
+}
+
usage()
{
local scriptname=$0
@@ -152,6 +185,8 @@ Options:
--noemail Only show instances that do not have email enabled
--sip Only show instances that have SIP enabled
--nosip Only show instances that do not have SIP enabled
+ --plugins Only show instances that have Koha plugins enabled
+ --noplugins Only show instances that do not have Koha plugins enabled
--help | -h Show this help
The filtering options can be combined, and you probably want to do this
@@ -163,7 +198,7 @@ show="all"
show_email="all"
show_sip="all"
-args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip -o h -n $0 -- "$@")
+args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip,plugins,noplugins -o h -n $0 -- "$@")
set -- $args
while [ ! -z "$1" ]
@@ -174,6 +209,8 @@ do
--noemail) set_show_email "disabled" ;;
--sip) set_show_sip "enabled" ;;
--nosip) set_show_sip "disabled" ;;
+ --plugins) set_show_plugins "enabled" ;;
+--noplugins) set_show_plugins "disabled" ;;
--enabled) set_show "enabled" ;;
--disabled) set_show "disabled" ;;
*) break;;
@@ -181,6 +218,6 @@ do
shift
done
-show_instances $show $show_email $show_sip
+show_instances $show $show_email $show_sip $show_plugins
exit 0
--
1.8.1.2
More information about the Koha-patches
mailing list