:license: Apache-2.0
:disable_docs: true

:sources:
- chef-expander.rb
- chef-expander.service
- chef-expander.tmpfiles.d
- chef-expander.init
- chef-expander.logrotate

:patches:
  BNC-770427-commit-changes.patch: -p1

:preamble: |-
  %if 0%{?suse_version} >= 1230
  BuildRequires:  pkgconfig(systemd)
  %endif

  Requires:       logrotate
  BuildRequires:  fdupes
  %if 0%{?suse_version} > 1110
  Requires(pre):  pwdutils
  %else
  Requires(pre):  shadow-utils
  %endif
  PreReq:         rubygem(chef-expander) = %{version}
  #!BuildIgnore:  rubygem(chef-expander)

:main:
  :preamble: |-
    Requires:  rubygem-chef-expander

:post_install: |-
  install -d -m 755 %{buildroot}%{_sysconfdir}/logrotate.d
  install -D -m 644 %{SOURCE5} %{buildroot}%{_sysconfdir}/logrotate.d/chef-expander

  install -d -m 750 %{buildroot}%{_sysconfdir}/chef
  install -D -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/chef/expander.rb

  %if 0%{?suse_version} >= 1230
  install -D -m 644 %{SOURCE3} %{buildroot}/usr/lib/tmpfiles.d/chef-expander.conf
  install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/chef-expander.service

  install -d -m 755 %{buildroot}%{_sbindir}
  ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcchef-expander
  %else
  install -d -m 755 %{buildroot}%{_sysconfdir}/init.d
  install -D -m 750 %{SOURCE4} %{buildroot}%{_sysconfdir}/init.d/chef-expander

  install -d -m 755 %{buildroot}%{_sbindir}
  ln -s %{_sysconfdir}/init.d/chef-expander %{buildroot}%{_sbindir}/rcchef-expander
  %endif

  install -d -m 750 %{buildroot}%{_localstatedir}/log/chef
  install -d -m 750 %{buildroot}%{_localstatedir}/lib/chef
  install -d -m 750 %{buildroot}%{_localstatedir}/cache/chef
  %if 0%{?suse_version} < 1230
  install -d -m 750 %{buildroot}%{_localstatedir}/run/chef
  %endif

  rm -rf %{buildroot}%{gem_base}/gems/%{mod_full_name}/conf

  find %{buildroot} -name "*.orig" -delete -print
  %fdupes %{buildroot}

:scripts:
  :pre: |-
    getent group chef >/dev/null || groupadd -r chef
    getent passwd chef >/dev/null || useradd  -r -g chef -d %{_localstatedir}/lib/chef -s /sbin/nologin -c "Opscode chef daemon" chef

    %if 0%{?suse_version} >= 1230
    %service_add_pre chef-expander.service
    %endif

  :preun: |-
    %if 0%{?suse_version} >= 1230
    %service_del_preun chef-expander.service
    %else
    %stop_on_removal chef-expander
    %endif

  :post: |-
    %if 0%{?suse_version} >= 1230
    systemd-tmpfiles --create /usr/lib/tmpfiles.d/chef-expander.conf || true
    %service_add_post chef-expander.service
    %else
    %fillup_and_insserv chef-expander
    %endif

  :postun: |-
    %if 0%{?suse_version} >= 1230
    %service_del_postun chef-expander.service
    %else
    %restart_on_update chef-expander
    %insserv_cleanup
    %endif

:filelist: |-
  %dir %attr(0750, chef, chef) %{_localstatedir}/log/chef
  %dir %attr(0750, chef, chef) %{_localstatedir}/lib/chef
  %dir %attr(0750, chef, chef) %{_localstatedir}/cache/chef
  %if 0%{?suse_version} < 1230
  %ghost %attr(0750, chef, chef) %{_localstatedir}/run/chef
  %endif

  %if 0%{?suse_version} >= 1230
  /usr/lib/tmpfiles.d/chef-expander.conf
  %{_unitdir}/chef-expander.service
  %else
  %{_sysconfdir}/init.d/chef-expander
  %endif

  %{_sbindir}/rcchef-expander

  %dir %attr(0750, root, chef) %{_sysconfdir}/chef
  %config(noreplace) %attr(0640, root, chef) %{_sysconfdir}/chef/expander.rb

  %config %attr(0640, root, chef) %{_sysconfdir}/logrotate.d/chef-expander
