##
##  ez-ipupdate.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:         ez-ipupdate
Summary:      Assistant to Dynamic DNS Services
URL:          http://www.ez-ipupdate.com/
Vendor:       Angus Mackay
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        DNS
License:      GPL
Version:      3.0.10
Release:      20080101

#   list of sources
Source0:      http://ez-ipupdate.com/dist/ez-ipupdate-%{version}.tar.gz
Source1:      ez-ipupdate.conf
Source2:      rc.ez-ipupdate
Patch0:       ez-ipupdate.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, flex, bison
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  getopt
PreReq:       getopt

%description
    A client for automaticly updating your EZ-IP.net, justlinux.com,
    dhs.org, dyndns.org, ods.org, gnudip.cheapnet.net, tzo.com,
    easydns.com dynamic hostname parameters. Includes daemon support
    that only sends updates if your IP address changes.

%track
    prog ez-ipupdate = {
        version   = %{version}
        url       = http://www.ez-ipupdate.com/
        regex     = ez-ipupdate-(\d+\.\d+\.\d+)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0

%build
    #   config package
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O} `getopt-config --cflags`" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags} `getopt-config --ldflags`" \
    LIBS="`getopt-config --libs`" \
    ./configure \
        --prefix=%{l_prefix}

    #   build package
    %{l_make} %{l_mflags}

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/ez-ipupdate \
        $RPM_BUILD_ROOT%{l_prefix}/var/ez-ipupdate

    #   install program and default configuration
    %{l_shtool} install -c -s \
        ez-ipupdate $RPM_BUILD_ROOT%{l_prefix}/sbin/
    %{l_shtool} install -c -m 644 \
        %{SOURCE ez-ipupdate.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/ez-ipupdate/

    #   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.ez-ipupdate} $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/ez-ipupdate/ez-ipupdate.conf'

%files -f files

%clean

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

%preun
    #   before erase, stop service and remove run-time files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} ez-ipupdate stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/ez-ipupdate/* >/dev/null 2>&1 || true
    exit 0

