#!/usr/bin/perl
#
# wrapper script to work around bug 908798
# https://bugzilla.opensuse.org/show_bug.cgi?id=908798
# -- never add pam_systemd to the config unless pam-config
#    is called interactively
# hack alert: the fact that this  script is called interactively is
# determined by STDIN being a terminal, this might not be always true
#
# (C) 2014 Stefan Seyfried
# License: WTFPL v2
#
use strict;
use warnings;

use POSIX('isatty');
my $manual = isatty('STDIN');
my $bin = $0 . ".bin";

if (! $manual) {
	my $add = 0;
	my $systemd = 0;
	foreach my $elem (@ARGV) {
		$add = 1 if $elem eq "-a";
		$add = 1 if $elem eq "--add";
		$systemd = 1 if $elem eq "--systemd";
	}
	if ($add && $systemd) {
		print STDERR "pam-config: not adding pam_systemd, not called from a terminal\n";
		exit 0;
	}
}

exec $bin, @ARGV;
exit 1;
