##
##  tsmc.spec -- OpenPKG RPM Specification
##  Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         tsmc
Summary:      Tivoli Storage Manager (TSM) Client
URL:          http://www.tivoli.com/support/storage_mgr/clients.html
Vendor:       Tivoli
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        Converter
License:      Commercial
Version:      5.1.5.6
Release:      20030108

#   list of sources
Source0:      ftp://service.boulder.ibm.com/storage/tivoli-storage-management/patches/client/v5r1/Linux/Linux86/v515/TIVsm-BA.i386.rpm
Source1:      ftp://service.boulder.ibm.com/storage/tivoli-storage-management/patches/client/v5r1/Solaris/v515/IP22545_6.tar.Z
Source2:      dsmexec
Source3:      dsm.sys
Source4:      dsm.opt
Source5:      rc.tsmc
%NoSource     0
%NoSource     1

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20030108
PreReq:       OpenPKG, openpkg >= 20030108
AutoReq:      no
AutoReqProv:  no

%description
    This is a stripped down version of the client part of the Tivoli
    Storage Manager (TSM v5) software. It can be used to backup Solaris,
    Linux and FreeBSD machines to a TSM server.

%prep
    %integrity
    %setup -q -T -c

%build
    #   unpack the corresponding binary only
    case "%{l_target}" in
        *-freebsd* | *-linux* )
            %{l_prefix}/bin/rpm2cpio %{SOURCE0} | cpio -idmu
            mv opt/tivoli/tsm/client root
            ;;
        *-solaris* )
            %{l_gzip} -d -c %{SOURCE IP22545_2.tar.Z} | %{l_tar} xf -
            %{l_prefix}/bin/gzip -d -c %{SOURCE1} | %{l_prefix}/bin/tar xf -
            pkgtrans `pwd`/TIVsmCba.pkg `pwd` TIVsmCba
            mv TIVsmCba/reloc root
            ;;
    esac

%install
    rm -rf $RPM_BUILD_ROOT

    #   create filesystem hiearchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/tsmc \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/en_US \
        $RPM_BUILD_ROOT%{l_prefix}/var/tsmc

    #   install execution wrapper
    %{l_shtool} install -c -m 755 \
        -e 's;@l_prefix@;%{l_prefix};g' \
        %{SOURCE dsmexec} $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/

    #   install binaries
    for f in dsmadmc dsmagent dsmc dsmcad dsmtca ; do
        file="root/ba/bin/$f"
        if [ -f "root/admin/bin/$f" ]; then
            file="root/admin/bin/$f"
        fi
        %{l_shtool} install -c -m 755 \
            $file $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/
        case "%{l_target}" in
            *-freebsd* ) brandelf -t Linux $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/$f ;;
        esac
        ln $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/dsmexec \
           $RPM_BUILD_ROOT%{l_prefix}/bin/$f
    done

    #   install required NLS stuff
    %{l_shtool} install -c -m 644 \
        root/ba/bin/en_US/* \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/en_US
    rm -f $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/en_US/wchelp.htl >/dev/null 2>&1 || true

    #   install default configuration
    case "%{l_target}" in
        *-freebsd* ) l_resutil="1" ;;
        * )          l_resutil="2" ;;
    esac
    %{l_shtool} install -c -m 755 \
        -e "s;@resutil@;${l_resutil};g" \
        -e 's;@l_prefix@;%{l_prefix};g' \
        %{SOURCE dsm.opt} %{SOURCE dsm.sys} \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/
    mv $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/dsm.sys \
       $RPM_BUILD_ROOT%{l_prefix}/etc/tsmc/dsm.sys
    ln -s ../../etc/tsmc/dsm.sys \
       $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/
    mv $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/dsm.opt \
       $RPM_BUILD_ROOT%{l_prefix}/etc/tsmc/dsm.opt
    ln -s ../../etc/tsmc/dsm.opt \
       $RPM_BUILD_ROOT%{l_prefix}/libexec/tsmc/

    #   install run-command script
    %{l_shtool} install -c -m 755 \
        -e 's;@l_prefix@;%{l_prefix};g' \
        -e 's;@l_musr@;%{l_musr};g' \
        -e 's;@l_mgrp@;%{l_mgrp};g' \
        %{SOURCE rc.tsmc} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/tsmc/*' \
        '%attr(4755,root,%{l_mgrp}) %{l_prefix}/bin/dsmtca'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
    if [ $1 -eq 1 ]; then
        case "%{l_target}" in
            *-freebsd*)
                if [ ! -f /compat/linux/bin/sh ]; then
                    ( echo "The Linux ABI base system is not installed under /compat/linux/."
                      echo "Please install the FreeBSD port/package linux_base-6.1."
                    ) | %{l_rpmtool} msg -b
                fi
                if [ ! -f /compat/linux/etc/mtab ]; then
                    ( echo "TSM insists on an /etc/mtab in the Linux ABI base system. Please"
                      echo "create /compat/linux/etc/mtab with at least these lines:"
                      awk </etc/fstab '
                          /^\/.+ufs.+/ { printf("%s\t%s\text2\trw\t1\t1\n", $1, $2); }
                      '
                    ) | %{l_rpmtool} msg -b
                fi
                ( if [ -r /etc/defaults/rc.conf ]; then
                      . /etc/defaults/rc.conf
                  fi
                  if [ -r /etc/rc.conf ]; then
                      . /etc/rc.conf
                  fi
                  case ${linux_enable} in
                      [Yy][Ee][Ss])
                          ;;
                      * )
                          ( echo "TSM requires the Linux ABI in the kernel."
                            echo "Run /usr/sbin/linux manually before running TSM"
                            echo "or add the following line to /etc/rc.conf:"
                            echo "linux_enable=\"YES\""
                          ) | %{l_rpmtool} msg -b
                          ;;
                  esac
                )
                ;;
            *-linux*)
                ( echo "Please make sure you have the vendor libstdc++ 2.9 package installed:"
                  echo "- RedHat Linux 7.x:     compat-libstdc++-6.2-2.9.0.16"
                  echo "- Debian GNU/Linux 2.2: libstdc++2.9-glibc2.1"
                  echo "- Debian GNU/Linux 3.0: libstdc++2.9-glibc2.1"
                  echo "The resulting library file has to be named libstdc++-libc6.1-1.so.2"
                ) | %{l_rpmtool} msg -b
                ;;
        esac
    fi

