Koha Install

by samuelelliot
14 deployments · 1 still active · last rev. 2 years ago

Install Koha OPAC (Online Public Access Catalog)
http://koha-community.org/

Compatible with: No distros currently supported
						#!/usr/bin/env bash
#
# Koha Install
#
# Install Koha OPAC (Online Public Access Catalog)
# http://koha-community.org/
#
# <UDF name="stackscriptslog"           label="Log StackScripts Activity"   oneOf="Yes,No"  example="Log output & any errors to roots home. Output is still sent to STDOUT and may be watched from LISH" />
# <UDF name="sys_hostname"              label="Hostname"                                    example="library.example.com" />
# <UDF name="sys_timezone"              label="Timezone"                                    example="America/Los_Angeles, US/Central, EST, etc." />
#
# <UDF name="db_password"               label="MySQL root Password" />
#
# <UDF name="koha_version"              label="Koha Version"                oneOf="Current Stable,Old Stable,Development" />
# <UDF name="koha_domain"               label="Base Domain"                                 example=".example.com" />
# <UDF name="koha_instance"             label="Instance Sub-Domain"                         example="library" />
# <UDF name="koha_intra_port"           label="Admin Interface Port"                        example="80" />
# <UDF name="koha_intra_prefix"         label="Admin Sub-Domain Prefix"     default=""      example="intra-" />
# <UDF name="koha_intra_suffix"         label="Admin Sub-Domain Suffix"     default=""      example="-intra" />
# <UDF name="koha_default_sql"          label="Default SQL"                 default="" />
# <UDF name="koha_opac_port"            label="OPAC Port"                                   example="80" />
# <UDF name="koha_opac_prefix"          label="OPAC Sub-Domain Prefix"      default="" />
# <UDF name="koha_opac_suffix"          label="OPAC Sub-Domain Suffix"      default="" />
# <UDF name="koha_zebra_marc_format"    label="Zebra Marc Format"           oneOf="marc21,normarc,unimarc" />
# <UDF name="koha_zebra_language"       label="Zebra Language"              oneOf="en,fr,nb" />
#
# <UDF name="koha_install_email"        label="Install Notice Email"        default=""      example="user@example.com; test@example.com" />

source <ssinclude StackScriptID="1">
source <ssinclude StackScriptID="3687">


####################
## KOHA FUNCTIONS ##
####################

koha_site_config_add() {
    # Add configuration to Koha site config
    # $1 = the directive
    # $2 = [optional] the value

    if [ ! -n "$1" ]; then
        echo "koha_site_config_add() requires a directive & an optional value argument"
        return 1;
    fi

    if [ ! -n "$2" ]; then
        VALUE=""
    else
        VALUE="$2"
    fi

    echo "$1=\"$VALUE\"" >> "/etc/koha/koha-sites.conf"
}


######################
## APACHE FUNCTIONS ##
######################

apache_port_add() {
    # Add Port to Apache ports.conf
    # $1 = Port to add

    if [ ! "$(grep "NameVirtualHost \*:$1" /etc/apache2/ports.conf)" ]; then
        echo "NameVirtualHost *:$1" >> /etc/apache2/ports.conf
    fi

    if [ ! "$(grep "Listen $1" /etc/apache2/ports.conf)" ]; then
        echo "Listen $1" >> /etc/apache2/ports.conf
    fi
}


######################
## STACKSCRIPT FLOW ##
######################

if [ "$STACKSCRIPTSLOG" == "Yes" ]; then
	echo
	echo "Initializing error logging"
	echo

    # Defined in StackScriptID 3687
    stackscript_log
fi


echo
echo "Upgrading system repositories & packages "
echo

# Defined in StackScriptID 3687
apt_upgrade_full


echo
echo "Setting system hostname & timezone"
echo

# Defined in StackScriptID 3687
set_hostname "$SYS_HOSTNAME"
set_timezone "$SYS_TIMEZONE"


echo
echo "Adding Koha repository source & key"
echo

# Select Koha version
if [ "$KOHA_VERSION" == "Current Stable" ]; then
    KOHA_VERSION="squeeze"
elif [ "$KOHA_VERSION" == "Old Stable" ]; then
    KOHA_VERSION="oldstable"
elif [ "$KOHA_VERSION" == "Development" ]; then
    KOHA_VERSION="squeeze-dev"
fi

# Defined in StackScriptID 3687
apt_sources_add "binary" "http://debian.koha-community.org/koha" "$KOHA_VERSION" "main" "koha"
apt_sources_key_add "http://debian.koha-community.org/koha/gpg.asc"


