# Build a Debian package that adds guest-account functionality to LightDM.
#
# For guest accounts to work LightDM needs a binary "guest-account" which it
# will run to create / destroy guest accounts.[0]  The default Debian package
# does not provide one.[1] However, the Ubuntu package does.[2]
#
# The simple way to use this script is simply to call `make install`. This will
# fetch the Ubuntu package, unpack it and install only the files that are
# relevant for guest accounts.  However, this is strongly discouraged because
# it bypasses the package system.
#
# The recommended way to use this script is to call `make`. This will use
# checkinstall[3] to create a Debian package that does exactly the same as
# `make install`.
#
# NOTE: This script will create some temporary files. It is recommended to run
# it in an otherwise empty directory to avoid pollution.
#
# [0]: https://lists.freedesktop.org/archives/lightdm/2014-July/000631.html
# [1]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=661230
# [2]: http://packages.ubuntu.com/xenial/lightdm
# [4]: https://wiki.debian.org/CheckInstall
# http://de.archive.ubuntu.com/ubuntu/pool/universe/l/lightdm/lightdm_1.30.0-0ubuntu1_amd64.deb

PREFIX := /
VERSION := 1.30.0-0ubuntu1
ARCH := amd64

checkinstall:
	checkinstall --install=no -y --pkgname=guest-account --pkgversion=$(VERSION) --pkgarch=all --pkgsource=lightdm

install: tmp tmp/install.sh
	cd tmp && ./install.sh usr/sbin/guest-account
	cd tmp && ./install.sh usr/lib/lightdm/guest-session-auto.sh
	cd tmp && ./install.sh usr/share/lightdm/guest-session/setup.sh
	cd tmp && ./install.sh usr/share/lightdm/guest-session/skel/.config/autostart/guest-session-startup.desktop
#	cd tmp && ./install.sh etc/apparmor.d/lightdm-guest-session

tmp/install.sh: tmp
	echo '#!/bin/sh\nmkdir -p "$(PREFIX)$$(dirname $$1)"\ncp --preserve=mode "$$1" "$(PREFIX)$$1"' > $@
	chmod +x $@

tmp:
	mkdir -p tmp/
	cd tmp && wget http://de.archive.ubuntu.com/ubuntu/pool/universe/l/lightdm/lightdm_$(VERSION)_$(ARCH).deb -O source.deb
	cd tmp && unp source.deb
	cd tmp && unp data.tar.xz

clean:
	rm -rf tmp
	rm -f description-pak
	rm -f backup-*.tgz
