##
##  dante.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:         dante
Summary:      SOCKS Proxy Toolkit
URL:          http://www.inet.no/dante/
Vendor:       Inferno Nettverk A/S
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Networking
License:      BSD/CMU-type
Version:      1.4.1
Release:      20141009

#   list of sources
Source0:      ftp://ftp.inet.no/pub/socks/dante-%{version}.tar.gz
Source1:      sockd.conf
Source2:      socks.conf
Source3:      rc.dante

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101

%description
     Dante is a RFC1928 (SOCKS v5) based circuit-level firewall/proxy
     that can be used to provide convenient and secure network
     connectivity to a wide range of hosts while requiring only the
     server Dante runs on to have external network connectivity. Dante
     relays TCP and UDP both from outside the network to inside, and
     from inside to outside.

%track
    prog dante = {
        version   = %{version}
        url       = ftp://ftp.inet.no/pub/socks/
        regex     = dante-(\d+\.\d+\.\d+)\.tar\.gz
    }

%prep
    %setup -q

%build
    #   configure
    %{l_shtool} subst \
        -e 's;-Wall;;g' \
        -e 's;-Werror;;g' \
        configure
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --with-socks-conf=%{l_prefix}/etc/dante/socks.conf \
        --with-sockd-conf=%{l_prefix}/etc/dante/sockd.conf \
        --with-pidfile=%{l_prefix}/var/dante/sockd.pid \
        --disable-libwrap \
        --disable-preload

    #   build
    %{l_make} %{l_mflags -O}

%install
    #   install
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

    #   strip down installation
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/libsocks.so*
    %{l_shtool} subst \
        -e 's;^\(dlname=.\).*\(.\);\1\2;' \
        -e 's;^\(library_names=.\).*\(.\);\1\2;' \
        $RPM_BUILD_ROOT%{l_prefix}/lib/libsocks.la

    #   install default configurations
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/dante
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE sockd.conf} %{SOURCE socks.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/dante/

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

    #   create run-time directory
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/var/dante/tmp

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/dante/*'

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} dante status 2>/dev/null`
    [ ".$dante_active" = .yes ] && %{l_rc} dante restart
    exit 0

%preun
    #   before erase, stop service and remove log files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} dante stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/dante/sockd.log >/dev/null 2>&1 || true
    rm -f $RPM_INSTALL_PREFIX/var/dante/sockd.pid >/dev/null 2>&1 || true
    rm -f $RPM_INSTALL_PREFIX/var/dante/tmp/*     >/dev/null 2>&1 || true
    exit 0

