File dash-core.spec of Package dash-core

%global selinux_variants mls strict targeted

%bcond_with depends

%define boostargs %{nil}

%if 0%{?_no_gui:1}
%define _buildqt 0
%define buildargs --with-gui=no
%else
%define _buildqt 1
%define buildargs --with-qrencode --with-gui=qt5
%endif

# LTO breaks build because of inline assembler in src/compat/glibc_compat.cpp
%define _lto_cflags %{nil}

Name:		dash-core
Version:	21.1.0
Release:	1%{?dist}
Summary:	Dash - digital cash

Group:		Applications/System
License:	MIT
URL:		https://dash.org/
Source0:	https://github.com/dashpay/dash/archive/v%{version}/dash-%{version}.tar.gz

#selinux
Source30:	dash.te
# Source31 - what about dash-tx and bench_dash ???
Source31:	dash.fc
Source32:	dash.if

Patch1:         dash-core-newer-boost-fs.patch
Patch3:         dash-core-timeout_factor.patch

BuildRequires:  git-core
BuildRequires:	autoconf automake libtool
%if %{with depends}
BuildRequires:	gperf
BuildRequires:  libstdc++-static
%if 0%{?fedora} >= 39
BuildRequires:  python3dist(zombie-imp)
%endif
%else
BuildRequires:	boost-devel
BuildRequires:	miniupnpc-devel
BuildRequires:	libevent-devel
BuildRequires:	libdb4-cxx-devel
BuildRequires:  libbacktrace-devel
BuildRequires:  libnatpmp-devel
BuildRequires:	gmp-devel
%endif
BuildRequires:	python%{python3_pkgversion}-dash_hash

Source150:      update-sources.sh

%if %{with depends}
# Autogenerated section begin. Do not edit.
Source200:      https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source//boost_1_77_0.tar.bz2
Source201:      https://github.com/libevent/libevent/releases/download/release-2.1.12-stable//libevent-2.1.12-stable.tar.gz
Source202:      https://gmplib.org/download/gmp/gmp-6.2.1.tar.bz2
Source203:      https://github.com/ianlancetaylor/libbacktrace/archive/11427f31a64b11583fec94b4c2a265c7dafb1ab3.tar.gz#/backtrace_11427f31a64b11583fec94b4c2a265c7dafb1ab3.tar.gz
Source204:      https://download.qt.io/official_releases/qt/5.15/5.15.11/submodules/qtbase-everywhere-opensource-src-5.15.11.tar.xz
Source205:      https://download.qt.io/official_releases/qt/5.15/5.15.11/submodules/qttranslations-everywhere-opensource-src-5.15.11.tar.xz
Source206:      https://download.qt.io/official_releases/qt/5.15/5.15.11/submodules/qttools-everywhere-opensource-src-5.15.11.tar.xz
Source207:      https://github.com/libexpat/libexpat/releases/download/R_2_4_8//expat-2.4.8.tar.xz
Source208:      https://xcb.freedesktop.org/dist/libxcb-1.14.tar.xz
Source209:      https://xorg.freedesktop.org/archive/individual/proto/xcb-proto-1.15.2.tar.xz
Source210:      https://xorg.freedesktop.org/releases/individual/lib//libXau-1.0.9.tar.bz2
Source211:      https://xorg.freedesktop.org/releases/individual/proto/xproto-7.0.31.tar.bz2
Source212:      https://download.savannah.gnu.org/releases/freetype/freetype-2.11.0.tar.xz
Source213:      https://www.freedesktop.org/software/fontconfig/release//fontconfig-2.12.1.tar.bz2
Source214:      https://xkbcommon.org/download//libxkbcommon-0.8.4.tar.xz
Source215:      https://xcb.freedesktop.org/dist/xcb-util-0.4.0.tar.bz2
Source216:      https://xcb.freedesktop.org/dist/xcb-util-renderutil-0.3.9.tar.bz2
Source217:      https://xcb.freedesktop.org/dist/xcb-util-keysyms-0.4.0.tar.bz2
Source218:      https://xcb.freedesktop.org/dist/xcb-util-image-0.4.0.tar.bz2
Source219:      https://xcb.freedesktop.org/dist/xcb-util-wm-0.4.1.tar.bz2
Source220:      https://fukuchi.org/works/qrencode//qrencode-3.4.4.tar.bz2
Source221:      https://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz
Source222:      https://sqlite.org/2022//sqlite-autoconf-3380500.tar.gz
Source223:      https://miniupnp.tuxfamily.org/files//miniupnpc-2.2.2.tar.gz
Source224:      https://github.com/miniupnp/libnatpmp/archive/4536032ae32268a45c073a4d5e91bbab4534773a.tar.gz
Source225:      https://github.com/zeromq/libzmq/releases/download/v4.3.4//zeromq-4.3.4.tar.gz
# Autogenerated section end.
%endif


