# SliTaz package receipt.

PACKAGE="slim-pam"
VERSION="1.3.6"
CATEGORY="x-window"
SHORT_DESC="Desktop-independent graphical login manager for X11 (PAM enabled)."
MAINTAINER="pascal.bellard@slitaz.org"
LICENSE="GPL2"
WEB_SITE="https://www.berlios.de/software/slim/"
REPOLOGY="slim-login-manager"

SOURCE="slim"
TARBALL="$SOURCE-$VERSION.tar.gz"
WGET_URL="https://github.com/iwamatsu/$SOURCE/archive/refs/tags/v$VERSION.tar.gz"

PROVIDE="slim:pam"
RELATED="slim slim-theme-default"
SUGGESTED="slim-theme-default slitaz-configs"
DEPENDS="gcc-lib-base libjpeg libpng pam xorg-libXft xorg-libXmu"
BUILD_DEPENDS="cmake freetype-dev jpeg-dev libpng-dev pam-dev xorg-libXft-dev
	xorg-libXmu-dev"

CONFIG_FILES="/etc/slim.conf"

# What is the latest version available today?
current_version()
{
	wget -O - https://sourceforge.net/projects/slim.berlios/files/ 2>/dev/null | \
	sed '/scope="row/!d;/slim-/!d;s|.*/slim-||;s|.tar.*||;q'
}

# Rules to configure and make the package.
compile_rules()
{
	patch --input=$WOK/$SOURCE/stuff/patches/app.cpp-$VERSION || return 1
	patch --input=$WOK/$SOURCE/stuff/patches/cfg.cpp-$VERSION || return 1
	patch --input=$WOK/$SOURCE/stuff/patches/slim.conf-$VERSION || return 1

	mkdir	_build &&
	cd	_build &&
	cmake	..					\
		-D CMAKE_INSTALL_PREFIX=/usr		\
		-D X11_Xmu_LIB=-lXmu			\
		-D USE_PAM=yes &&
	make &&
	make install DESTDIR=$DESTDIR
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr/share/slim

	cp -a $install/etc		$fs
	cp -a $install/usr/bin		$fs/usr
	cp -a $install/usr/lib		$fs/usr
	cp -a $WOK/$SOURCE/stuff/themes	$fs/usr/share/slim

	# rc script.
	cp -a $WOK/$SOURCE/stuff/etc	$fs
	chown -R root.root		$fs

	# slim-theme manager
	install -m755 $WOK/$SOURCE/stuff/slim-theme $fs/usr/bin/slim-theme
}

post_install()
{
	# replace default user tux by user with userid 1000 in slim.conf
	local USER
	USER=$(awk -F: '/:1000:1000:/ { print $1 }' < "$1/etc/passwd")
	[ -n "$USER" ] &&
	sed -i s/"default_user .*"/"default_user        $USER"/ "$1/etc/slim.conf"

	# In order to update the SLiM, we need to restart it.
	# We can't just "/etc/init.d/slim restart" because it momentarily interrupts
	# X session and the user will get a terrible console with strange letters.
	printf '\n%40s\n' | tr ' ' '='
	echo "In order to update the SLiM,"
	echo "please, reboot your system!"
}

pre_remove()
{
	tazpkg get-install  ${PACKAGE%-pam}
}

testsuite()
{
	readelf -h	$install/usr/bin/slim
}