X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=debian%2Fscripts%2Fkoha-create;h=b90e7d4e236ae54870ed1fe7c599a9a1f334cc6d;hb=7b1e8c59fe0edc2faab878c6bd9d45de9f720e81;hp=bb2b642082749d79ca2cd495d3ae91653b241cbc;hpb=1ee7f449be2ba45c2458d2ac571172ecf58752b2;p=koha-ffzg.git diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create index bb2b642082..b90e7d4e23 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # koha-create -- Create a new Koha instance. # Copyright 2010 Catalyst IT, Ltd @@ -16,19 +16,71 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Read configuration variable file if it is present +[ -r /etc/default/koha-common ] && . /etc/default/koha-common set -e -usage="Usage: $0 [--create-db|--request-db|--populate-db|--use-db] \ - [--marcflavor marc21|normarc|unimarc] \ - [--zebralang en|nb|fr] \ - [--defaultsql /path/to/some.sql] \ - [--configfile /path/to/config] [--passwdfile /path/to/passwd] \ - [--database database] [--adminuser n] instancename" - -die() { - echo "$@" 1>&2 +# 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 + +usage() +{ + local scriptname=$0 + cat </templates + --timezone time/zone Specify a timezone. e.g. America/Argentina + --upload-path dir Set a user defined upload_path. It defaults to + /var/lib/koha//uploads + --tmp-path dir Set a user defined tmp_path. It defaults to + /var/lib/koha//tmp + --letsencrypt Set up a https-only site with letsencrypt certificates + --help,-h Show this help. + +Note: the instance name cannot be longer that 11 chars. + +EOF } # UPPER CASE VARIABLES - from configfile or default value @@ -37,7 +89,8 @@ generate_config_file() { touch "$2" chown "root:$username" "$2" chmod 0640 "$2" - sed -e "s/__KOHASITE__/$name/g" \ + sed -e "s/__KOHA_CONF_DIR__/\/etc\/koha\/sites\/$name/g" \ + -e "s/__KOHASITE__/$name/g" \ -e "s/__OPACPORT__/$OPACPORT/g" \ -e "s/__INTRAPORT__/$INTRAPORT/g" \ -e "s/__OPACSERVER__/$opacdomain/g" \ @@ -45,20 +98,40 @@ generate_config_file() { -e "s/__ZEBRA_PASS__/$zebrapwd/g" \ -e "s/__ZEBRA_MARC_FORMAT__/$ZEBRA_MARC_FORMAT/g" \ -e "s/__ZEBRA_LANGUAGE__/$ZEBRA_LANGUAGE/g" \ + -e "s/__SRU_BIBLIOS_PORT__/$SRU_SERVER_PORT/g" \ + -e "s/__START_SRU_PUBLICSERVER__/$START_SRU_PUBLICSERVER/g" \ + -e "s/__END_SRU_PUBLICSERVER__/$END_SRU_PUBLICSERVER/g" \ + -e "s/__API_SECRET__/$API_SECRET/g" \ -e "s/__DB_NAME__/$mysqldb/g" \ -e "s/__DB_HOST__/$mysqlhost/g" \ -e "s/__DB_USER__/$mysqluser/g" \ -e "s/__DB_PASS__/$mysqlpwd/g" \ + -e "s/__ELASTICSEARCH_SERVER__/${ELASTICSEARCH_SERVER}/g" \ -e "s/__UNIXUSER__/$username/g" \ -e "s/__UNIXGROUP__/$username/g" \ + -e "s#__TEMPLATE_CACHE_DIR__#$TEMPLATE_CACHE_DIR#g" \ + -e "s#__TIMEZONE__#$TIMEZONE#g" \ + -e "s#__UPLOAD_PATH__#$UPLOAD_PATH#g" \ + -e "s#__TMP_PATH__#$TMP_PATH#g" \ + -e "s/__LOG_DIR__/\/var\/log\/koha\/$name/g" \ + -e "s/__PLUGINS_DIR__/\/var\/lib\/koha\/$name\/plugins/g" \ + -e "s/__MEMCACHED_NAMESPACE__/$MEMCACHED_NAMESPACE/g" \ + -e "s/__MEMCACHED_SERVERS__/$MEMCACHED_SERVERS/g" \ "/etc/koha/$1" > "$2" + } getmysqlhost() { + if [ ! -f /etc/mysql/debian.cnf ] + then + echo localhost + return + fi awk ' - /^\[/ { inclient = 0 } - /^\[client\]/ { inclient = 1 } - inclient && /^ *host *=/ { print $3 }' \ + BEGIN { FS="=" } + $1 ~/\[/ { inclient=0 } + $1 ~/\[client\]/ { inclient=1; next } + inclient==1 && $1 ~/host/ { gsub(/ /, "", $2); print $2 }' \ /etc/mysql/koha-common.cnf } @@ -74,6 +147,185 @@ getinstancemysqldatabase() { xmlstarlet sel -t -v 'yazgfs/config/database' "/etc/koha/sites/$1/koha-conf.xml" } +check_apache_config() +{ + + # Check that mpm_itk is installed and enabled + if ! /usr/sbin/apachectl -M | grep -q 'mpm_itk'; then + # Check Apache version + APACHE_DISABLE_MPM_MSG="" + if /usr/sbin/apache2ctl -v | grep -q "Server version: Apache/2.4"; then + # mpm_event or mpm_worker need to be disabled first. mpm_itk depends + # on mpm_prefork, which is enabled if needed. See + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=734865 + if /usr/sbin/apachectl -M | grep -q 'mpm_event'; then + APACHE_DISABLE_MPM_MSG=" sudo a2dismod mpm_event ;" + elif /usr/sbin/apachectl -M | grep -q 'mpm_worker'; then + APACHE_DISABLE_MPM_MSG=" sudo a2dismod mpm_worker ;" + # else mpm_prefork: a2enmod mpm_itk works + fi + # else Apache 2.2: a2enmod mpm_itk works + fi + + cat 1>&2 <&2 <&2 << EOM +Koha requires mod_cgi to be enabled within Apache in order to run. +Typically this can be enabled with: + + sudo a2enmod cgi +EOM + die + fi + + # Check that mod_ssl is installed and enabled. + if [ "$CLO_LETSENCRYPT" = "yes" ]; then + if ! /usr/sbin/apachectl -M | grep -q 'ssl_module'; then + cat 1>&2 </dev/null | grep -c "ok installed") -eq 0 ]; then + set +e + apt-cache show letsencrypt &>/dev/null + local aptcacheshow=$? + set -e + if [ $aptcacheshow -eq 0 ]; then + read -r -p "The letsencrypt package is not installed. Do it now? [y/N] " response + if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then + local debrelease="$(lsb_release -c -s)" + if [ $debrelease = "jessie" ]; then + apt-get install -y -t jessie-backports letsencrypt + else + apt-get install -y letsencrypt + fi + else + die "You have to install letsencrypt to use the --letsencrypt parameter." + fi + else + echo "No installation candidate available for package letsencrypt." + if [[ -f /usr/bin/letsencrypt ]]; then + read -r -p "If you have a symlink from /usr/bin/letsencrypt to letsencrypt-auto, it should work. [y/N] " response + if [[ ! $response =~ ^([yY][eE][sS]|[yY])$ ]]; then + die "You have to install letsencrypt to use the --letsencrypt parameter." + fi + else + die "You can create a symlink from /usr/bin/letsencrypt to letsencrypt-auto." + fi + fi + fi +} + +letsencrypt_instance() +{ + # Get letsencrypt certificates + letsencrypt --agree-tos --renew-by-default --webroot certonly \ + -w /usr/share/koha/opac/htdocs/ -d $opacdomain -w /usr/share/koha/intranet/htdocs/ -d $intradomain + # enable all ssl settings (apache won't start with these before certs are present) + sed -i "s:^\s*#\(\s*SSL.*\)$:\1:" "/etc/apache2/sites-available/$name.conf" + # change port from 80 to 443. (apache won't start if it is 443 without certs present) + sed -i "s:^\s*\( #https$:\1443>:" "/etc/apache2/sites-available/$name.conf" + # enable redirect from http to https on port 80 + sed -i "s:^\s*#\(.*\)#nohttps$:\1:" "/etc/apache2/sites-available/$name.conf" + # make koha-list --letsencrypt aware of this instance # could be done by checking apache conf instead + echo -e "opacdomain=\"$opacdomain\"\nintradomain=\"$intradomain\"" > /var/lib/koha/$name/letsencrypt.enabled + # restart apache with working certs + service apache2 restart +} + # Set defaults and read config file, if it exists. DOMAIN="" OPACPORT="80" @@ -87,14 +339,47 @@ ZEBRA_MARC_FORMAT="marc21" ZEBRA_LANGUAGE="en" ADMINUSER="1" PASSWDFILE="/etc/koha/passwd" + +# memcached variables +USE_MEMCACHED="yes" +MEMCACHED_SERVERS="" +MEMCACHED_PREFIX="" +# elasticsearch config +ELASTICSEARCH_SERVER="localhost:9200" +# hardcoded memcached defaults +DEFAULT_MEMCACHED_SERVERS="127.0.0.1:11211" +DEFAULT_MEMCACHED_PREFIX="koha_" +# hardcoded instance base path +INSTANCE_PATH_BASE="/var/lib/koha" +UPLOAD_DIR="uploads" +UPLOAD_PATH="" +# timezone defaults to empty +TIMEZONE="" +# hardcoded upload_tmp_path +TMP_DIR="tmp" +TMP_PATH="" +# cache base dir +CACHE_DIR_BASE="/var/cache/koha" +# Generate a randomizaed API secret +API_SECRET="$(pwgen -s 64 1)" +# SRU server variables +ENABLE_SRU="no" +SRU_SERVER_PORT="" +# hardcoded default SRU server port +DEFAULT_SRU_SERVER_PORT="7090" +START_SRU_PUBLICSERVER="" + +APACHE_CONFIGFILE="" + if [ -e /etc/koha/koha-sites.conf ] then . /etc/koha/koha-sites.conf fi -[ $# -ge 2 ] && [ $# -le 16 ] || die $usage +[ $# -ge 1 ] && [ $# -le 16 ] || ( usage ; die "Error: wrong parameters" ) -TEMP=`getopt -o crpm:l:d:f:a: -l create-db,request-db,populate-db,use-db,marcflavor:,zebralang:,defaultsql:,configfile:,passwdfile:,adminuser: \ +TEMP=`getopt -o chrpm:l:d:f:b:a: -l create-db,request-db,populate-db,use-db,enable-sru,sru-port:,help,marcflavor:,auth-idx:,biblio-idx:,zebralang:,defaultsql:,configfile:,passwdfile:,dbhost:,database:,elasticsearch-server:,adminuser:,memcached-servers:,memcached-prefix:,template-cache-dir:,timezone:,upload-path:,tmp-path:,letsencrypt, \ -n "$0" -- "$@"` # Note the quotes around `$TEMP': they are essential! @@ -105,23 +390,68 @@ CLO_ZEBRA_MARC_FORMAT="" CLO_ZEBRA_LANGUAGE="" CLO_DEFAULTSQL="" CLO_ADMINUSER="" +CLO_MEMCACHED_SERVERS="" +CLO_MEMCACHED_PREFIX="" +CLO_ELASTICSEARCH_SERVER="" +CLO_UPLOAD_PATH="" +CLO_TMP_PATH="" +CLO_LETSENCRYPT="" +CLO_TEMPLATE_CACHE_DIR="" +CLO_TIMEZONE="" while true ; do - case "$1" in - -c|--create-db) op=create ; shift ;; - -r|--request-db) op=request ; shift ;; - -p|--populate-db) op=populate ; shift ;; - -u|--use-db) op=use ; shift ;; - -m|--marcflavor) CLO_ZEBRA_MARC_FORMAT="$2" ; shift 2 ;; - -l|--zebralang) CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;; - -d|--defaultsql) CLO_DEFAULTSQL="$2" ; shift 2 ;; - -f|--configfile) configfile="$2" ; shift 2 ;; - -s|--passwdfile) CLO_PASSWDFILE="$2" ; shift 2 ;; - -b|--database) CLO_DATABASE="$2" ; shift 2 ;; - -a|--adminuser) CLO_ADMINUSER="$2" ; shift 2 ;; - --) shift ; break ;; - *) die "Internal error processing command line arguments" ;; - esac + case "$1" in + -c|--create-db) + op=create ; shift ;; + -r|--request-db) + op=request ; shift ;; + -p|--populate-db) + op=populate ; shift ;; + -u|--use-db) + op=use ; shift ;; + --memcached-servers) + CLO_MEMCACHED_SERVERS="$2" ; shift 2 ;; + --memcached-prefix) + CLO_MEMCACHED_PREFIX="$2" ; shift 2;; + --elasticsearch-server) + CLO_ELASTICSEARCH_SERVER="$2" ; shift 2 ;; + -m|--marcflavor) + CLO_ZEBRA_MARC_FORMAT="$2" ; shift 2 ;; + -l|--zebralang) + CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;; + -d|--defaultsql) + CLO_DEFAULTSQL="$2" ; shift 2 ;; + -f|--configfile) + configfile="$2" ; shift 2 ;; + -s|--passwdfile) + CLO_PASSWDFILE="$2" ; shift 2 ;; + -b|--database) + CLO_DATABASE="$2" ; shift 2 ;; + --dbhost) + CLO_DBHOST="$2" ; shift 2 ;; + -a|--adminuser) + CLO_ADMINUSER="$2" ; shift 2 ;; + --enable-sru) + ENABLE_SRU="yes" ; shift ;; + --sru-port) + SRU_SERVER_PORT="$2" ; shift 2 ;; + --template-cache-dir) + CLO_TEMPLATE_CACHE_DIR="$2" ; shift 2 ;; + --timezone) + CLO_TIMEZONE="$2" ; shift 2 ;; + --upload-path) + CLO_UPLOAD_PATH="$2" ; shift 2 ;; + --tmp-path) + CLO_TMP_PATH="$2" ; shift 2 ;; + --letsencrypt) + CLO_LETSENCRYPT="yes" ; shift ;; + -h|--help) + usage ; exit 0 ;; + --) + shift ; break ;; + *) + die "Internal error processing command line arguments" ;; + esac done # Load the configfile given on the command line @@ -157,18 +487,78 @@ then PASSWDFILE="$CLO_PASSWDFILE" fi +if [ "$CLO_TIMEZONE" != "" ]; then + TIMEZONE=$CLO_TIMEZONE +fi + +if [ "${CLO_ELASTICSEARCH_SERVER}" != "" ]; then + ELASTICSEARCH_SERVER="${CLO_ELASTICSEARCH_SERVER}" +fi + +if [ "$ENABLE_SRU" != "no" ]; then + enable_sru_server +fi + +[ $# -ge 1 ] || ( usage ; die "Missing instance name..." ) + name="$1" +set_upload_path $name +set_tmp_path $name + +if [ "$op" = use ] && [ "$CLO_DATABASE" = "" ] && + ( [ ! -f "$PASSWDFILE" ] || [ ! `cat $PASSWDFILE | grep "^$name:"` ] ) +then + cat < /dev/null 2>&1 || + a2ensite "${name}.conf" > /dev/null 2>&1 + }; then + echo "Warning: problem enabling $name in Apache" >&2 + fi service apache2 restart # Start Zebra. - koha-start-zebra "$name" + koha-zebra --start "$name" + + if [ "$USE_INDEXER_DAEMON" = "yes" ]; then + # Start Indexer daemon + koha-indexer --start "$name" + fi + + if [ "$CLO_LETSENCRYPT" = "yes" ]; then + # Get letsencrypt certificates + letsencrypt_instance + fi + + chown $username:$username /var/log/koha/$name/*.log fi