##
##  typo3.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  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:         typo3
Summary:      Enterprise Content Management System (CMS)
URL:          http://typo3.com/
Vendor:       TYPO3 Association et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        CMS
License:      GPL
Version:      6.1.7
Release:      20131210

#   list of sources
Source0:      http://download.sourceforge.net/typo3/typo3_src-%{version}.tar.gz
Source1:      http://download.sourceforge.net/typo3/dummy-%{version}.tar.gz
Source2:      rc.typo3
Source3:      typo3-apache.conf
Source4:      typo3-setup.sh

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, cpio
PreReq:       OpenPKG, openpkg >= 20160101
PreReq:       apache
PreReq:       apache-php
PreReq:       apache-php::with_mysql = yes
PreReq:       apache-php::with_sendmail = yes
PreReq:       apache-php::with_gd = yes
PreReq:       apache-php::with_freetype = yes
PreReq:       apache-php::with_mm = yes
PreReq:       apache-php::with_xml = yes

%description
    TYPO3 is a free Open Source content management system for enterprise
    purposes on the Web and in intranets. It offers full flexibility
    and extendability while featuring an accomplished set of ready-made
    interfaces, functions and modules.

%track
    prog typo3:typo3 = {
        version   = %{version}
        url       = http://typo3.org/download/packages/
        regex     = typo3_src-(\d+\.\d+\.\d+)\.tar\.gz
    }
    prog typo3:dummy = {
        version   = %{version}
        url       = http://typo3.org/download/packages/
        regex     = dummy-(\d+\.\d+\.\d+)\.tar\.gz
    }

%prep
    %setup -q -n typo3_src-%{version}

%build
    %{l_shtool} subst \
        -e 's;/usr/X11R6/bin/;%{l_prefix}/bin/;' \
        -e 's;/usr/bin/;%{l_prefix}/bin/;' \
        t3lib/config_default.php

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/typo3 \
        $RPM_BUILD_ROOT%{l_prefix}/lib/typo3 \
        $RPM_BUILD_ROOT%{l_prefix}/var/typo3/cms \
        $RPM_BUILD_ROOT%{l_prefix}/var/typo3/run \
        $RPM_BUILD_ROOT%{l_prefix}/var/typo3/log

    #   install program code
    (find . -depth -print | cpio -o 2>/dev/null) |\
    (cd $RPM_BUILD_ROOT%{l_prefix}/lib/typo3; cpio -idmu) || exit $?

    #   install skeleton CMS
    %{l_shtool} install -c -m 644 \
        %{SOURCE dummy-%{version}.tar.gz} \
        $RPM_BUILD_ROOT%{l_prefix}/lib/typo3/

    #   install MySQL database setup script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE typo3-setup.sh} $RPM_BUILD_ROOT%{l_prefix}/sbin/typo3-setup

    #   install run-command script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.typo3} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   install Apache server configuration
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE typo3-apache.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/typo3/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/typo3/typo3-apache.conf' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/typo3/*'

%files -f files

%clean

%post
    if [ $1 -eq 1 ]; then
        #   make sure a default CMS named "typo3" is available
        if [ ! -d $RPM_INSTALL_PREFIX/var/typo3/cms/typo3 ]; then
            ( echo "Creating default CMS named \"typo3\""
            ) | %{l_rpmtool} msg -b -t notice

            #   unpack skeleton CMS
            ( cd $RPM_INSTALL_PREFIX/var/typo3/cms || exit $?
              %{l_tar} xf $RPM_INSTALL_PREFIX/lib/typo3/dummy-%{version}.tar.gz || exit $?
              mv dummy-%{version} typo3 || exit $?
            ) || exit $?

            #   link default CMS to program code
            rm -f $RPM_INSTALL_PREFIX/var/typo3/cms/typo3/typo3_src
            %{l_shtool} mkln -s \
                $RPM_INSTALL_PREFIX/lib/typo3 \
                $RPM_INSTALL_PREFIX/var/typo3/cms/typo3/typo3_src

            #   create hint file for TYPO3 1-2-3 installer
            touch $RPM_INSTALL_PREFIX/var/typo3/cms/typo3/typo3conf/ENABLE_INSTALL_TOOL

            #   fixate file ownerships
            chown -R %{l_rusr}:%{l_rgrp} \
                $RPM_INSTALL_PREFIX/var/typo3/cms/typo3 >/dev/null 2>&1 || true
        fi

        #   display final hints on initial installation
        ( echo "1. To complete this installation of TYPO3 please start MySQL and"
          echo "   initialize the TYPO3 database like this:"
          echo "     \$ $RPM_INSTALL_PREFIX/bin/openpkg rc mysql start"
          echo "     \$ $RPM_INSTALL_PREFIX/sbin/typo3-setup install"
          echo ""
          echo "2. By default, TYPO3 runs its own Apache server on IPv4 address"
          echo "   127.0.0.1, TCP port 8082. Please change this by editing the"
          echo "   \"Listen 127.0.0.1:8082\" directive in the configuration file"
          echo "     $RPM_INSTALL_PREFIX/etc/typo3/typo3-apache.conf"
          echo ""
          echo "3. After this postinstallation, start TYPO3 by running"
          echo "     \$ $RPM_INSTALL_PREFIX/bin/openpkg rc typo3 start"
          echo "   and initialize the TYPO3 database by connecting to:"
          echo "     http://127.0.0.1:8082/typo3/"
          echo "   Now configure TYPO3 for access to the database \"typo3\""
          echo "   with the login \"typo3\" and password \"typo3\"."
          echo ""
          echo "4. Now you can access TYPO3 at the following two URLs:"
          echo "     http://127.0.0.1:8082/typo3/       (website)"
          echo "     http://127.0.0.1:8082/typo3/typo3/ (administration)"
          echo "   Login with username \"admin\" and password \"password\""
          echo "   at the administration interface."
        ) | %{l_rpmtool} msg -b -t notice
    fi
    exit 0

%preun
    if [ $1 -eq 0 ]; then
        #   before erase, stop service and remove log files
        %{l_rc} typo3 stop 2>/dev/null
        $RPM_INSTALL_PREFIX/sbin/typo3-setup uninstall >/dev/null 2>&1 || true
        rm -rf $RPM_INSTALL_PREFIX/var/typo3/cms/* >/dev/null 2>&1 || true
        rm -f  $RPM_INSTALL_PREFIX/var/typo3/log/* >/dev/null 2>&1 || true
        rm -f  $RPM_INSTALL_PREFIX/var/typo3/run/* >/dev/null 2>&1 || true
    fi
    exit 0

