6151a28
#! /bin/bash
6151a28
6151a28
# Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
93ac5ce
#
6151a28
# This program is free software; you can redistribute it and/or modify
6151a28
# it under the terms of the GNU General Public License as published by
6151a28
# the Free Software Foundation; version 2 of the License.
93ac5ce
#
6151a28
# This program is distributed in the hope that it will be useful,
6151a28
# but WITHOUT ANY WARRANTY; without even the implied warranty of
6151a28
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6151a28
# GNU General Public License for more details.
93ac5ce
#
6151a28
# You should have received a copy of the GNU General Public License
6151a28
# along with this program; if not, write to the Free Software
6151a28
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
6151a28
6151a28
function showHelp()
6151a28
{
6151a28
    echo \
6151a28
$"Usage: clamd-gen --service=<SERVICE> --version=<VERSION> --release=<RELEASE>
93ac5ce
                 --license=<LICENSE> --username=>USERNAME>
6151a28
"
6151a28
    exit 0
6151a28
}
6151a28
6151a28
function rpm.generatePreamble()
6151a28
{
6151a28
    cat <
1ce8761
%{!?release_func:%define release_func()	%1%{?dist}}
6151a28
# The name of the minit service
6151a28
%define minitsvcdir	%minitdir/services/%name
6151a28
# The configuration file for the SysV initservice
6151a28
%define conffile	%_sysconfdir/clamd.d/%service.conf
6151a28
# The directory, where the milter socket will be placed into; this
6151a28
# socket will be named clamd.sock
6151a28
%define rundir		/var/run/clamd.%service
6151a28
# The name of the logfile
6151a28
%define logfile		/var/log/clamd.%service
6151a28
# The user under whose id, the clamd shall be running. This user must
6151a28
# be able to read the files from the base-service and is usually
6151a28
# created there.
6151a28
%define username	$USERNAME
6151a28
# The packagename of the service
6151a28
%define service		$SERVICE
6151a28
# The service name as used by the system's initscripts; usually this
6151a28
# is %service
6151a28
%define baseservice	%service
6151a28
6151a28
%define __chkconfig	/sbin/chkconfig
6151a28
%define minitdir	%_sysconfdir/minit
6151a28
6151a28
6151a28
EOF
6151a28
}
6151a28
6151a28
function rpm.generateHeader()
6151a28
{
6151a28
    cat <
6151a28
Summary:		Clamav server for '%service'
6151a28
Name:			clamd.%service
6151a28
Version:		$VERSION
6151a28
Release:		%release_func $RELEASE
6151a28
Epoch:			0
6151a28
License:		$LICENSE
6151a28
Group:			System Environment/Daemons
6151a28
BuildRoot:		%_tmppath/%name-%version-%release-root
6151a28
BuildArch:		noarch
6151a28
Requires:		init(%name)
6151a28
Requires(pre):		%service
6151a28
Requires:		clamav-server
6151a28
BuildRequires:		clamav-devel
6151a28
6151a28
%package sysv
6151a28
Summary:		SysV initscripts for a %service clamav-server
6151a28
Group:			System Environment/Daemons
6151a28
Provides:		init(%name) = sysv
6151a28
Conflicts:		init(%name) < sysv
6151a28
Conflicts:		init(%name) > sysv
cbeb9f1
Requires:		clamav-server-sysv
6151a28
Requires(post):		%name = %epoch:%version-%release
6151a28
Requires(post):		diffutils mktemp %__chkconfig
6151a28
Requires(preun):	%__chkconfig
6151a28
Requires(pre):		%_initrddir
6151a28
Requires(postun):	%_initrddir
6151a28
6151a28
%package minit
6151a28
Summary:		minit initscripts for a %service clamav-server
6151a28
Group:			System Environment/Daemons
6151a28
Provides:		init(%name) = minit
6151a28
Conflicts:		init(%name) < minit
6151a28
Conflicts:		init(%name) > minit
6151a28
Requires(post):		%name = %epoch:%version-%release
6151a28
Requires(post):		diffutils mktemp
6151a28
Requires(pre):		minit-setup
6151a28
Requires(postun):	minit-setup
6151a28
Requires(triggers):	minit-tools
6151a28
6151a28
6151a28
%description
6151a28
Basic setup for a clamav server for '%service'.
6151a28
6151a28
6151a28
%description sysv
6151a28
Basic setup for a clamav server for '%service'.
6151a28
6151a28
This package contains initscripts for SysV based systems.
6151a28
6151a28
6151a28
%description minit
6151a28
Basic setup for a clamav server for '%service'.
6151a28
6151a28
This package contains initscripts for minit based systems.
6151a28
6151a28
EOF
6151a28
}
6151a28
6151a28
6151a28
function rpm.genBody()
6151a28
{
6151a28
    cat <<"XEOFX"
6151a28
%prep
6151a28
%build
6151a28
6151a28
%install
6151a28
rm -rf $RPM_BUILD_ROOT
6151a28
%__install -d -m755 $RPM_BUILD_ROOT{%minitsvcdir,%_sbindir,%rundir,/var/log}
6151a28
6151a28
d=/usr/share/clamav/template
6151a28
6151a28
function subst
6151a28
{
6151a28
	src=$d/$1
6151a28
	dst=$RPM_BUILD_ROOT$2
6151a28
6151a28
	%__install -d -m755 $(dirname "$dst")
6151a28
	sed -e 's!^\(#?LogFile \).*!\1%logfile!g;
6151a28
		s!^#?\(LocalSocket \).*!\1%rundir/clamd.sock!g;
6151a28
		s!^#?\(PidFile \).*!\1%rundir/clamd.pid!g;
6151a28
		s!<SERVICE>!%service!g;
6151a28
		s!<USER>!%username!g;' "$src" >"$dst"
6151a28
	chmod --reference "$src" "$dst"
6151a28
}
6151a28
6151a28
subst clamd.conf      %conffile
6151a28
subst clamd.logrotate %_sysconfdir/logrotate.d/clamd.%service
6151a28
6151a28
%if 0%{!?_without_sysv:1}
6151a28
subst clamd.sysconfig %_sysconfdir/sysconfig/clamd.%service
6151a28
subst clamd.init      %_initrddir/clamd.%service
6151a28
%endif
6151a28
6151a28
ln -s clamd $RPM_BUILD_ROOT%_sbindir/clamd.%service
6151a28
6151a28
touch $RPM_BUILD_ROOT%logfile
6151a28
touch $RPM_BUILD_ROOT%rundir/clamd.sock
6151a28
6151a28
%if 0%{!?_without_minit:1}
6151a28
ln -s %_sbindir/clamd.%service $RPM_BUILD_ROOT%minitsvcdir/run
6151a28
touch                          $RPM_BUILD_ROOT%minitsvcdir/respawn
6151a28
cat <<EOF                     >$RPM_BUILD_ROOT%minitsvcdir/params
6151a28
-c
6151a28
%conffile
6151a28
EOF
6151a28
%endif
6151a28
6151a28
%clean
6151a28
rm -rf $RPM_BUILD_ROOT
6151a28
6151a28
6151a28
%triggerin minit -- %baseservice
6151a28
minit-svc add services/clamd.%service services/%baseservice/
6151a28
6151a28
%triggerun minit -- %baseservice
6151a28
test "$1" != 0 -a "$2" != 0 || \
6151a28
	minit-svc del services/clamd.%service services/%baseservice/
6151a28
6151a28
6151a28
%post minit
6151a28
d=$(mktemp /tmp/clamd.%service.XXXXXX)
6151a28
sed -e 's!^#Foreground!Foreground!' "%conffile" >"$d"
6151a28
grep -q '^Foreground' $d || echo 'Foreground' >>$d
6151a28
cmp -s "$d" %conffile || cat "$d" >"%conffile"
6151a28
rm -f "$d"
6151a28
6151a28
%post sysv
6151a28
d=$(mktemp /tmp/clamd.%service.XXXXXX)
6151a28
sed -e 's!^Foreground!#Foreground!' "%conffile" >"$d"
6151a28
cmp -s "$d" %conffile || cat "$d" >"%conffile"
6151a28
rm -f "$d"
6151a28
6151a28
%__chkconfig --add %name
6151a28
6151a28
6151a28
%preun sysv
6151a28
test "$1" != 0 || %__chkconfig --del %name
6151a28
6151a28
XEOFX
6151a28
}
6151a28
6151a28
6151a28
function rpm.genFiles
6151a28
{
6151a28
    cat <<"EOF"
6151a28
%files
6151a28
%defattr(-,root,root,-)
6151a28
%doc
6151a28
%config(noreplace) %verify(not size md5 mtime) %attr(0620,root,%username)  %logfile
6151a28
%config(noreplace) %verify(not mtime) %conffile
6151a28
%config(noreplace) %verify(not mtime) %_sysconfdir/logrotate.d/clamd.%service
6151a28
%_sbindir/clamd.%service
6151a28
%dir %attr(0700,%username,root) %rundir
6151a28
%ghost %rundir/clamd.sock
6151a28
6151a28
6151a28
%if 0%{!?_without_sysv:1}
6151a28
%files sysv
6151a28
%defattr(-,root,root,-)
6151a28
%config            %verify(not mtime) %_initrddir/clamd.%service
6151a28
%config(noreplace) %verify(not mtime) %_sysconfdir/sysconfig/clamd.%service
6151a28
%endif
6151a28
6151a28
6151a28
%if 0%{!?_without_minit:1}
6151a28
%files minit
6151a28
%defattr(-,root,root,-)
6151a28
%dir                                  %minitsvcdir
6151a28
%config(noreplace) %verify(not mtime) %minitsvcdir/params
6151a28
%config                               %minitsvcdir/run
93ac5ce
				      %minitsvcdir/respawn
6151a28
%endif
6151a28
EOF
6151a28
}
6151a28
6151a28
6151a28
SERVICE=
6151a28
VERSION=
6151a28
RELEASE=
6151a28
LICENSE=
6151a28
USERNAME=
6151a28
tmp=$(getopt -o '' --long service:,version:,release:,license:,username:,help -n "$0" -- "$@") || exit 1
6151a28
eval set -- "$tmp"
6151a28
6151a28
while true; do
6151a28
    case "$1" in
6151a28
	(--help)	showHelp $0;;
6151a28
	(--service)	SERVICE=$2;  shift;;
6151a28
	(--version)	VERSION=$2;  shift;;
6151a28
	(--release)	RELEASE=$2;  shift;;
6151a28
	(--license)	LICENSE=$2;  shift;;
6151a28
	(--username)	USERNAME=$2; shift;;
6151a28
	(--)		shift; break;;
6151a28
    esac
6151a28
    shift
6151a28
done
6151a28
6151a28
for i in SERVICE VERSION RELEASE LICENSE USERNAME; do
6151a28
    eval tmp=\$${i}
6151a28
    test "$tmp" || {
6151a28
	echo $"No value for $i specified; assuming @${i}@"  >&2;
6151a28
	eval $i=@${i}@;
6151a28
    }
6151a28
done
6151a28
6151a28
6151a28
rpm.generatePreamble
6151a28
rpm.generateHeader
6151a28
rpm.genBody
6151a28
rpm.genFiles