echo
echo "Updating system repositories"
echo

# Defined in StackScriptID 3687
apt_update


echo
echo "Installing Apache"
echo

# Defined in StackScriptID 1
apache_install


echo
echo "Tunning Apache"
echo

# Defined in StackScriptID 1
apache_tune 40


echo
echo "Enabling required Apache modules"
echo

a2enmod rewrite
a2enmod deflate


echo
echo "Restarting Apache"
echo

service apache2 restart


echo
echo "Verifying Apache is listening to required ports"
echo

apache_port_add "$KOHA_OPAC_PORT"
apache_port_add "$KOHA_INTRA_PORT"


echo
echo "Installing and configuring Postfix"
echo

# Defined in StackScriptID 1
postfix_install_loopback_only


echo
echo "Installing MySQL"
echo

# Defined in StackScriptID 1
mysql_install "$DB_PASSWORD"


echo
echo "Tunning MySQL"
echo

# Defined in StackScriptID 1
mysql_tune 40


echo
echo "Installing Koha"
echo

# Defined in StackScriptID 3687
apt_install "koha-common"


echo
echo "Configuring Koha"
echo

koha_site_config_add "DOMAIN"            "$KOHA_DOMAIN"
koha_site_config_add "INTRAPORT"         "$KOHA_INTRA_PORT"
koha_site_config_add "INTRAPREFIX"       "$KOHA_INTRA_PREFIX"
koha_site_config_add "INTRASUFFIX"       "$KOHA_INTRA_SUFFIX"
koha_site_config_add "DEFAULTSQL"        "$KOHA_DEFAULT_SQL"
koha_site_config_add "OPACPORT"          "$KOHA_OPAC_PORT"
koha_site_config_add "OPACPREFIX"        "$KOHA_OPAC_PREFIX"
koha_site_config_add "OPACSUFFIX"        "$KOHA_OPAC_SUFFIX"
koha_site_config_add "ZEBRA_MARC_FORMAT" "$KOHA_ZEBRA_MARC_FORMAT"
koha_site_config_add "ZEBRA_LANGUAGE"    "$KOHA_ZEBRA_LANGUAGE"

echo
echo "Creating Koha database instance"
echo

koha-create --create-db "$KOHA_INSTANCE"

echo
echo "Remove anonymous user from MySQL"
echo

echo "DELETE FROM mysql.user WHERE user=''; FLUSH PRIVILEGES;" | mysql -u root -p"$DB_PASSWORD"


echo
echo "Disableing default Apache vHost and enableing Koha vHost"
echo

a2dissite "000-default"
a2ensite "$KOHA_INSTANCE"


echo
echo "Restarting Apache"
echo

service apache2 restart


echo "You can access the new installation with the following information:

.-=*=-.-=*=-.-=*=-.-=*=-.-=*=-.-=*=-.-=*=-.-=*=-.

Login to Koha Admin

OPAC URL:  $KOHA_OPAC_PREFIX$KOHA_INSTANCE$KOHA_OPAC_SUFFIX$KOHA_DOMAIN:$KOHA_OPAC_PORT
Admin URL: $KOHA_INTRA_PREFIX$KOHA_INSTANCE$KOHA_INTRA_SUFFIX$KOHA_DOMAIN:$KOHA_INTRA_PORT
User:      koha_$KOHA_INSTANCE
Password:  $(xmlstarlet sel -t -v "yazgfs/config/pass" /etc/koha/sites/library/koha-conf.xml)

.-=*=-.-=*=-.-=*=-.-=*=-.-=*=-.-=*=-.-=*=-.-=*=-." > "/root/koha_install.txt"

if [ -n "$KOHA_INSTALL_EMAIL" ]; then
    EMAIL_FROM="Koha Install <no-reply@$KOHA_INTRA_PREFIX$KOHA_INSTANCE$KOHA_INTRA_SUFFIX$KOHA_DOMAIN>"
    EMAIL_SUBJECT="Koha has been installed"
    EMAIL_MESSAGE="$(cat "/root/koha_install.txt")"

    send_email "$EMAIL_FROM" "$KOHA_INSTALL_EMAIL" "$EMAIL_SUBJECT" "$EMAIL_MESSAGE"

    echo "Installation email (as follows) has been sent"
    echo "To:      $KOHA_INSTALL_EMAIL"
    echo "From:    $EMAIL_FROM"
    echo "Subject: $EMAIL_SUBJECT"
    echo "Message:"
    echo "$EMAIL_MESSAGE"
else
    cat "/root/koha_install.txt"
fi