From 7258095decfd92f9a76850137d5915794d92fb05 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Mon, 28 May 2018 16:45:29 +0000 Subject: [PATCH] Bug 20692: Extreme toggle checking for plack TEST PLAN --------- sudo koha-plack --disable sudo koha-plack --disable sudo koha-plack --enable sudo koha-plack --disable echo $? sudo koha-plack --disable echo $? sudo koha-list --noplack echo $? sudo koha-plack --enable echo $? sudo koha-plack --enable echo $? sudo koha-list --plack echo $? git bz apply 20692 sudo perl ~/misc4dev/cp_debian_files.pl then repeat the test. It should also be noted, because the enable and disable are now split, if for some reason they become out of sync, an enable or disable should correct them. Because these are bash scripts, the test tool (/home/vagrant/qa-test-tools/koha-qa.pl) does not apply. Signed-off-by: Liz Rea Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens (cherry picked from commit de20398db303a1ee45b62f9aa51f124597ed0cd8) Signed-off-by: Martin Renvoize (cherry picked from commit 84adcb4017e7be038e5e32c37a6b40e4ab9f59c7) Signed-off-by: Lucas Gass --- debian/scripts/koha-functions.sh | 54 ++++++++++++++++++-- debian/scripts/koha-plack | 84 +++++++++++++++++++++++++++++--- 2 files changed, 126 insertions(+), 12 deletions(-) diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh index c6f79b4933..afcf04d39d 100755 --- a/debian/scripts/koha-functions.sh +++ b/debian/scripts/koha-functions.sh @@ -185,6 +185,40 @@ is_indexer_running() fi } +is_plack_enabled_opac() +{ + local instancefile=$1 + + if [ "$instancefile" = "" ]; then + return 1 + fi + + # remember 0 means success/true in bash. + if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-opac-plack.conf' \ + "$instancefile" ; then + return 0 + else + return 1 + fi +} + +is_plack_enabled_intranet() +{ + local instancefile=$1 + + if [ "$instancefile" = "" ]; then + return 1 + fi + + # remember 0 means success/true in bash. + if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-intranet-plack.conf' \ + "$instancefile" ; then + return 0 + else + return 1 + fi +} + is_plack_enabled() { local site=$1 @@ -194,10 +228,22 @@ is_plack_enabled() 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 + if is_plack_enabled_opac $instancefile ; then + enabledopac=1 + else + enabledopac=0 + fi + if is_plack_enabled_intranet $instancefile ; then + enabledintra=1 + else + enabledintra=0 + fi + + # remember 0 means success/true in bash. + if [ "$enabledopac" != "$enabledintra" ] ; then + echo "$site has a plack configuration error. Enable or disable plack to correct this." + return 0 + elif [ "$enabledopac" = "1" ] ; then return 0 else return 1 diff --git a/debian/scripts/koha-plack b/debian/scripts/koha-plack index 68f899113b..b14bac5f9f 100755 --- a/debian/scripts/koha-plack +++ b/debian/scripts/koha-plack @@ -181,14 +181,48 @@ enable_plack() local instancename=$1 local instancefile=$(get_apache_config_for "$instancename") - if ! is_plack_enabled $instancename; then - # Uncomment the plack related lines for OPAC and intranet + alreadyopac=0 + alreadyintra=0 + failopac=0 + failintra=0 + if ! is_plack_enabled_opac $instancefile; then + # Uncomment the plack related lines for OPAC sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:\1:' "$instancefile" + if ! is_plack_enabled_opac $instancefile; then + [ "${quiet}" != "yes" ] && warn "Plack not enabled for ${instancename} OPAC" + failopac=1 + else + [ "${quiet}" != "yes" ] && warn "Plack enabled for ${instancename} OPAC" + fi + else + [ "${quiet}" != "yes" ] && warn "Plack already enabled for ${instancename} OPAC" + alreadyopac=1 + fi + if ! is_plack_enabled_intranet $instancefile; then + # Uncomment the plack related lines for intranet sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:\1:' "$instancefile" - [ "${quiet}" != "yes" ] && warn "Plack enabled for ${instancename}" + if ! is_plack_enabled_intranet $instancefile; then + [ "${quiet}" != "yes" ] && warn "Plack not enabled for ${instancename} Intranet" + failintra=1 + else + [ "${quiet}" != "yes" ] && warn "Plack enabled for ${instancename} Intranet" + fi + else + [ "${quiet}" != "yes" ] && warn "Plack already enabled for ${instancename} Intranet" + alreadyintra=1 + fi + + # Fail if it was already plack enabled. + if [ $alreadyopac -eq 1 ] && [ $alreadyintra -eq 1 ] ; then + return 1 + elif [ "$alreadyopac" != "$alreadyintra" ]; then + [ "${quiet}" != "yes" ] && warn "$instancename had a plack configuration error. Please confirm it is corrected." + fi + + # Succeed if both or any plack were turned on. + if [ $failopac -eq 0 ] || [ $failintra -eq 0 ] ; then return 0 else - [ "${quiet}" != "yes" ] && warn "Plack already enabled for ${instancename}" return 1 fi } @@ -198,14 +232,48 @@ disable_plack() local instancename=$1 local instancefile=$(get_apache_config_for "$instancename") - if is_plack_enabled $instancename; then - # Comment out the plack related lines for OPAC and intranet + alreadyopac=0 + alreadyintra=0 + failopac=0 + failintra=0 + if is_plack_enabled_opac $instancefile ; then + # Comment the plack related lines for OPAC sed -i 's:^\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:#\1:' "$instancefile" + if is_plack_enabled_opac $instancefile ; then + [ "${quiet}" != "yes" ] && warn "Plack not disabled for ${instancename} OPAC" + failopac=1 + else + [ "${quiet}" != "yes" ] && warn "Plack disabled for ${instancename} OPAC" + fi + else + [ "${quiet}" != "yes" ] && warn "Plack already disabled for ${instancename} OPAC" + alreadyopac=1 + fi + if is_plack_enabled_intranet $instancefile; then + # Comment the plack related lines for intranet sed -i 's:^\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:#\1:' "$instancefile" - [ "${quiet}" != "yes" ] && warn "Plack disabled for ${instancename}" + if is_plack_enabled_intranet $instancefile; then + [ "${quiet}" != "yes" ] && warn "Plack not disabled for ${instancename} Intranet" + failintra=1 + else + [ "${quiet}" != "yes" ] && warn "Plack disabled for ${instancename} Intranet" + fi + else + [ "${quiet}" != "yes" ] && warn "Plack already disabled for ${instancename} Intranet" + alreadyintra=1 + fi + + # Fail if it was already plack disabled. + if [ $alreadyopac -eq 1 ] && [ $alreadyintra -eq 1 ] ; then + return 1 + elif [ "$alreadyopac" != "$alreadyintra" ]; then + [ "${quiet}" != "yes" ] && warn "$instancename had a plack configuration error. Please confirm it is corrected." + fi + + # Succeed if both or any plack were turned off. + if [ $failopac -eq 0 ] || [ $failintra -eq 0 ] ; then return 0 else - [ "${quiet}" != "yes" ] && warn "Plack already disabled for ${instancename}" return 1 fi } -- 2.39.5