%define puppet_groupid 65432
%define puppet_userid  65432

Name:          puppet
Version:       4.7.0
Release:       1mamba
Summary:       An automated administrative engine for your Linux, Unix, and Windows systems
Group:         System/Management
Vendor:        openmamba
Distribution:  openmamba
Packager:      Silvan Calarco <silvan.calarco@mambasoft.it>
URL:           http://puppetlabs.com/
Source:        https://rubygems.org/downloads/puppet-%{version}.gem
License:       Apache License 2.0
## AUTOBUILDREQ-BEGIN
## AUTOBUILDREQ-END
BuildRequires: ruby
Requires:      ruby
Requires:      ruby-facter
Requires:      ruby-hiera
Requires:      ruby-json_pure
Requires:      ruby-rgen
Requires(pre): pwdutils
BuildRoot:     %{_tmppath}/%{name}-%{version}-root

%description
Puppet, an automated administrative engine for your Linux, Unix, and Windows systems, performs
administrative tasks (such as adding users, installing packages, and updating server
configurations) based on a centralized specification.

%prep
%setup -q -c

%build

%install
[ "%{buildroot}" != / ] && rm -rf "%{buildroot}"
gemdir="$(ruby -rubygems -e'puts Gem.default_dir')"

gem install --no-user-install --ignore-dependencies -i "%{buildroot}$gemdir" \
  --no-ri --no-rdoc -n "%{buildroot}/usr/bin" "%{SOURCE0}"

# Set up vim and emacs
install -Dp -m0644 \
   %{buildroot}${gemdir}/gems/puppet-%{version}/ext/vim/ftdetect/puppet.vim \
   %{buildroot}%{_datadir}/vim/vimfiles/ftdetect/puppet.vim
install -Dp -m0644 \
   %{buildroot}${gemdir}/gems/puppet-%{version}/ext/vim/syntax/puppet.vim \
   %{buildroot}%{_datadir}/vim/vimfiles/syntax/puppet.vim
install -Dp -m0644 \
   %{buildroot}${gemdir}/gems/puppet-%{version}/ext/emacs/puppet-mode.el \
   %{buildroot}%{_datadir}/emacs/site-lisp/puppet-mode.el
install -Dp -m0644 \
   %{buildroot}${gemdir}/gems/puppet-%{version}/ext/emacs/puppet-mode-init.el \
   %{buildroot}%{_datadir}/emacs/site-lisp/site-start.d/puppet-mode-init.el

# Configuration and rc scripts
install -Dm 644 \
   %{buildroot}${gemdir}/gems/puppet-%{version}/conf/puppet.conf \
   %{buildroot}%{_sysconfdir}/puppet/puppet.conf
install -Dm 644 \
   %{buildroot}${gemdir}/gems/puppet-%{version}/conf/fileserver.conf \
   %{buildroot}%{_sysconfdir}/puppet/fileserver.conf
install -Dm 644 \
   %{buildroot}${gemdir}/gems/puppet-%{version}/conf/auth.conf \
   %{buildroot}%{_sysconfdir}/puppet/auth.conf
#install -Dm 644 \
#   %{buildroot}${gemdir}/gems/puppet-%{version}/conf/tagmail.conf \
#   %{buildroot}%{_sysconfdir}/puppet/tagmail.conf

# Setup tmpfiles.d config
install -d %{buildroot}%{_libdir}/tmpfiles.d/
echo "D /run/puppet 0755 puppet puppet -" > %{buildroot}%{_libdir}/tmpfiles.d/puppet.conf

# Logrotate
install -Dm 644 \
   %{buildroot}${gemdir}/gems/puppet-%{version}/ext/redhat/logrotate \
   %{buildroot}%{_sysconfdir}/logrotate.d/puppet

# Systemd files
install -Dm 644 \
   %{buildroot}${gemdir}/gems/puppet-%{version}/ext/systemd/puppet.service \
   %{buildroot}/lib/systemd/system/puppet.service
