From 42b948485af2f8622bcbd8151ed51fe4c686305a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 25 May 2010 13:44:10 +1200 Subject: [PATCH] Add koha-create, a script to create a new Koha instance. Signed-off-by: Galen Charlton --- debian/scripts/koha-create | 175 +++++++++++++++++++++++++++++++++++ debian/scripts/koha-create.8 | 128 +++++++++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100755 debian/scripts/koha-create create mode 100644 debian/scripts/koha-create.8 diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create new file mode 100755 index 0000000000..466f055819 --- /dev/null +++ b/debian/scripts/koha-create @@ -0,0 +1,175 @@ +#!/bin/sh +# +# koha-create -- Create a new Koha instance. +# Copyright 2010 Catalyst IT, Ltd +# +# 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 . + + +set -e + + +die() { + echo "$@" 1>&2 + exit 1 +} + + +generate_config_file() { + touch "$2" + chown "root:$username" "$2" + chmod 0640 "$2" + sed -e "s/__KOHASITE__/$name/g" \ + -e "s/__OPACPORT__/80/g" \ + -e "s/__INTRAPORT__/$INTRAPORT/g" \ + -e "s/__OPACSERVER__/$domain/g" \ + -e "s/__INTRASERVER__/$intradomain/g" \ + -e "s/__ZEBRA_PASS__/$zebrapwd/g" \ + -e "s/__DB_NAME__/$mysqldb/g" \ + -e "s/__DB_USER__/$mysqluser/g" \ + -e "s/__DB_PASS__/$mysqlpwd/g" \ + -e "s/__UNIXUSER__/$username/g" \ + -e "s/__UNIXGROUP__/$username/g" \ + "/etc/koha/$1" > "$2" +} + + +# Set defaults and read config file, if it exists. +DOMAIN="" +INTRAPORT="8080" +INTRAPREFIX="" +INTRASUFFIX="" +DEFAULTSQL="" +if [ -e /etc/koha/koha-sites.conf ] +then + . /etc/koha/koha-sites.conf +fi + + +# Parse command line. +[ "$#" = 1 ] || die "Usage: $0 instancename" +name="$1" +domain="$name$DOMAIN" +if [ "$INTRAPORT" = 80 ] || [ "$INTRAPORT" = "" ] +then + intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN" +else + intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN:$INTRAPORT" +fi + + +# Create new user and group. +username="$name-koha" +if getent passwd "$username" > /dev/null +then + die "User $username already exists." +fi +if getent group "$username" > /dev/null +then + die "Group $username already exists." +fi +adduser --no-create-home --disabled-login --gecos "Koha instance $username" \ + --quiet "$username" + + +# Create the site-specific directories. +mkdir "/etc/koha/sites/$name" + +mkdir "/var/lock/koha/$name" +mkdir "/var/lock/koha/$name/authorities" +mkdir "/var/lock/koha/$name/biblios" +chown -R "root:$username" "/var/lock/koha/$name" +chmod -R g+w "/var/lock/koha/$name" +[ -d "/var/spool/koha/$name" ] || mkdir "/var/spool/koha/$name" + +install -d -o "$username" -g "$username" "/var/lib/koha/$name" +install -d -o "$username" -g "$username" "/var/lib/koha/$name/authorities" +install -d -o "$username" -g "$username" "/var/lib/koha/$name/biblios" +install -d -o "$username" -g "$username" "/var/lib/koha/$name/biblios/key" +install -d -o "$username" -g "$username" "/var/lib/koha/$name/biblios/register" +install -d -o "$username" -g "$username" "/var/lib/koha/$name/biblios/shadow" + +install -d "/var/run/koha/$name/authorities" +install -d "/var/run/koha/$name/biblios" + + +# Generate Zebra database password. +zebrapwd="$(pwgen -1)" + + +# Set up MySQL database for this instance. +mysqldb="koha_$name" +mysqluser="koha_$name" +mysqlpwd="$(pwgen -1)" +mysql --defaults-extra-file=/etc/mysql/debian.cnf <) { print md5_base64($_), "\n"; }') + mysql --defaults-extra-file=/etc/mysql/debian.cnf <. +.TH KOHA-CREATE 8 2010-05-03 Koha +.SH NAME +koha-create \- create a new Koha instance +.SH SYNOPSIS +.B koha-create +.IR instance-name +.SH DESCRIPTION +.B koha-create +creates a new Koha instance. +It is meant for a site that provides Koha hosting, +and serves several sites from the same host. +.PP +The name of the instance is used as the domain name for Apache, +and Unix user and group names, and MySQL username and table names +are derived from it. +Unix user and group are named +.IR instance -koha. +MySQL username is +.RI koha_ instance , +and table is +.RI koha_ instance . +.PP +The Unix user has logins disabled. +The password for MySQL is generated randomly, and printed to the terminal. +.PP +The instance name is used as the domain name (ServerName) for Apache. +The open catalog (OPAC), for library customers, is on port 80. +The librarian intranet interface is on port 8080. +.PP +After the Koha instance is created, it is ready to be used, +but the librarian needs to log in via the intranet and configure things. +.PP +Several configuration variables are available for adjusting this behavior. +The variables are put into +.B /etc/koha/koha-site.conf . +The following variables are obeyed: +.PP +.TP +.B DOMAIN +The domain to append to the instance name, for Apache ServerName. +Default is empty. +The value must begin with a period. +.TP +.B INTRAPORT +The port for the intranet. +If you set this to empty or 80, then you +.I must +also define +.B INTRAPREFIX +or +.BR INTRASUFFIX . +.TP +.B INTRAPREFIX +This is inserted before the instance name when forming Apache ServerName. +For subdomains, make sure it ends with a period. +.TP +.B INTRASUFFIX +This is inserted after the instance name, +but before the domain name, +when forming Apache ServerName. +.TP +.B DEFAULTSQL +An SQL file (possibly compressed with gzip) that can be fed to +.BR mysql (1) +to initialize the database after it has been created. +Might be created using +.BR koha-dump-defaults (8). +.SH FILES +.TP +.B /etc/koha/koha-site.conf +Configuration variables are read from this file, if it exists. +.SH BUGS +The program is a bit fragile. +If something goes wrong, it does not clean up after itself. +.SH EXAMPLE +To create a new Koha instance: +.PP +.RS +koha-create hslibrary +.RE +.PP +The public catalog is now at +.I http://hslibrary/ +and the librarian interface at +.IR http://hslibrary:8080/ . +.PP +To use full domain names, and have the intranet interface on port 80, but +on a different domain name, add the following variables to the +configuration file: +.PP +.nf +.RS +DOMAIN=".example.com" +INTRAPORT="" +INTRASUFFIX="-intra" +.RE +.fi +.PP +This will result in the addresses for the public and intranet interfaces +becoming these: +.PP +.nf +.RS +http://hslibrary.example.com/ +http://hslibrary-intra.example.com/ +.RE +.fi +.PP +Configuration changes only apply to instances created afterwards. +.SH "SEE ALSO" +.BR koha-remove (8). +.PP +.B http://koha-community.org/ + -- 2.39.2