%description
Dash is a digital cryptographic currency that uses peer-to-peer technology to
operate with no central authority or banks; managing transactions and the
issuing of dashes is carried out collectively by the network.

%if %{_buildqt}
%package -n dash-qt
Summary:	Peer to Peer Cryptographic Currency
Group:		Applications/System
Obsoletes:	%{name} < %{version}-%{release}
Provides:	%{name} = %{version}-%{release}
%if !%{with depends}
%if 0%{?_use_qt4}
BuildRequires:	qt-devel
%else
BuildRequires:	qt5-qtbase-devel
# for /usr/bin/lrelease-qt5
BuildRequires:	qt5-linguist
%endif
BuildRequires:	protobuf-devel
BuildRequires:	qrencode-devel
%endif
BuildRequires:	%{_bindir}/desktop-file-validate
# for icon generation from SVG
BuildRequires:	%{_bindir}/inkscape

%description -n dash-qt
Dash is a digital cryptographic currency that uses peer-to-peer technology to
operate with no central authority or banks; managing transactions and the
issuing of dashes is carried out collectively by the network.

This package contains the Qt based graphical client and node. If you are looking
to run a Dash wallet, this is probably the package you want.
%endif


%package -n dash-libs
Summary:	Dash shared libraries
Group:		System Environment/Libraries

%description -n dash-libs
This package provides the dashconsensus shared libraries. These libraries
may be used by third party software to provide consensus verification
functionality.

Unless you know need this package, you probably do not.

%package -n dash-devel
Summary:	Development files for dash
Group:		Development/Libraries
Requires:	%{name}-libs = %{version}-%{release}

%description -n dash-devel
This package contains the header files and static library for the
dashconsensus shared library. If you are developing or compiling software
that wants to link against that library, then you need this package installed.

Most people do not need this package installed.

%package -n dash-server
Summary:	The dash daemon
Group:		System Environment/Daemons
Requires:	dash-utils = %{version}-%{release}
Requires:	selinux-policy policycoreutils policycoreutils-python-utils
Requires:	firewalld-filesystem
Requires(pre):	shadow-utils
Requires(post):	%{_sbindir}/semodule %{_sbindir}/restorecon %{_sbindir}/fixfiles %{_sbindir}/sestatus
Requires(postun):	%{_sbindir}/semodule %{_sbindir}/restorecon %{_sbindir}/fixfiles %{_sbindir}/sestatus
BuildRequires:	systemd
BuildRequires:	checkpolicy
BuildRequires:	%{_datadir}/selinux/devel/Makefile
%if !%{with depends}
BuildRequires:	zeromq-devel
%endif
BuildRequires:	python%{python3_pkgversion}-zmq
BuildRequires:	firewalld-filesystem

%description -n dash-server
This package provides a stand-alone dash-core daemon. For most users, this
package is only needed if they need a full-node without the graphical client.

Some third party wallet software will want this package to provide the actual
dash-core node they use to connect to the network.

If you use the graphical dash-core client then you almost certainly do not
need this package.

%package -n dash-utils
Summary:	Dash utilities
Group:		Applications/System

%description -n dash-utils
This package provides several command line utilities for interacting with a
dash-core daemon.

The dash-cli utility allows you to communicate and control a dash daemon
over RPC, the dash-tx utility allows you to create a custom transaction, and
the bench_dash utility can be used to perform some benchmarks.

This package contains utilities needed by the dash-server package.


%prep
%autosetup -S git_am -n dash-%{version}
mkdir SELinux
cp -p %{SOURCE30} %{SOURCE31} %{SOURCE32} SELinux/

# Replace share/genbuild.sh script with the one that generates
# hardcoded version tag and stable build datetime equal to
# package version and date of newest file in tarball respectively.
d="`%{__tar} xf %{SOURCE0} --to-command '/bin/echo $TAR_MTIME' | sort | tail -1`"
mv share/genbuild.sh share/genbuild.sh.orig
cat >share/genbuild.sh <<EOF
#!/bin/sh
test \$# -le 0 && {
  echo "Usage: \$0 FILENAME [SRCROOT]" >&2
  exit 1
}
FILE="\$1"
test \$# -gt 1 && cd "\$2"
echo '#define BUILD_DESC "v%{version}"' >"\$FILE"
echo '#define BUILD_DATE "`date -d @$d -u '+%%Y-%%m-%%d %%H:%%M:%%S %%z'`"' >>"\$FILE"
EOF
chmod a+x share/genbuild.sh

