##
##  mediaproxy.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:         mediaproxy
Summary:      NAT Traversal Solution for SIP Express Router
URL:          http://www.ag-projects.com/MediaProxy.html
Vendor:       AG Projects
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        VoIP
License:      GPL
Version:      1.9.1
Release:      20080112

#   list of sources
Source0:      http://mediaproxy.ag-projects.com/mediaproxy-%{version}.tar.gz
Source1:      rc.mediaproxy
Patch0:       mediaproxy.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, python
PreReq:       OpenPKG, openpkg >= 20160101, python, python-db::with_mysql = yes

%description
    MediaProxy is a far-end NAT traversal solution for SIP Express
    Router ([Open]SER). The proxy server is meant to be used in
    conjunction with [Open]SER's "mediaproxy" module.

%track
    prog mediaproxy = {
        version   = %{version}
        url       = http://mediaproxy.ag-projects.com/
        regex     = mediaproxy-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n mediaproxy
    %patch -p1
    %{l_shtool} subst \
        -e 's;mediaproxy.ini;%{l_prefix}/etc/mediaproxy/mediaproxy.ini;g' \
        modules/configuration.py
    %{l_shtool} subst \
        -e 's;/var/run/mediaproxy.sock;%{l_prefix}/var/mediaproxy/mediaproxy.sock;g' \
        -e 's;/var/run/proxydispatcher.sock;%{l_prefix}/var/mediaproxy/proxydispatcher.sock;g' \
        -e 's;/var/run/mediaproxy.pid;%{l_prefix}/var/mediaproxy/mediaproxy.pid;g' \
        -e 's;/var/run/proxydispatcher.pid;%{l_prefix}/var/mediaproxy/proxydispatcher.pid;g' \
        -e 's;openser;%{l_rgrp};g' \
        sessions.py utils/fakeconversations.py utils/rtpgenerator.py \
        modules/dispatcher.py modules/rtphandler.py \
        mediaproxy.py proxydispatcher.py mediaproxy.ini.sample
%build

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/modules \
        $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/utils \
        $RPM_BUILD_ROOT%{l_prefix}/etc/mediaproxy \
        $RPM_BUILD_ROOT%{l_prefix}/var/mediaproxy \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    cp -f *.py $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/
    cp -f utils/*.py $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/utils/
    cp -f modules/*.py $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/modules/
    cp -rf modules/external \
        $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/modules/
    cp -f mediaproxy.ini.sample $RPM_BUILD_ROOT%{l_prefix}/etc/mediaproxy/mediaproxy.ini
    ln  $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/mediaproxy.py \
        $RPM_BUILD_ROOT%{l_prefix}/sbin/mediaproxy
    ln  $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/proxydispatcher.py \
        $RPM_BUILD_ROOT%{l_prefix}/sbin/proxydispatcher
    ln  $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/sessions.py \
        $RPM_BUILD_ROOT%{l_prefix}/sbin/rtpsessions
    ln  $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/utils/fakeconversations.py \
        $RPM_BUILD_ROOT%{l_prefix}/bin/fakeconversations
    ln  $RPM_BUILD_ROOT%{l_prefix}/lib/python/site-packages/mediaproxy/utils/rtpgenerator.py \
        $RPM_BUILD_ROOT%{l_prefix}/bin/rtpgenerator
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.mediaproxy} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/mediaproxy/*' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/mediaproxy'

%files -f files

%clean

