File saptune.spec of Package saptune.11733

#
# spec file for package saptune
#
# Copyright (c) 2017-2019 SUSE LLC.
#
# 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 http://bugs.opensuse.org/
#

%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates
%endif

Name:           saptune
Version:        2.0.1
Release:        0
License:        GPL-3.0
Summary:        Comprehensive system tuning management for SAP solutions
Url:            https://www.suse.com/products/sles-for-sap
Group:          System/Management
Source0:        %{name}-%{version}.tgz
Source1:        rpmlintrc
Source2:        %{name}-1.1.9.tgz
BuildRequires:  go tuned bash-completion
Requires:       tuned vim
Requires:       systemd >= 228-142.1
Requires:       /usr/bin/cpupower
Requires:       sysstat
Requires:       uuidd
ExclusiveArch:  x86_64 ppc64le
%{?systemd_requires}

%define GONS github.com/SUSE
%define SRCDIR   src/%{GONS}/%{name}

%description
The utility adjusts system parameters such as kernel parameters and resource
limits to allow running various SAP solutions at satisfactory performance.
The utility can be used in place of sapconf.

%prep
mkdir -p %{SRCDIR}_v2
cd %{SRCDIR}_v2
tar xf %{S:0}
cd %{_builddir}
mkdir -p %{SRCDIR}_v1
cd %{SRCDIR}_v1
tar xf %{S:2}

%build
export GOPATH=$(pwd)
ln -s %{_builddir}/%{SRCDIR}_v1 %{SRCDIR}
cd %{SRCDIR}
gzip ospackage/man/saptune_v1.8
go build -o saptune_v1
cd %{_builddir}
rm %{SRCDIR}
mv %{SRCDIR}_v2 %{SRCDIR}
cd %{SRCDIR}
gzip ospackage/man/saptune.8
gzip ospackage/man/saptune_v2.8
gzip ospackage/man/saptune-note.5
gzip ospackage/man/saptune-migrate.7
gzip ospackage/%{_datadir}/doc/packages/%{name}/sapconf2saptune.1
go build

%install
cd %{SRCDIR}
mkdir -p %{buildroot}/%{_sbindir}
install -m 0755 %{name} %{buildroot}/%{_sbindir}/
install -m 0755 ../%{name}_v1/%{name}_v1 %{buildroot}/%{_sbindir}/%{name}_v1

# Sysconfig file
mkdir -p %{buildroot}/%{_fillupdir}
install -m 0644 ospackage/etc/sysconfig/%{name} %{buildroot}/%{_fillupdir}/sysconfig.%{name}

# scripts location
mkdir -p %{buildroot}/%{_datadir}/%{name}/scripts
pushd ospackage/%{_datadir}/%{name}/scripts
for scriptfiles in *; do
    install -m 0755 $scriptfiles %{buildroot}/%{_datadir}/%{name}/scripts
done
popd

# note files location
mkdir -p %{buildroot}/%{_datadir}/%{name}/notes
pushd ospackage/%{_datadir}/%{name}/notes
for notefiles in *; do
    case $notefiles in
    1984787|2205917|1557506)
        # SLE12 notes
        %if 0%{?sle_version} < 150000
            install -m 0644 $notefiles %{buildroot}/%{_datadir}/%{name}/notes/
        %endif
        ;;
    2578899|2684254)
        # SLE15 notes
        %if 0%{?sle_version} >= 150000
            install -m 0644 $notefiles %{buildroot}/%{_datadir}/%{name}/notes/
        %endif
        ;;
    *)
        install -m 0644 $notefiles %{buildroot}/%{_datadir}/%{name}/notes/
        ;;
    esac
done
popd

# NoteTemplate file
install -m 0644 ospackage/%{_datadir}/%{name}/NoteTemplate.conf %{buildroot}/%{_datadir}/%{name}/NoteTemplate.conf

# solution definition
install -m 0644 ospackage/%{_datadir}/%{name}/solsdeprecated %{buildroot}/%{_datadir}/%{name}/solsdeprecated
%if 0%{?sle_version} < 150000
    install -m 0644 ospackage/%{_datadir}/%{name}/solutions %{buildroot}/%{_datadir}/%{name}/solutions
%else
    install -m 0644 ospackage/%{_datadir}/%{name}/solutions_15 %{buildroot}/%{_datadir}/%{name}/solutions
%endif

# vendor file location
mkdir -p %{buildroot}/%{_sysconfdir}/%{name}/extra

# override file location
mkdir -p %{buildroot}/%{_sysconfdir}/%{name}/override

