<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<article>
  <title>Updating Koha</title>

  <articleinfo>
    <pubdate>2006-03-17</pubdate>

    <author>
      <firstname>Joshua</firstname>

      <surname>Ferraro</surname>

      <email>jmf at liblime dot com</email>
    </author>

    <author>
      <firstname>Pierrick</firstname>

      <surname>Le Gall</surname>

      <email>pierrick at koha-fr dot org</email>
    </author>

    <copyright>
      <year>2004-2006</year>

      <holder>Joshua Ferraro</holder>
    </copyright>

    <legalnotice>
      <para>This document is related to Koha and is licensed to you under the
      GNU General Public License version 2 or later (<ulink
      url="http://www.gnu.org/licenses/gpl.html">http://www.gnu.org/licenses/gpl.html</ulink>).</para>

      <para>Koha-related documents may be reproduced and distributed in whole
      or in part, in any medium physical or electronic, as long as this
      copyright notice is retained on all copies.</para>

      <para>You may create a derivative work and distribute it provided that
      you:</para>

      <orderedlist>
        <listitem>
          <para>License the derivative work with this same license, or the
          Linux Documentation Project License (<ulink
          url="http://www.tldp.org/COPYRIGHT.html">http://www.tldp.org/COPYRIGHT.html</ulink>).
          Include a copyright notice and at least a pointer to the license
          used.</para>
        </listitem>

        <listitem>
          <para>Give due credit to previous authors and major
          contributors.</para>
        </listitem>
      </orderedlist>

      <para>Commercial redistribution is allowed and encouraged; however, the
      author would like to be notified of any such distributions.</para>

      <para>No liability for the contents of this document can be accepted.
      Use the concepts, examples and information at your own risk. There may
      be errors and inaccuracies, that could be damaging to your system.
      Proceed with caution, and although this is highly unlikely, the
      author(s) do not take any responsibility.</para>

      <para>All copyrights are held by their by their respective owners,
      unless specifically noted otherwise. Use of a term in this document
      should not be regarded as affecting the validity of any trademark or
      service mark. Naming of particular products or brands should not be seen
      as endorsements.</para>
    </legalnotice>

    <revhistory>
      <revision>
        <revnumber>2.2.0</revnumber>

        <date>2004-12-13</date>

        <authorinitials>jmf</authorinitials>

        <revdescription>
          <para>Changes made by Joshua Ferraro. Original Document</para>
        </revdescription>
      </revision>

      <revision>
        <revnumber>2.2.0p1</revnumber>

        <date>2005-01-09</date>

        <authorinitials>jmf</authorinitials>

        <revdescription>
          <para>Minor change to cvs command following official release of
          2.2.0</para>
        </revdescription>
      </revision>

      <revision>
        <revnumber>2.2.5</revnumber>

        <date>2006-03-13</date>

        <authorinitials>plg</authorinitials>

        <revdescription>
          <para>Bug fixes on symlinks. New script to create symlinks, with
          comand-line parameters. Precision on CVS repository : use of CVS
          working directory when talking about the checked out
          directory.</para>
        </revdescription>
      </revision>
    </revhistory>
  </articleinfo>

  <section>
    <title>Introduction</title>

    <para>At the beginning of the project, <application>Koha</application>
    project developers used <systemitem>sourceforge.net</systemitem> as their
    centralized repository for source code; in December 2005 the source code
    was moved to savannah.nongnu.org. Savannah's repositories use
    <firstterm>CVS</firstterm> (Concurrent Versions System), a tool used to
    manage changes within a source code tree.</para>

    <para>Some in the Koha community have expressed interest in migrating
    Revision Management Systems (RMS) from CVS to a more distributed system
    like Arch. If project developers move all <application>Koha</application>
    development to an Arch model a different guide would be necessary, but for
    now, I can describe the basics of how to keep your
    <application>Koha</application> 2.2 system up-to-date using CVS and
    Savannah. At this time, this document does not discuss how to upgrade a
    system from an older version of <application>Koha</application> to a newer
    version.</para>
  </section>

  <section>
    <title>Before You Begin</title>

    <para>In order to access a CVS repository, you must first install a CVS
    client (if one is not already installed on your system). General
    information about CVS client software (and it's use with
    <systemitem>sourceforge.net</systemitem>) can be found in the following
    SourceForge.net document: <ulink
    url="http://sourceforge.net/docman/display_doc.php?docid=14033&amp;group_id=1">Basic
    Introduction to CVS and SourceForge.net (SF.net) Project CVS
    Services</ulink>. Information more specific to Savannah can be found in
    the Savannah <ulink url="http://savannah.nongnu.org/faq/">Frequently Asked
    Questions</ulink>.</para>

    <section>
      <title>Understand What You Will Be Doing</title>

      <para>If you are unfamiliar with the concept of symlinks take a look at
      this helpful introduction: <ulink
      url="http://librenix.com/?inode=5164">http://librenix.com/?inode=5164</ulink>.
      You will be "checking out" a <application>Koha</application> CVS
      repository and then symlinking your installed
      <application>Koha</application> directory tree to the CVS repository
      which will enable you to update to the latest stable version of
      <application>Koha</application> by issuing a simple CVS update
      command.</para>

      <para>The resulting directory structure will also afford you an easy
      centralized backup point for your <application>Koha</application>
      directory tree -- you should make sure to regularly backup your database
      and <application>Koha</application> directory tree to preserve your data
      as well as any customizations you've made to
      <application>Koha</application> templates, modules or scripts. More info
      on backing up your <application>Koha</application> system can be found
      in that section of the <application>Koha</application> documentation.
      For now, choose a location that is easy for you to remember. I have a
      directory <filename>/build</filename> on a separate partition that I use
      as the root directory for my <application>Koha</application>
      installation as well as custom library-specific scripts, backups, etc.,
      so in the examples I give, replace <filename>/build</filename> with the
      location that you have chosen.</para>

      <para>It's best to perform your update immediately after installing
      <application>Koha</application> to ensure that you will be running the
      very latest version. Also, if you setup the symlinks upon the initial
      install you may find that it's easier to roll-back an update if
      something should go wrong.</para>
    </section>
  </section>

  <section>
    <title>Checking Out Koha from Savannah</title>

    <para>The checking out process is quite simple. Change your directory to
    the directory you have selected as the root directory for your CVS working
    copy (mine is <filename>/build</filename>) and type: <userinput>cvs -z3
    -d:pserver:anonymous@cvs.savannah.nongnu.org:/sources/koha co -r rel_2_2
    koha</userinput></para>

    <para>At this point you should see a long listing of all the files that
    are being checked out, and eventually it will finish and you will be back
    at the command line:<literallayout>...
cvs checkout: Updating koha/z3950 
U koha/z3950/processz3950queue 
U koha/z3950/search.pl 
U koha/z3950/z3950-daemon-launch.sh 
U koha/z3950/z3950-daemon-shell.sh 
U koha/z3950/z3950import.pl 
cvs checkout: Updating koha/z3950/encodingfix 
U koha/z3950/encodingfix/Biblio.pm 
U koha/z3950/encodingfix/README-english 
U koha/z3950/encodingfix/README-polish 
U koha/z3950/encodingfix/search.pl 
cvs checkout: Updating koha/z3950/server 
U koha/z3950/server/zed-koha-server.pl 
[root@frodo]#</literallayout></para>

    <para>So now you have a new directory "koha" which contains the very
    latest files and bugfixes for that version of
    <application>Koha</application>. But this directory does not update your
    installed version of <application>Koha</application>. To do that you will
    need to link the installed directory tree to locations within the new
    directory you just created. One confusing element of this step is the fact
    that the CVS directory tree is quite different than the installation tree.
    This is because the organization of the documents after an installation
    doesn't make sense as the organization for developers to use while
    programming.</para>
  </section>

  <section>
    <title>Creating the Symlinks</title>

    <para>The first step you'll want to take is to backup your existing
    <application>Koha</application> directory tree. If you performed a default
    install of <application>Koha</application> without customizing your
    directory locations the following directories need to be backed up:</para>

    <itemizedlist>
      <listitem>
        <para><filename>/usr/local/koha/intranet/cgi-bin</filename></para>
      </listitem>

      <listitem>
        <para><filename>/usr/local/koha/intranet/htdocs/intranet-tmpl</filename></para>
      </listitem>

      <listitem>
        <para><filename>/usr/local/koha/intranet/modules/C4</filename></para>
      </listitem>

      <listitem>
        <para><filename>/usr/local/koha/opac/cgi-bin</filename></para>
      </listitem>

      <listitem>
        <para><filename>/usr/local/koha/opac/htdocs</filename></para>
      </listitem>
    </itemizedlist>

    <para>This is easily accomplished by using the <command>mv</command>
    command. For example, to backup the
    <filename>/usr/local/koha/intranet/cgi-bin</filename> directory, change
    directories to <filename>/usr/local/koha/intranet</filename> and
    issue:<literallayout>[root@frodo]# mv cgi-bin cgi-bin.bak</literallayout></para>

    <para>If for some reason you are having trouble with the symlinking or you
    want to revert back to the default directories you can always use this
    backup to restore things (simply reverse the above command).</para>

    <para>After backing up all of the above directories you'll be ready to
    create the symlinks. This is accomplished using the <command>ln</command>
    command with the <command>-s</command> option. For more info on
    <command>ln</command>, see the <command>man</command> page.</para>

    <para>$KOHA_WORKING_DIR is where you "checked out" Koha, $KOHA_INSTALL_DIR
    is where you installed Koha (/usr/local/koha by default) Here are the
    symlink mappings we're going to create:</para>

    <itemizedlist>
      <listitem>
        <para>$KOHA_WORKING_DIR ---&gt;
        $KOHA_INSTALL_DIR/intranet/cgi-bin</para>
      </listitem>

      <listitem>
        <para>$KOHA_WORKING_DIR/koha-tmpl/intranet-tmpl ---&gt;
        $KOHA_INSTALL_DIR/intranet/htdocs/intranet-tmpl</para>
      </listitem>

      <listitem>
        <para>$KOHA_WORKING_DIR/C4 ---&gt;
        $KOHA_INSTALL_DIR/intranet/modules/C4</para>
      </listitem>

      <listitem>
        <para>$KOHA_WORKING_DIR/opac ---&gt;
        $KOHA_INSTALL_DIR/opac/cgi-bin</para>
      </listitem>

      <listitem>
        <para>$KOHA_WORKING_DIR/koha-tmpl/opac-tmpl ---&gt;
        $KOHA_INSTALL_DIR/opac/htdocs/opac-tmpl</para>
      </listitem>
    </itemizedlist>

    <para>For example, to link the first directory listed above you would type
    the following:<literallayout>[root@frodo]# ln -s /koha /usr/local/koha/intranet/cgi-bin</literallayout></para>

    <section>
      <title>Automating the Symlink Creation</title>

      <para>Automating the symlink creation is a good idea if you want to have
      a record of exactly what you did to create the symlinks. Automating also
      makes it easier if you need to restore a <application>Koha</application>
      installation quickly. Here's a simple Perl script that I use to create
      my symlinks:</para>

      <programlisting>#!/usr/bin/perl -w

use strict;
use Getopt::Long;

my %opt = ();
GetOptions(
    \%opt,
    qw/working_dir=s install_dir=s no-backup help/
) or die "\nHouston, we got a problem\n";

if (exists $opt{help}) {
    print &lt;&lt;FIN;

Create symbolic links between a Koha installation and a Koha CVS working
directory.

Usage: koha_symlinks.pl --install_dir=&lt;installation directory&gt;
                        --working_dir=&lt;working directory&gt;
                        [--no-backup]
                        [--help]

--install_dir: is the directory where Koha is installed. By default,
  /usr/local/koha

--working_dir: where you checked out Koha. No default.

--no-backup: you really don't want to backup your installation directory

--help: show this help

FIN

      exit(0);
}

$opt{install_dir} = exists $opt{install_dir}
    ? $opt{install_dir}
    : '/usr/local/koha';

# Configurable Variables
foreach my $option (qw/working_dir install_dir/) {
  if (not exists $opt{$option}) {
    die 'option "', $option, '" is mandatory', "\n";
  }

  if (not -d $opt{$option}) {
    die '"', $opt{$option}, '" must be an existing directory', "\n";
  }

  if (not $opt{$option} =~ m{^/}) {
    die '--', $option, ' must be an absolute path', "\n";
  }
}

unless (exists $opt{'no-backup'}) {
    my @directories = (
        'intranet/cgi-bin',
        'intranet/htdocs/intranet-tmpl',
        'intranet/modules/C4',
        'opac/cgi-bin',
        'opac/htdocs',
    );

    foreach my $directory (map {$opt{install_dir}.'/'.$_} @directories) {
        system(
            'mv',
            $directory,
            $directory.'.bak'
        );
    }
}

system(
    'ln',
    '-s',
    $opt{working_dir},
    $opt{install_dir}.'/intranet/cgi-bin'
);

system(
    'ln',
    '-s',
    $opt{working_dir}.'/koha-tmpl/intranet-tmpl',
    $opt{install_dir}.'/intranet/htdocs/intranet-tmpl'
);

system(
    'ln',
    '-s',
    $opt{working_dir}.'/C4',
    $opt{install_dir}.'/intranet/modules/C4'
);

system(
    'ln',
    '-s',
    $opt{working_dir}.'/opac',
    $opt{install_dir}.'/opac/cgi-bin'
);

system(
    'ln',
    '-s',
    $opt{working_dir}.'/koha-tmpl/opac-tmpl',
    $opt{install_dir}.'/opac/htdocs'
);
</programlisting>
    </section>
  </section>

  <section>
    <title>Updating Your httpd.conf File</title>

    <para>Depending on your settings you may need to add the following line to
    both your intranet and opac virtual hosts configuration section of your
    <filename>httpd.conf</filename> or
    <filename>/etc/koha-httpd.conf</filename> file:<literallayout>Options +FollowSymLinks</literallayout></para>

    <para>This ensures that <application>Apache</application> will allow
    connections to symlinked directories.</para>
  </section>

  <section>
    <title>Updating Your Database</title>

    <para>The next step in updating your <application>Koha</application>
    installation is to update your database. Over time, when bugs are fixed or
    when new features are added, the <database>Koha</database> database is
    subject to change. The <filename>updatedatbase</filename> script will
    modify your database to the latest version. It's located in the
    <filename>koha/updater</filename> directory of the CVS working copy. It is
    strongly recommended that you backup your database before running the
    <filename>updatedatabase</filename> script. For more information on how to
    backup your system see that section in the <application>Koha</application>
    documentation.</para>

    <para>In order to run this script you may need to export the environment
    variable so that Perl knows where <filename>Context.pm</filename> is. You
    can do this by running:<literallayout>[root@frodo]# export PERL5LIB="<emphasis>your_koha_cvs_working_copy</emphasis>"</literallayout>or
    the path to your modules (usually
    <filename>/usr/local/koha/intranet/modules</filename>). Alternatively you
    can simply specify the path while executing the script:<literallayout>[root@frodo]# perl -I <emphasis>your_koha_cvs_working_copy</emphasis> updatedatabase</literallayout></para>

    <para>You may see some messages that look like this:<literallayout>localhost:/build/koha/updater# perl -I /build/koha updatedatabase
connected to your DB. Checking &amp; modifying it
Could convert to MyISAM database tables...
  Alter z3950random in marc_breeding
  Alter bookfundid in aqbookfund
  Alter aqbudgetid in aqbudget
  Alter id in z3950servers
Creating  index on z3950results
Checking for data required in table userflags...
Checking for data required in table systempreferences... </literallayout></para>
  </section>
</article>