File sispmctl.spec of Package sispmctl

#
# spec file for package sispmctl
#
# Copyright (c) 2025 SUSE LLC and contributors
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%define sha1 40100ef2f70b7ad9ca65b1b9a3d5e11b0d6e7b45
%define ver 4.12
%define so_ver 0

Name:           sispmctl
Version:        %ver
Release:        0
Summary:        Control SiS-PM USB-controlled Power Outlets
License:        GPL-2.0-or-later
URL:            https://sispmctl.sourceforge.net
#Downloaded from  https://sourceforge.net/code-snapshots/git/s/si/%{name}/git.git/%{name}-git-%{sha1}.zip#/%{name}-%{version}.zip
Patch0:         main-avoid-buffer-overrun.patch
Patch1:         main-do-not-assign-NULL-if-that-value-is-not-used.patch
Patch2:         Remove-nethelp.c-nethelp.h.patch
Patch3:         plannif_scanf-avoid-underflow.patch
Patch4:         socket_init-avoid-memory-leak.patch
Patch5:         Fix-web-skin-path-location.patch
Patch6:         Install-headers-as-well.patch
Patch7:         Extend-the-allowed-Address-Families-in-the-systemd-service-file.patch
Source:         %{name}-%{version}.zip
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  fdupes
BuildRequires:  libtool
BuildRequires:  libusb-compat-devel
BuildRequires:  systemd-rpm-macros
BuildRequires:  sysuser-tools
BuildRequires:  unzip
BuildRequires:  aaa_base
Requires:       user(%{name})
%sysusers_requires

%description
sispmctl is an application enabling the use of the GEMBIRD SiS-PM and
mSiS(sispm) USB-controlled power-outlet device under Linux. Note that
the device is also sold under different names.

%package -n lib%{name}%{so_ver}
Summary:        Shared Lib for %{name}

%description -n lib%{name}%{so_ver}
Shared library of package %{name}

%package devel
Summary:        Devel Package for %{name}
BuildArch:      noarch

%description devel
Devel package for %{name} containing headers for building.

%package -n system-user-%name
Summary:        %{name} System User
BuildArch:      noarch

%description -n system-user-%name
System user for package %{name}

%prep
%setup -q -n %{name}-git-%{sha1}
%autopatch -p1

%build
./autogen.sh
%configure \
    --docdir=%{_docdir}/%{name} \
    --includedir=%{_includedir}/%{name} \
    --with-webdir=%{_datadir}/%{name} \
    --disable-static
%make_build
sed -ie "s@/usr/local/bin@%{_bindir}@" examples/sispmctl.service
echo -e "u %{name}\ng %{name}" > system-user-%{name}.conf
%sysusers_generate_pre system-user-%{name}.conf %{name} system-user-%{name}.conf

%install
%make_install
rm -f %{buildroot}%{_libdir}/libsispmctl.so \
   %{buildroot}%{_libdir}/libsispmctl.la \
   %{buildroot}%{_docdir}/%{name}/README.md \
   %{buildroot}%{_docdir}/%{name}/COPYING
mkdir -m 0700 -p %{buildroot}%_sysconfdir/%{name}
mkdir -p %{buildroot}%{_sysusersdir}
install -D -m 644 system-user-%{name}.conf %{buildroot}%{_sysusersdir}/system-user-%{name}.conf
mkdir -p %{buildroot}%{_udevrulesdir}
mv %{buildroot}%{_docdir}/%{name}/examples/60-sispmctl.rules %{buildroot}%{_udevrulesdir}
mkdir -p %{buildroot}%{_unitdir}
mv %{buildroot}%{_docdir}/%{name}/examples/sispmctl.service %{buildroot}%{_unitdir}
mkdir -p %{buildroot}%{_sbindir}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcsispmctl
%fdupes -s %{buildroot}%{_datadir}/%{name}
cat > README.SUSE <<EOF
Sispmctl has been built with web support.
To use it, create a username/password by choosing a username and
password and run the following commands (when base64 waits for
input enter: <username>:<password> and terminate with Ctrl-D twice.

# base64 > %_sysconfdir/%name/password
# chmod 0700 %_sysconfdir/%name/password
# chown sispmctl:sispmctl %_sysconfdir/%name/password

Then start the service:

# systemctl enable --now sispmctl
EOF
%check
LD_LIBRARY_PATH=%{buildroot}%{_libdir} %{buildroot}%{_bindir}/sispmctl

%pre
%service_add_pre sispmctl.service

%pre -n system-user-%name -f %{name}.pre


%post
%service_add_post sispmctl.service

%preun
%service_del_preun sispmctl.service

%postun
%service_del_postun sispmctl.service

%post -n lib%{name}%{so_ver} -p /sbin/ldconfig
%postun -n lib%{name}%{so_ver} -p /sbin/ldconfig

%files
%license COPYING
%doc README.md README.SUSE
%attr(0700, %{name}, %{name}) %{_sysconfdir}/%{name}
%{_bindir}/sispmctl
%{_sbindir}/rcsispmctl
%{_mandir}/man1/*
%{_datadir}/%{name}
%{_docdir}/%{name}
%{_udevrulesdir}/60-sispmctl.rules
%{_unitdir}/sispmctl.service

%files -n lib%{name}%{so_ver}
%{_libdir}/libsispmctl.so.*

%files devel
%{_includedir}/%{name}

%files -n system-user-%name
%{_sysusersdir}/system-user-%{name}.conf

%changelog
openSUSE Build Service is sponsored by