# manual pages
mkdir -p %{buildroot}/%{_mandir}/man5
install -m 0644 ospackage/man/saptune-note.5.gz %{buildroot}/%{_mandir}/man5/
mkdir -p %{buildroot}/%{_mandir}/man7
install -m 0644 ospackage/man/saptune-migrate.7.gz %{buildroot}/%{_mandir}/man7/
mkdir -p %{buildroot}/%{_mandir}/man8
install -m 0644 ospackage/man/saptune.8.gz %{buildroot}/%{_mandir}/man8/
install -m 0644 ospackage/man/saptune_v2.8.gz %{buildroot}/%{_mandir}/man8/
install -m 0644 ../%{name}_v1/ospackage/man/saptune_v1.8.gz %{buildroot}/%{_mandir}/man8/

# One tuned profile
mkdir -p %{buildroot}/%{_libexecdir}/tuned/%{name}
cp ospackage/profile/* %{buildroot}/%{_libexecdir}/tuned/%{name}/
ls -lR %{buildroot}/%{_libexecdir}/tuned/%{name}/

# bash-completion
mkdir -p %{buildroot}/%{_datadir}/bash-completion/completions
install -m 0644 ospackage/%{_datadir}/bash-completion/completions/%{name}.completion %{buildroot}%{_datadir}/bash-completion/completions/%{name}

# helper script for support
mkdir -p %{buildroot}/%{_datadir}/doc/packages/%{name}
install -m 0755 ospackage/%{_datadir}/doc/packages/%{name}/sapconf2saptune %{buildroot}/%{_datadir}/doc/packages/%{name}/sapconf2saptune
install -m 0644 ospackage/%{_datadir}/doc/packages/%{name}/sapconf2saptune.1.gz %{buildroot}/%{_datadir}/doc/packages/%{name}

%pre
if [ $1 -ne 1 ]; then
    # package update

    NOTEDIR=/usr/share/saptune/notes
    STATEDIR=/var/lib/saptune/saved_state
    if [ ! -d ${NOTEDIR} ]; then
        # installed package version is < 2.0, update v1 to v2
        # indicated by missing directory /usr/share/saptune/notes

        # only change version to '1' (compatibility), if saptune is really used
        # so check, if a solution or a note is defined
        if (grep '^TUNE_FOR_SOLUTIONS[[:space:]]*=[[:space:]]*""' /etc/sysconfig/saptune >/dev/null 2>&1) && (grep '^TUNE_FOR_NOTES[[:space:]]*=[[:space:]]*""' /etc/sysconfig/saptune >/dev/null 2>&1); then
            echo "saptune NOT configured and NOT used - version will be set to '2'"
        else
            echo "saptune configured and used - version will be set to '1'"
            touch /tmp/update_v1tov2_saptune_inst || :

            # preserve 'old' BOBJ and ASE note definition files for saptune
            # version 1 compatibility
            if [ -f /etc/saptune/extra/SAP_BOBJ-SAP_Business_OBJects.conf ]; then
                cp /etc/saptune/extra/SAP_BOBJ-SAP_Business_OBJects.conf /etc/saptune/extra/SAP_BOBJ_n2c.conf
            fi
            if [ -f /etc/saptune/extra/SAP_ASE-SAP_Adaptive_Server_Enterprise.conf ]; then
                cp /etc/saptune/extra/SAP_ASE-SAP_Adaptive_Server_Enterprise.conf /etc/saptune/extra/SAP_ASE_n2c.conf
            fi
        fi
    #else
        # package version 2.0 or later
    fi
#else
    # initial installation
fi

%post
%fillup_only -n saptune

if [ $1 -ne 1 ]; then
    # package update
    if [ -f /tmp/update_v1tov2_saptune_inst ]; then
        # update from v1 to v2
        /usr/share/saptune/scripts/upd_helper v1tov2pi || :
    else
        # update from v2 to v2, call update helper script in posttrans
        touch /tmp/update_sle12tosel15_saptune_inst || :
    fi
#else
    # initial install
fi

%preun
test -n "$FIRST_ARG" || FIRST_ARG=$1
if [ $FIRST_ARG -eq 0 ]; then
    # Package removal, not upgrade
    # revert settings
    if (grep '^TUNE_FOR_SOLUTIONS[[:space:]]*=[[:space:]]*""' /etc/sysconfig/saptune >/dev/null 2>&1) && (grep '^TUNE_FOR_NOTES[[:space:]]*=[[:space:]]*""' /etc/sysconfig/saptune >/dev/null 2>&1); then
        # saptune note configured and not used - nothing to do
        :
    else
        # saptune configured and used - revert settings to clean up the system
        saptune daemon revert >/dev/null 2>&1 || :
    fi
    # clean up saved states left over
    rm -rf /var/lib/saptune/parameter/* /var/lib/saptune/saved_state/* || :
    # to suppress error messages from tuned, if the current active profile is
    # the removed saptune profile
    stvers=$(grep ^SAPTUNE_VERSION= /etc/sysconfig/saptune | awk -F '"' '{ print $2 }')
    (systemctl -q is-active tuned && [[ $(cat /etc/tuned/active_profile) == saptune ]] ) && ([[ "$stvers" == 1 ]] && tuned-adm off; /usr/sbin/saptune daemon stop >/dev/null 2>&1) || :
    # preserve 'old' BOBJ and ASE note definition files for saptune
    # version 1 compatibility
    if [ -f /etc/saptune/extra/SAP_BOBJ-SAP_Business_OBJects.conf ]; then
       echo "warning: /etc/saptune/extra/SAP_BOBJ-SAP_Business_OBJects.conf saved as /etc/saptune/extra/SAP_BOBJ-SAP_Business_OBJects.rpmsave"
        mv /etc/saptune/extra/SAP_BOBJ-SAP_Business_OBJects.conf /etc/saptune/extra/SAP_BOBJ-SAP_Business_OBJects.rpmsave || :
    fi
    if [ -f /etc/saptune/extra/SAP_ASE-SAP_Adaptive_Server_Enterprise.conf ]; then
	echo "warning: /etc/saptune/extra/SAP_ASE-SAP_Adaptive_Server_Enterprise.conf saved as /etc/saptune/extra/SAP_ASE-SAP_Adaptive_Server_Enterprise.conf.rpmsave"
        mv /etc/saptune/extra/SAP_ASE-SAP_Adaptive_Server_Enterprise.conf /etc/saptune/extra/SAP_ASE-SAP_Adaptive_Server_Enterprise.conf.rpmsave || :
    fi
    # preserve saptune configuration, if saptune was used
    # so check, if a solution or a note is defined
    if (grep '^TUNE_FOR_SOLUTIONS[[:space:]]*=[[:space:]]*""' /etc/sysconfig/saptune >/dev/null 2>&1) && (grep '^TUNE_FOR_NOTES[[:space:]]*=[[:space:]]*""' /etc/sysconfig/saptune >/dev/null 2>&1) && (grep '^NOTE_APPLY_ORDER[[:space:]]*=[[:space:]]*""' /etc/sysconfig/saptune >/dev/null 2>&1); then
       rm /etc/sysconfig/saptune || :
    else
       echo "warning: /etc/sysconfig/saptune saved as /etc/sysconfig/saptune.rpmsave"
       mv /etc/sysconfig/saptune /etc/sysconfig/saptune.rpmsave || :
    fi
fi

%posttrans -p /bin/bash
# Use a real bash script with an explicit "exit 0" at the end to be by default fail safe
# an explicit "exit 1" must be use to enforce package install/upgrade/erase failure where needed

if [ -f /tmp/update_v1tov2_saptune_inst ]; then
    # update from v1 to v2
    rm -f /tmp/update_v1tov2_saptune_inst || :

    # get back custom note definition files for BOBJ and/or ASE
    # needed for migration, if customer had applied these notes
    /usr/share/saptune/scripts/upd_helper v1tov2pt || :
fi
if [ -f /tmp/update_sle12tosel15_saptune_inst ]; then
    rm -f /tmp/update_sle12tosel15_saptune_inst || :
    # check for SAP Note name changes between SLE12 and SLE15
    /usr/share/saptune/scripts/upd_helper sle12to15pt || :
fi
exit 0

%files
%defattr(-,root,root)
%{_fillupdir}/sysconfig.%{name}
%{_sbindir}/%{name}
%{_sbindir}/%{name}_v1
%{_mandir}/man5/*
%{_mandir}/man7/*
%{_mandir}/man8/*
%dir %{_libexecdir}/tuned/%{name}
%{_libexecdir}/tuned/%{name}/*
%dir %{_sysconfdir}/%{name}
%dir %{_sysconfdir}/%{name}/extra
%dir %{_sysconfdir}/%{name}/override
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/notes
%dir %{_datadir}/%{name}/scripts
%{_datadir}/%{name}/notes/*
%{_datadir}/%{name}/scripts/*
%{_datadir}/%{name}/NoteTemplate.conf
%{_datadir}/%{name}/solutions
%{_datadir}/%{name}/solsdeprecated
%{_datadir}/bash-completion/completions/%{name}
%dir %{_datadir}/doc/packages/%{name}
%{_datadir}/doc/packages/%{name}/sapconf2saptune
%{_datadir}/doc/packages/%{name}/sapconf2saptune.1.gz
# Created at run-time by saptune executable
%ghost %dir %{_localstatedir}/lib/%{name}/
%ghost %dir %{_localstatedir}/lib/%{name}/parameter
%ghost %dir %{_localstatedir}/lib/%{name}/saved_state
openSUSE Build Service is sponsored by