%if %{with depends}
# Copy sources for depends and write download stamps with checksums
makefile='include Makefile
list_pkgs:; @$(foreach p,$(all_packages),echo $(p):$($(p)_sha256_hash):$($(p)_all_sources);)'
%{__mkdir_p} depends/sources/download-stamps
%{__make} -s -C depends -f /dev/stdin list_pkgs <<<"$makefile" |
while IFS=: read pkg sha256sum files; do
  if [ -n "$sha256sum" ]; then
    first=true
    for file in $files; do
      %{__cp} "%{_sourcedir}/$file" "depends/sources/$file"
      if $first; then
        echo "$sha256sum $file" > "depends/sources/download-stamps/.stamp_fetched-${pkg}-${file}.hash"
        (cd depends/sources && %{_bindir}/sha256sum -c "download-stamps/.stamp_fetched-${pkg}-${file}.hash")
        if [ "$pkg" = native_protobuf ]; then
          echo "$sha256sum $file" > "depends/sources/download-stamps/.stamp_fetched-protobuf-${file}.hash"
        fi
        first=false
      fi
    done
  fi
done
%endif


%build
CWD=`pwd`
./autogen.sh
%if %{with depends}
HOST="`./depends/config.guess`"
make -C depends HOST="$HOST" %{?_smp_mflags}
CONFIG_SITE="$PWD/depends/$HOST/share/config.site"
export CONFIG_SITE
%endif
%configure --with-miniupnpc --enable-glibc-back-compat %{buildargs} %{boostargs}
make %{?_smp_mflags}

pushd SELinux
for selinuxvariant in %{selinux_variants}; do
	make NAME=${selinuxvariant} -f %{_datadir}/selinux/devel/Makefile
	mv dash.pp dash.pp.${selinuxvariant}
	make NAME=${selinuxvariant} -f %{_datadir}/selinux/devel/Makefile clean
done
popd


%install
make install DESTDIR=%{buildroot}

find %{buildroot} -name "*.la" -delete

mkdir -p -m755 %{buildroot}%{_sbindir}
mv %{buildroot}%{_bindir}/dashd %{buildroot}%{_sbindir}/dashd

# systemd stuff
mkdir -p %{buildroot}%{_tmpfilesdir}
cat <<EOF > %{buildroot}%{_tmpfilesdir}/dash.conf
d /run/dashd 0750 dash dash -
EOF
touch -a -m -t 201504280000 %{buildroot}%{_tmpfilesdir}/dash.conf

mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
cat <<EOF > %{buildroot}%{_sysconfdir}/sysconfig/dash
# Provide options to the dash daemon here, for example
# OPTIONS="-testnet -disable-wallet"

OPTIONS=""

# System service defaults.
# Don't change these unless you know what you're doing.
CONFIG_FILE="%{_sysconfdir}/dash/dash.conf"
DATA_DIR="%{_localstatedir}/lib/dash"
PID_FILE="/run/dashd/dashd.pid"
EOF
touch -a -m -t 201504280000 %{buildroot}%{_sysconfdir}/sysconfig/dash

mkdir -p %{buildroot}%{_unitdir}
cat <<EOF > %{buildroot}%{_unitdir}/dash.service
[Unit]
Description=Dash daemon
After=syslog.target network.target

[Service]
Type=forking
ExecStart=%{_sbindir}/dashd -daemon -conf=\${CONFIG_FILE} -datadir=\${DATA_DIR} -pid=\${PID_FILE} \$OPTIONS
EnvironmentFile=%{_sysconfdir}/sysconfig/dash
User=dash
Group=dash

Restart=on-failure
PrivateTmp=true
TimeoutStopSec=120
TimeoutStartSec=60
StartLimitInterval=240
StartLimitBurst=5

[Install]
WantedBy=multi-user.target
EOF
touch -a -m -t 201504280000 %{buildroot}%{_unitdir}/dash.service
#end systemd stuff

mkdir %{buildroot}%{_sysconfdir}/dash
mkdir -p %{buildroot}%{_localstatedir}/lib/dash

#SELinux
for selinuxvariant in %{selinux_variants}; do
	install -d %{buildroot}%{_datadir}/selinux/${selinuxvariant}
	install -p -m 644 SELinux/dash.pp.${selinuxvariant} %{buildroot}%{_datadir}/selinux/${selinuxvariant}/dash.pp
done

# firewalld
install -d %{buildroot}/usr/lib/firewalld/services

