File mysql-backupscript.spec of Package mysql-backupscript

#
# spec file for package mysql-backupscript
#
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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/
#


%if ! %{defined _fillupdir}
  %define _fillupdir %{_localstatedir}/adm/fillup-templates
%endif
%if 0%{?suse_version} >= 1210
%bcond_without systemd
%else
%bcond_with systemd
%endif

Name:           mysql-backupscript
Version:        2.0.2
Release:        0
Summary:        Simple mysql database backup
License:        BSD-3-Clause
Group:          System/Monitoring
URL:            https://github.com/openSUSE/mysql-backupscript
Source1:        mysql-backupscript
Source2:        mysql-backup.sysconfig
Source3:        mysql-backup.logrotate
Source4:        README.SUSE
Source5:        LICENSE
Source6:        %{name}.timer
Source7:        %{name}.service
Requires:       logrotate
Requires:       mailx
Requires:       mysql-client
Requires:       net-tools
Recommends:     xz
Requires(pre):  %fillup_prereq
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch
%if %{with systemd}
BuildRequires: systemd-rpm-macros
Requires(pre): systemd
%{?systemd_requires}
%else
Requires:       cron
%endif


%description
This package contains a simple mysql database backup script
running daily.

To restore, simply 'cd' into the backup directory of your
choise (configured in %{_sysconfdir}/sysconfig/mysql-backupscript),
bunzip2 the database file you want to restore and run:
  mysql < $dbfile
That's it. The script also copies your %{_sysconfdir}/my.cnf away, so
you have something at hand if you played too much with the
settings there ;-)

More information can be found in
 %{_docdir}/%{name}/README.SUSE

%prep
install -m644 %{SOURCE5} .
install -m644 %{SOURCE4} .

%build
#

%install
install -Dm755 %{SOURCE1} %{buildroot}/%{_sbindir}/mysql-backupscript
%if %{with systemd}
install -Dm644 %{SOURCE7} %{buildroot}%{_unitdir}/%{name}.service
install -Dm644 %{SOURCE6} %{buildroot}%{_unitdir}/%{name}.timer
ln -s %{_sbindir}/%{name} %{buildroot}/%{_sbindir}/rc%{name}
%else
mkdir -p %{buildroot}/%{_sysconfdir}/cron.daily
ln -s %{_sbindir}/%{name} %{buildroot}/%{_sysconfdir}/cron.daily/suse.de-mysql-backup
%endif
install -Dm644 %{SOURCE2} %{buildroot}/%{_fillupdir}/sysconfig.mysql-backupscript
install -Dm644 %{SOURCE3} %{buildroot}/%{_sysconfdir}/logrotate.d/%{name}

%check
output=$(%buildroot/%{_sbindir}/%{name} -h 2>&1) || :
exit_code=$(echo $?)
expected_exit_code=0
if [ "$exit_code" != "$expected_exit_code" ]; then
    echo "ERROR: exit code is not as expected: $exit_code"
    exit 1
fi

%if %{with systemd}
%pre
%service_add_pre %{name}.service %{name}.timer

%post
%service_add_post %{name}.service %{name}.timer
# enable the timer if the package is installed for the first time
if [ ${1:-0} -eq 1 ]; then
    %{_bindir}/systemctl enable %{name}.timer
    %{_bindir}/systemctl start %{name}.timer
fi
%{fillup_only %name}

%preun
%service_del_preun %{name}.service %{name}.timer

%postun
%service_del_postun %{name}.service %{name}.timer
%else
%post
%{fillup_only %{name}}
%endif

%files
%defattr(-,root,root)
%doc README*
%if 0%{?suse_version} >= 1500
%license LICENSE
%else
%doc LICENSE
%endif
%if %{with systemd}
%{_unitdir}/%{name}.service
%{_unitdir}/%{name}.timer
%{_sbindir}/rc%{name}
%else
%{_sysconfdir}/cron.daily/suse.de-mysql-backup
%endif
%{_sbindir}/%{name}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%if %{?suse_version} < 1230 &&  %{?suse_version} > 1140
%dir %{_fillupdir}
%endif
%{_fillupdir}/sysconfig.mysql-backupscript

%changelog