##
##  omnisync.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:         omnisync
Summary:      Network Time Protocol (NTP) Alternative Backend Driver
URL:          http://www.vanheusden.com/time/omnisync/
Vendor:       Vanheusden
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Networking
License:      Open Source
Version:      1.0
Release:      20090104

#   list of sources
Source0:      http://www.vanheusden.com/time/omnisync/omnisync-%{version}.tgz
Source1:      rc.omnisync
Patch0:       omnisync.patch

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

%description
    OmniSync is a driver for NTPd for situations where the NTP protocol
    cannot be spoken directly, i.e., it enables systems to sync time
    when port 123 (UDP) is blocked. It allows you to sync against the
    daytime service (port 13 tcp/udp), time (port 37 tcp/udp), SNTS,
    ICMP, SNMP, precision time protocol (PTP - IEEE 1588), (S)NTP via a
    socks5 proxy server, http and https (both also via proxy server).
    It doesn't directly set the clock but uses NTPd for this as this
    enables you to have multiple time sources as well as bad-chimer
    detection etc.

%track
    prog omnisync = {
        version   = %{version}
        url       = http://www.vanheusden.com/time/omnisync/
        regex     = omnisync-(__VER__)\.tgz
    }

%prep
    %setup -q
    %patch -p0

%build
    %{l_make} %{l_mflags} \
        CC="%{l_cc}" \
        CFLAGS="%{l_cflags -O} %{l_cppflags}" \
        LDFLAGS="%{l_ldflags}"

%install
    %{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}/var/omnisync
    %{l_shtool} install -c -s -m 755 \
        omnisync $RPM_BUILD_ROOT%{l_prefix}/sbin/
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.omnisync} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/omnisync'

%files -f files

%clean

%post
    #   after upgrade, restart service
    if [ $1 -eq 1 ]; then
        #   display information about next steps
        ( echo "Configure NTP with:"
          echo "    # $RPM_INSTALL_PREFIX/etc/ntp/ntp.conf:"
          echo "    server 127.127.28.0"
        ) | %{l_rpmtool} msg -b -t notice
    fi
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} omnisync status 2>/dev/null`
    [ ".$omnisync_active" = .yes ] && %{l_rc} omnisync restart
    exit 0

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

