# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../shadow/shadow.conf
# Copyright (C) 2006 - 2009 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

if pkginstalled libselinux; then
	var_append GCC_WRAPPER_APPEND ' ' '-lselinux'
else
	var_append confopt ' ' "--without-selinux"
fi

# Disable the installation of the groups program and its man pages,
# as Coreutils provides a better version
disable_groups() {
	echo_status "Disabling groups command..."
	echo_status "Using groups command provided by coreutils..."
	sed 's/groups$(EXEEXT) //' -i.orig src/Makefile
	find man -name Makefile -exec sed '/groups/d' -i.orig '{}' \;
}
hook_add premake 3 "disable_groups"

pm_shadow() {
	cp -fv etc/limits etc/login.access $root/etc/
	cp -fv $confdir/login.defs $root/etc/login.defs
	touch $root/var/log/lastlog $root/var/log/faillog
	mv $root/usr/bin/{login,su} $root/bin/

	if [ -e $root/etc/pam.d ]; then
		if pkginstalled libselinux; then
	 		cp etc/pam.d/[a-z]* $root/etc/pam.d/
		else
			for i in etc/pam.d/[a-z]*; do
				sed 's,\(.*selinux.*\),#\1,g' < $i > $root/$i
			done
		fi

		[ -f $root/etc/pam.d/login ] && \
			sed -i 's,\(.*loginuid.*\),#\1,g' $root/etc/pam.d/login
	fi

	mkdir -p $root/etc/default
	echo 'SHELL=/bin/bash' > $root/etc/default/useradd
}

hook_add postmake 5 "pm_shadow"

confopt="$confopt --enable-shared --disable-desrpc"

if ! atstage native; then
	libdir="/${libdir##*/}"
else
	libdir="$root/${libdir##*/}"
fi