File otrs.spec of Package otrs.import5098

#
# spec file for package otrs
#
# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%define otrsdoc_dir_files CHANGES COPYING* CREDITS INSTALL README* TODO UPGRADING doc
%define otrs_ver 2.4.11
%define itsm_ver 2.1.4
%define itsm_min 2.1

Name:           otrs
Summary:        The Open Ticket Request System
Version:        %{otrs_ver}
Release:        0.<RELEASE2>
License:        AGPLv3
Group:          Productivity/Networking/Email/Utilities
Url:            http://otrs.org/
AutoReqProv:    off
Source:         ftp://ftp.otrs.org/pub/otrs/%{name}-%{otrs_ver}.tar.bz2
Source1:        itsm-%{itsm_ver}.tar.bz2
Source2:        rpmlintrc
Source11:       sysconfig.%{name}
Source12:       %{name}.README.en
Source13:       %{name}.README.de
Source14:       itsm.README.en
Source15:       itsm.README.de
Source16:       ZZZAuto.pm
Patch0:         %{name}-2.4.7-init.patch
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
PreReq:         %insserv_prereq %fillup_prereq 
PreReq:         coreutils mktemp net-tools pwdutils
# /usr/bin/getent
PreReq:         glibc
PreReq:         apache2 grep sed
BuildRequires:  pwdutils
%if 0%{?suse_version} > 1020
BuildRequires:  fdupes
%endif
Requires:       apache2-mod_perl
Requires:       perl perl-DBI perl-GD perl-GDGraph perl-GDTextUtil perl-Digest-MD5
Requires:       perl-DBD-mysql perl-Net-DNS perl-PDF-API2
Requires:       mysql mysql-client fetchmail procmail
Recommends:     perl-Encode-HanExtra
Recommends:     perl-IO-Socket-SSL
Recommends:     perl-SOAP-Lite

%if "%_vendor" == "suse"
	%define	VENDOR SUSE
%else
	%define	VENDOR %_vendor
%endif

%description
OTRS is an open source ticket request system with many features to
manage customer telephone calls and e-mails. It is distributed under
the GNU General Public License (GPL) and tested on Linux, Solaris, AIX,
FreeBSD, and Mac OS 10.x. If you receive many e-mails and want to
answer them with a team of agents, OTRS is a tool that can help.

Feature list: see README

Authors list: see CREDITS  

%package doc
License:        AGPLv3
Summary:        OTRS Documentation
Group:          Documentation/Other

%description doc
This package contains the README, Changes and docs for OTRS

Authors list: see CREDITS  

%package -n otrs-itsm
License:        AGPLv3
Summary:        ITIL (R) focused IT service management
Version:        %{itsm_ver}
Release:        0.<RELEASE2>
Group:          Productivity/Networking/Email/Utilities
Requires:       %{name} >= 2.4.7
Provides:       itsm OTRS::ITSM

%description itsm
OTRS::ITSM implements ITIL (R) focused IT service management.