cat <<EOF > %{buildroot}/usr/lib/firewalld/services/dash.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Dash server</short>
  <description>Dash is a digital cryptographic currency that uses peer-to-peer technology to operate with no central authority or banks. Open this service to participate in Dast p2p network.</description>
  <port port="9999" protocol="tcp"/>
</service>
EOF

cat <<EOF > %{buildroot}/usr/lib/firewalld/services/dash-testnet.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Dash server (testnet)</short>
  <description>Dash is a digital cryptographic currency that uses peer-to-peer technology to operate with no central authority or banks. Open this service to participate in Dast p2p testing network.</description>
  <port port="19999" protocol="tcp"/>
</service>
EOF

%if %{_buildqt}
# qt icons
install -D -p share/pixmaps/dash.ico %{buildroot}%{_datadir}/pixmaps/dash.ico
install -d %{buildroot}%{_datadir}/icons/hicolor/scalable/apps
install -p share/pixmaps/dash-hicolor-scalable.svg %{buildroot}%{_datadir}/icons/hicolor/scalable/apps/dash.svg
inkscape_export_opt=
for opt in --export-png --export-filename --export-file; do
  if %{_bindir}/inkscape --help | fgrep -q -e "$opt"; then
    inkscape_export_opt="$opt"
    break
  fi
done
if [ -z "$inkscape_export_opt" ]; then
  echo "Unknown version of inkscape: unable to determine PNG export option" >&2
  exit 1
fi
for size in 16 22 24 32 48 64 128 256; do
  install -d %{buildroot}%{_datadir}/icons/hicolor/${size}x${size}/apps
  %{_bindir}/inkscape share/pixmaps/dash-hicolor-scalable.svg "${inkscape_export_opt}=%{buildroot}%{_datadir}/icons/hicolor/${size}x${size}/apps/dash.png" -w ${size} -h ${size}
  touch %{buildroot}%{_datadir}/icons/hicolor/${size}x${size}/apps/dash.png -r share/pixmaps/dash-hicolor-scalable.svg
done

# Desktop File - change the touch timestamp if modifying
mkdir -p %{buildroot}%{_datadir}/applications
cat <<EOF > %{buildroot}%{_datadir}/applications/dash-qt.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Dash
Comment=Dash P2P Cryptocurrency
Comment[fr]=Dash, monnaie virtuelle cryptographique pair à pair
Comment[tr]=Dash, eşten eşe kriptografik sanal para birimi
Exec=dash-qt %u
Terminal=false
Type=Application
Icon=dash
MimeType=x-scheme-handler/dash;
Categories=Office;Finance;
EOF
# change touch date when modifying desktop
touch -a -m -t 201511100546 %{buildroot}%{_datadir}/applications/dash-qt.desktop
%{_bindir}/desktop-file-validate %{buildroot}%{_datadir}/applications/dash-qt.desktop

# KDE protocol - change the touch timestamp if modifying
mkdir -p %{buildroot}%{_datadir}/kde4/services
cat <<EOF > %{buildroot}%{_datadir}/kde4/services/dash-core.protocol
[Protocol]
exec=dash-qt '%u'
protocol=dash
input=none
output=none
helper=true
listing=
reading=false
writing=false
makedir=false
deleting=false
EOF
# change touch date when modifying protocol
touch -a -m -t 201511100546 %{buildroot}%{_datadir}/kde4/services/dash-core.protocol
%endif

# nuke these, we do extensive testing of binaries in %%check before packaging
rm -f %{buildroot}%{_bindir}/test_*

%check
%if %{with depends}
HOST="`./depends/config.guess`"
LD_LIBRARY_PATH="$PWD/depends/$HOST/lib"
export LD_LIBRARY_PATH
%endif
make check
pushd src
srcdir=. ../test/util/bitcoin-util-test.py
popd
./test/functional/test_runner.py \
    --timeout-factor=3 \
    --extended %{?_smp_mflags} \
    --exclude feature_pruning,feature_dbcrash

%post -n dash-libs -p /sbin/ldconfig

%postun -n dash-libs -p /sbin/ldconfig

%pre -n dash-server
getent group dash >/dev/null || groupadd -r dash
getent passwd dash >/dev/null ||
	useradd -r -g dash -d /var/lib/dash -s /sbin/nologin \
	-c "Dash wallet server" dash
exit 0

%post -n dash-server
%systemd_post dash.service
# SELinux
if [ `%{_sbindir}/sestatus |grep -c "disabled"` -eq 0 ]; then
for selinuxvariant in %{selinux_variants}; do
	%{_sbindir}/semodule -s ${selinuxvariant} -i %{_datadir}/selinux/${selinuxvariant}/dash.pp &> /dev/null || :