#install -Dm 644 \
#   %{buildroot}${gemdir}/gems/puppet-%{version}/ext/systemd/puppetmaster.service \
#   %{buildroot}/lib/systemd/system/puppetmaster.service

# Create puppet homedir and hieradir
install -d %{buildroot}/var/lib/puppet

install -d %{buildroot}%{_mandir}
mv %{buildroot}${gemdir}/gems/puppet-%{version}/man/* %{buildroot}/usr/share/man

rm -rf \
   %{buildroot}${gemdir}/gems/puppet-%{version}/ext/{autotest,debian,freebsd,\
gentoo,osx,redhat,solaris,suse,windows}

rm -f %{buildroot}${gemdir}/cache/puppet-%{version}.gem

%clean
[ "%{buildroot}" != / ] && rm -rf "%{buildroot}"

%pre
if [ $1 -ge 1 ]; then
   groupadd puppet -g %{puppet_groupid} 2>/dev/null
   useradd -u %{puppet_userid} -c 'Puppet service' -d /dev/null -g puppet \
      -s /bin/false puppet 2>/dev/null
fi
:

%post
if [ $1 -ge 1 ]; then
   systemctl -q daemon-reload
fi
:

%preun
if [ $1 -eq 0 ]; then
   groupdel puppet 2>/dev/null
   userdel puppet 2>/dev/null
fi
:

%postun
if [ $1 -eq 0 ]; then
   systemctl -q daemon-reload
fi
:

%files
%defattr(-,root,root)
%dir %{_sysconfdir}/puppet
%config(noreplace) %{_sysconfdir}/puppet/auth.conf
%config(noreplace) %{_sysconfdir}/puppet/fileserver.conf
%config(noreplace) %{_sysconfdir}/puppet/puppet.conf
#%config(noreplace) %{_sysconfdir}/puppet/tagmail.conf
%{_sysconfdir}/logrotate.d/puppet
%{_bindir}/puppet
%{_libdir}/ruby/gems/*/specifications/puppet-%{version}.gemspec
%dir %{_libdir}/ruby/gems/*/gems/puppet-%{version}
%{_libdir}/ruby/gems/*/gems/puppet-%{version}/*
/lib/systemd/system/puppet.service
#/lib/systemd/system/puppetmaster.service
%{_libdir}/tmpfiles.d/puppet.conf
%{_datadir}/emacs/site-lisp/puppet-mode.el
%{_datadir}/emacs/site-lisp/site-start.d/puppet-mode-init.el
%{_datadir}/vim/vimfiles/ftdetect/puppet.vim
%{_datadir}/vim/vimfiles/syntax/puppet.vim
%{_mandir}/man5/puppet.conf.5*
%{_mandir}/man8/extlookup2hiera.8*
%{_mandir}/man8/puppet*.8*
%attr(0755,puppet,puppet) %dir /var/lib/puppet

%changelog
* Fri Sep 30 2016 Automatic Build System <autodist@mambasoft.it> 4.7.0-1mamba
- automatic version update by autodist

* Thu Sep 08 2016 Automatic Build System <autodist@mambasoft.it> 4.6.2-1mamba
- automatic version update by autodist

* Fri Sep 02 2016 Automatic Build System <autodist@mambasoft.it> 4.6.1-1mamba
- automatic version update by autodist

* Sat Aug 20 2016 Automatic Build System <autodist@mambasoft.it> 4.5.3-1mamba
- automatic version update by autodist

* Tue Dec 29 2015 Automatic Build System <autodist@mambasoft.it> 3.7.2-1mamba
- automatic update by autodist

* Sat Sep 06 2014 Automatic Build System <autodist@mambasoft.it> 3.7.0-1mamba
- automatic version update by autodist

* Tue Jul 15 2014 Automatic Build System <autodist@mambasoft.it> 3.6.2-1mamba
- automatic version update by autodist

* Wed Dec 11 2013 Silvan Calarco <silvan.calarco@mambasoft.it> 3.3.2-1mamba
- package created using the webbuild interface