You need a OTRS %{otrs_ver} (http://otrs.org/) installation.

Make sure your database accepts packages over 5 MB in size. A MySQL database
for example accepts packages up to 1 MB by default. In this case, the value for
max_allowed_packet must be increased. The recommended maximum size accepted is
20 MB.

for INSTALL see INSTALL-%{itsm_min}.ITSM
please see README.itsm for further details, which comes with otrs package

Required OTRS::ITSM modules can be found under /opt/%{name}/itsm
  
Authors list: see CREDITS  

%prep
%setup -q -n %{name}-%{otrs_ver} -a 1
%patch0 -p1

find -name ".cvsignore" -type f | xargs rm -fv
pushd Kernel/Config/Files
%{__cp} %{S:16} .
popd

%build
%{_sbindir}/groupadd -g 88 -r %{name} 2>/dev/null || :
%{_sbindir}/useradd -c "OTRS User" -d /opt/%{name} -G %{name},www -g %{name} \
        -u 88 -r -s /bin/false %{name} 2>/dev/null || :
# copy config file
cp -a Kernel/Config.pm.dist Kernel/Config.pm
cd Kernel/Config/
for file in *.dist
do
        cp -a $file `basename $file .dist`
done
cd ../../
# copy all crontab dist files
for file in var/cron/*.dist
do
mv $file var/cron/`basename $file .dist`
done
rm INSTALL.RedHat
mv INSTALL.SuSE INSTALL

%install
export DESTROOT="/opt/%{name}/"
%{__install} -d ${RPM_BUILD_ROOT}/etc/init.d
%{__install} -d ${RPM_BUILD_ROOT}/etc/apache2/conf.d
%{__install} -d ${RPM_BUILD_ROOT}/etc/sysconfig
%{__install} -d ${RPM_BUILD_ROOT}${DESTROOT}
%{__install} -d ${RPM_BUILD_ROOT}%{_sbindir}
%{__install} -d ${RPM_BUILD_ROOT}/var/adm/fillup-templates
cp -a . ${RPM_BUILD_ROOT}/${DESTROOT}
for configFile in .fetchmailrc .mailfilter .procmailrc; do
        touch ${RPM_BUILD_ROOT}/${DESTROOT}/${configFile}
done
touch $RPM_BUILD_ROOT${DESTROOT}var/log/TicketCounter.log
# install README
for lang in en de; do
        cp -p "${RPM_SOURCE_DIR}/%{name}.README.${lang}" "README.%{VENDOR}.${lang}"
        cp -p "${RPM_SOURCE_DIR}/itsm.README.${lang}" "README.itsm.%{VENDOR}.${lang}"
done
# remove files that are part of the docdir
pushd ${RPM_BUILD_ROOT}/${DESTROOT}
rm -rf %{otrsdoc_dir_files}
%{__mkdir} doc
popd
# remove unneeded files from scripts
pushd ${RPM_BUILD_ROOT}/${DESTROOT}/scripts
rm -rf apache{,2}*.conf auto_build* auto_docbuild.sh redhat-* suse-*
popd

# install sysconfig file and init script
%{__install} -m 644 ${RPM_SOURCE_DIR}/sysconfig.%{name} $RPM_BUILD_ROOT/%{_var}/adm/fillup-templates/
%{__install} -m 755 scripts/suse-rc%{name} ${RPM_BUILD_ROOT}/etc/init.d/%{name}
ln -fs ../../etc/init.d/%{name} ${RPM_BUILD_ROOT}/%{_sbindir}/rc%{name}
# set permission
## FIXME - nochown patch obsolete, cause script complete changed
#${RPM_BUILD_ROOT}/opt/%{name}/bin/SetPermissions.sh ${RPM_BUILD_ROOT}/opt/%{name} %{name} wwwrun %{name} www echo

otrs_apache_conf="scripts/apache2-httpd-new.include.conf"
cp -p ${otrs_apache_conf} ${RPM_BUILD_ROOT}/etc/apache2/conf.d/%{name}.conf

# OTRS::ITSM
# rename itsm-%{itsm_ver} to itsm
pushd ${RPM_BUILD_ROOT}/${DESTROOT}
mv itsm-%{itsm_ver} itsm
popd

%if 0%{?suse_version} > 1020
%fdupes -s ${RPM_BUILD_ROOT}
%endif

%preun
%stop_on_removal otrs
:

%pre
# on `rpm -ivh` PARAM is 1
# on `rpm -Uvh` PARAM is 2
if [ -z  "`%{_bindir}/getent group %{name} 2>/dev/null`" ]; then
  %{_sbindir}/groupadd -g 88 -r %{name} 2>/dev/null
else
  if [ `%{_bindir}/id -g %{name}` != 88 ]; then
    %{_sbindir}/groupmod -g 88 %{name} 2>/dev/null
  fi
fi 
if [ -z "`%{_bindir}/getent passwd %{name} 2>/dev/null`" ]; then
  %{_sbindir}/useradd -c "OTRS User" -d /opt/%{name} -G %{name},www -g %{name} -u 88 -r -s /bin/false %{name} 2>/dev/null
else
  if [ `%{_bindir}/id -u %{name}` != 88 ]; then
    %{_sbindir}/usermod -G %{name},www -g %{name} -u 88 %{name} 2>/dev/null
  fi
fi

%post
# fill otrs sysconfig file
%{fillup_and_insserv otrs}
/usr/sbin/a2enmod perl >/dev/null
# if rpm is not in update mode
if ! [ ${FIRST_ARG:-0} -gt 1 ]; then
	if [ -z "${YAST_IS_RUNNING}" ]; then
		for lang in LC_ALL LC_MESSAGE LANG; do
			test "${!lang}" && break
		done
		echo
		case "${!lang}" in
			de_*)
				echo "Hinweise zur Erstkonfiguration von OTRS finden Sie in"
				echo "/usr/share/doc/packages/otrs/README.%{VENDOR}.de"
				;;
			*)
				echo "About the initial setup of OTRS, please read"
				echo "/usr/share/doc/packages/otrs/README.%{VENDOR}.en"
				;;
		esac
		echo
	fi
fi
exit 0

%postun
%restart_on_update otrs
%restart_on_update apache2
%insserv_cleanup

%clean
%{__rm} -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%dir /etc/apache2
%dir /etc/apache2/conf.d
%config(noreplace) /etc/apache2/conf.d/%{name}.conf
/etc/init.d/%{name}
/usr/sbin/rc%{name}
%{_var}/adm/fillup-templates/sysconfig.%{name}

# otrs HOME
%defattr(-,%{name},%{name})
%dir /opt/%{name}
%ghost %config(noreplace) /opt/%{name}/.fetchmailrc
%ghost %config(noreplace) /opt/%{name}/.mailfilter
%ghost %config(noreplace) /opt/%{name}/.procmailrc
/opt/%{name}/.fetchmailrc.dist
/opt/%{name}/.mailfilter.dist
/opt/%{name}/.procmailrc.dist
/opt/%{name}/ARCHIVE
/opt/%{name}/RELEASE

# doc and scripts
%defattr(-,wwwrun,%{name})
%dir /opt/%{name}/doc
/opt/%{name}/scripts/

# Kernel DIR
%defattr(0644,wwwrun,www,0755)
%dir /opt/%{name}/Kernel
%config(noreplace) /opt/%{name}/Kernel/Config.pm
/opt/%{name}/Kernel/Config.pm.dist
%dir /opt/%{name}/Kernel/Config
/opt/%{name}/Kernel/Config/Defaults.pm
%config(noreplace) /opt/%{name}/Kernel/Config/GenericAgent.pm
/opt/%{name}/Kernel/Config/GenericAgent.pm.*
%dir /opt/%{name}/Kernel/Config/Files
/opt/%{name}/Kernel/Config/Files/Framework.xml
/opt/%{name}/Kernel/Config/Files/Ticket.xml
/opt/%{name}/Kernel/cpan-lib
/opt/%{name}/Kernel/Language.pm
%dir /opt/%{name}/Kernel/Language
%config(noreplace) /opt/%{name}/Kernel/Language/*.pm
/opt/%{name}/Kernel/Modules/
%config(noreplace) /opt/%{name}/Kernel/Output/HTML/Standard/*.dtl
%config(noreplace) /opt/%{name}/Kernel/Output/HTML/Lite/*.dtl
%dir /opt/%{name}/Kernel/Output
%dir /opt/%{name}/Kernel/Output/HTML
%dir /opt/%{name}/Kernel/Output/HTML/Lite
%dir /opt/%{name}/Kernel/Output/HTML/Standard
/opt/%{name}/Kernel/Output/HTML/*.pm
/opt/%{name}/Kernel/System/

# bin
%defattr(0755,wwwrun,%{name},0755)
/opt/%{name}/bin
%attr(0700,%{name},root) /opt/%{name}/bin/DeleteSessionIDs.pl
%attr(0700,%{name},root) /opt/%{name}/bin/UnlockTickets.pl
%attr(0700,%{name},root) /opt/%{name}/bin/%{name}.getConfig

# var
%defattr(0644,%{name},www,0775)
%dir /opt/%{name}/var
/opt/%{name}/var/logo-%{name}.png
%dir /opt/%{name}/var/cron
%config(noreplace) /opt/%{name}/var/cron/*
/opt/%{name}/var/fonts
#%dir /opt/%{name}/var/packages
/opt/%{name}/var/packages
#%dir /opt/%{name}/var/pics
/opt/%{name}/var/pics
%dir /opt/%{name}/var/spool

# change defattr
%defattr(0644,%{name},www,2775)
%dir /opt/%{name}/var/article
%dir /opt/%{name}/var/log
%ghost %config(noreplace) %attr(660,%{name},www) /opt/%{name}/var/log/TicketCounter.log
%dir /opt/%{name}/var/tmp

# change defattr
%defattr(0644,wwwrun,www,0755)
#%dir /opt/%{name}/var/httpd
/opt/%{name}/var/httpd/
%dir /opt/%{name}/var/sessions
%dir /opt/%{name}/var/stats
/opt/%{name}/var/stats/*

%files doc
%defattr(-,root,root)
%doc %{otrsdoc_dir_files} scripts/apache2-httpd-new.include.conf

%files itsm
%defattr(-,root,root)
%doc itsm-%{itsm_ver}/INSTALL-%{itsm_min}.ITSM
#/opt/%{name}/itsm-%{itsm_ver}
/opt/%{name}/itsm
%config %attr(-,wwwrun,www) /opt/%{name}/Kernel/Config/Files/ZZZAuto.pm

%changelog
openSUSE Build Service is sponsored by