done
%{_sbindir}/semanage port -a -t dash_port_t -p tcp 9998
# Port 9999 is already labeled as jboss_management_port_t
%{_sbindir}/semanage port -a -t dash_port_t -p tcp 19998
%{_sbindir}/semanage port -a -t dash_port_t -p tcp 19999
%{_sbindir}/fixfiles -R dash-server restore &> /dev/null || :
%{_sbindir}/restorecon -R %{_localstatedir}/lib/dash || :
fi
%firewalld_reload

%posttrans -n dash-server
%{_bindir}/systemd-tmpfiles --create

%preun -n dash-server
%systemd_preun dash.service

%postun -n dash-server
%systemd_postun_with_restart dash.service
# SELinux
if [ $1 -eq 0 ]; then
	if [ `%{_sbindir}/sestatus |grep -c "disabled"` -eq 0 ]; then
	%{_sbindir}/semanage port -d -p tcp 9998
        # Port 9999 is already labeled as jboss_management_port_t
	%{_sbindir}/semanage port -d -p tcp 19998
	%{_sbindir}/semanage port -d -p tcp 19999
	for selinuxvariant in %{selinux_variants}; do
		%{_sbindir}/semodule -s ${selinuxvariant} -r dash &> /dev/null || :
	done
	%{_sbindir}/fixfiles -R dash-server restore &> /dev/null || :
	[ -d %{_localstatedir}/lib/dash ] && \
		%{_sbindir}/restorecon -R %{_localstatedir}/lib/dash &> /dev/null || :
	fi
fi

%clean
rm -rf %{buildroot}

%if %{_buildqt}
%files -n dash-qt
%defattr(-,root,root,-)
%license COPYING
%doc COPYING contrib/debian/examples/dash.conf doc/README.md doc/bips.md doc/files.md doc/reduce-traffic.md doc/release-notes.md doc/tor.md
%attr(0755,root,root) %{_bindir}/dash-qt
%attr(0644,root,root) %{_datadir}/applications/dash-qt.desktop
%attr(0644,root,root) %{_datadir}/kde4/services/dash-core.protocol
%attr(0644,root,root) %{_datadir}/pixmaps/*.ico
%attr(0644,root,root) %{_datadir}/icons/hicolor/scalable/apps/dash.svg
%attr(0644,root,root) %{_datadir}/icons/hicolor/*/apps/dash.png
%attr(0644,root,root) %{_mandir}/man1/dash-qt.1*
%endif

%files -n dash-libs
%defattr(-,root,root,-)
%license COPYING
%doc COPYING doc/README.md doc/shared-libraries.md
%{_libdir}/lib*.so.*

%files -n dash-devel
%defattr(-,root,root,-)
%license COPYING
%doc COPYING doc/README.md doc/developer-notes.md doc/shared-libraries.md
%attr(0644,root,root) %{_includedir}/*.h
%{_libdir}/*.so
%{_libdir}/*.a
%attr(0644,root,root) %{_libdir}/pkgconfig/*.pc

%files -n dash-server
%defattr(-,root,root,-)
%license COPYING
%doc COPYING contrib/debian/examples/dash.conf doc/README.md doc/REST-interface.md doc/bips.md doc/dnsseed-policy.md doc/files.md doc/instantsend.md doc/masternode*.md doc/reduce-traffic.md doc/release-notes.md doc/tor.md doc/zmq.md
%attr(0755,root,root) %{_sbindir}/dashd
%attr(0644,root,root) %{_tmpfilesdir}/dash.conf
%attr(0644,root,root) %{_unitdir}/dash.service
%dir %attr(0750,dash,dash) %{_sysconfdir}/dash
%dir %attr(0750,dash,dash) %{_localstatedir}/lib/dash
%config(noreplace) %attr(0600,root,root) %{_sysconfdir}/sysconfig/dash
%attr(0644,root,root) %{_datadir}/selinux/*/*.pp
%attr(0644,root,root) %{_mandir}/man1/dashd.1*
%attr(0644,root,root) /usr/lib/firewalld/services/*.xml

%files -n dash-utils
%defattr(-,root,root,-)
%license COPYING
%doc COPYING contrib/debian/examples/dash.conf doc/README.md
%attr(0755,root,root) %{_bindir}/dash-cli
%attr(0755,root,root) %{_bindir}/dash-tx
%attr(0755,root,root) %{_bindir}/dash-wallet
%attr(0755,root,root) %{_bindir}/bench_dash
%attr(0644,root,root) %{_mandir}/man1/dash-cli.1*
%attr(0644,root,root) %{_mandir}/man1/dash-tx.1*
%attr(0644,root,root) %{_mandir}/man1/dash-wallet.1*