#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
#

include /usr/share/cdbs/1/rules/debhelper.mk
include meta-subst.mk

# work around #262408
DEB_DH_INSTALL_SOURCEDIR := $(DEB_DESTDIR)

# Use SED script from our own source
DEB_META_SUBST__SED_SCRIPT := meta-subst.sed

BINDIR = $(DEB_DESTDIR)/usr/bin
SBINDIR = $(DEB_DESTDIR)/usr/sbin
LIBDIR = $(DEB_DESTDIR)/lib
DATADIR = $(DEB_DESTDIR)/usr/share
SYSCONFDIR = $(DEB_DESTDIR)/etc
CDBSLIBDIR = $(DATADIR)/cdbs/1/rules

PKGDATADIR = $(DATADIR)/elho
PKGLIBDIR = $(LIBDIR)/elho

common-install-indep::
	mkdir -p $(DEB_DESTDIR)
	install --directory $(BINDIR)
	install --directory $(SBINDIR)

	install --mode=755 apt-proxy-enable $(SBINDIR)
	install --mode=755 apt-proxy-disable $(SBINDIR)

	install --mode=755 debconf-get $(BINDIR)
	install --mode=755 debconf-fget $(BINDIR)
	install --mode=755 debconf-fset $(SBINDIR)
	install --mode=755 debconf-force-selections $(SBINDIR)

	install --mode=755 elho-install-sshkey $(BINDIR)

	install --directory $(PKGDATADIR)/ssh
	install --mode=644 ssh/id_rsa.pub $(PKGDATADIR)/ssh
	install --mode=644 ssh/id_rsa_root.pub $(PKGDATADIR)/ssh

	install --directory $(PKGLIBDIR)
	install --mode=755 addtogroup $(PKGLIBDIR)
	install --mode=755 customize-conffile $(PKGLIBDIR)
	install --mode=644 diff-pretty-print.sed $(PKGLIBDIR)
	install --mode=755 distmd5sum $(PKGLIBDIR)
	install --mode=644 invokeinitscript $(PKGLIBDIR)
	install --mode=644 meta-subst.sed $(PKGLIBDIR)
	install --mode=755 seed-exim4-hostnames $(PKGLIBDIR)
	install --directory $(CDBSLIBDIR)
	install --mode=644 meta-subst.mk $(CDBSLIBDIR)

	install --directory $(LIBDIR)/udev
	install --mode=755 udev/symlink-first $(LIBDIR)/udev

	install --directory $(SYSCONFDIR)/apt/apt.conf.d
	for f in 20-clean 20-norecommends 20-norecommends 20-proxy ; \
	do \
		install --mode=644 "etc/apt/apt.conf.d/$$f" \
			$(SYSCONFDIR)/apt/apt.conf.d ; \
	done

	install --directory $(SYSCONFDIR)/exim4/conf.d/acl
	install --directory $(SYSCONFDIR)/exim4/conf.d/main
	install --mode=644 etc/exim4/conf.d/acl/30_elho-base_check_vrfy \
		$(SYSCONFDIR)/exim4/conf.d/acl
	install --mode=644 etc/exim4/conf.d/main/01_elho-base_options \
		$(SYSCONFDIR)/exim4/conf.d/main
	install --mode=644 etc/exim4/conf.d/main/10_elho-base_options \
		$(SYSCONFDIR)/exim4/conf.d/main

	install --directory $(SYSCONFDIR)/ferm
	install --mode=644 etc/ferm/ferm.conf $(SYSCONFDIR)/ferm
	install --mode=644 etc/ferm/networks.ferm $(SYSCONFDIR)/ferm
	install --mode=644 etc/ferm/rules.ferm $(SYSCONFDIR)/ferm
	install --mode=644 etc/ferm/services.ferm $(SYSCONFDIR)/ferm

	install --directory $(SYSCONFDIR)/ssh
	install --mode=644 etc/ssh/ssh_known_hosts $(SYSCONFDIR)/ssh
	install --directory $(SYSCONFDIR)/sysctl.d
	for f in arp ip-redirects ip-sourcerouting ip-spoofing ipv6-autoconf \
		ipv6-dad sharedmemory ; \
	do \
		install --mode=644 --no-target-directory "etc/sysctl.d/$$f" \
			"$(SYSCONFDIR)/sysctl.d/$${f}.conf" ; \
	done
	install --directory $(SYSCONFDIR)/vim
	install --mode=644 etc/vim/vimrc.local $(SYSCONFDIR)/vim

	install --directory $(PKGDATADIR)/md5sums
	for f in ferm openssh-server ; \
	do \
		install --mode=644 "md5sums/$$f" $(PKGDATADIR)/md5sums ; \
	done
	install --directory $(PKGDATADIR)/customize
	install --directory $(PKGDATADIR)/customize/etc/apt
	install --mode=644 etc/apt/sources.list.sed \
		$(PKGDATADIR)/customize/etc/apt
	install --directory $(PKGDATADIR)/customize/etc/default
	for f in debsecan.sed ferm.sed grub.sed oidentd.sed tmpfs.sed ; \
	do \
		install --mode=644 "etc/default/$$f" \
			$(PKGDATADIR)/customize/etc/default ; \
	done
	install --directory $(PKGDATADIR)/customize/etc/ssh
	install --mode=644 etc/ssh/sshd_config.sed \
		$(PKGDATADIR)/customize/etc/ssh

	install --directory $(PKGDATADIR)/preseed
	for f in elho-base.cfg exim4-dns.cfg exim4-hostnames.cfg.in ; \
	do \
		install --mode=644 "preseed/$$f" $(PKGDATADIR)/preseed ; \
	done

	install --directory $(PKGDATADIR)/distfiles
	for d in etch lenny squeeze ; \
	do \
		install --directory "$(PKGDATADIR)/distfiles/$${d}" ; \
		for f in ferm.conf sshd_config sudoers ; \
		do \
			install --mode=644 "distfiles/$${d}/$${f}" \
				"$(PKGDATADIR)/distfiles/$${d}" ; \
		done \
	done
