diff options
author | Jonas Smedegaard <dr@jones.dk> | 2007-02-07 13:09:10 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2007-02-07 13:09:10 +0000 |
commit | f3fc925e3ac2e8faac63a37d96f516642243e66a (patch) | |
tree | 212c3fbce62e7d66caa11eea2ea9eafe65505538 /localuserinfo | |
parent | 42db407188c9a5700dc643a9cbc41962c925c605 (diff) |
Implement --mail support.
Diffstat (limited to 'localuserinfo')
-rwxr-xr-x | localuserinfo | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/localuserinfo b/localuserinfo index 2c13ec6..1773802 100755 --- a/localuserinfo +++ b/localuserinfo @@ -1,5 +1,5 @@ #!/usr/bin/perl -wT -my $ID = q$Id: localuserinfo,v 1.4 2007-02-07 11:43:34 jonas Exp $; +my $ID = q$Id: localuserinfo,v 1.5 2007-02-07 13:09:10 jonas Exp $; # # localuserinfo -- List fullname for each user # @@ -31,6 +31,10 @@ use User::grent; our $verbose = 1; # should we be verbose? my $ignore_badname = 0; # should we ignore bad names? +my $include_fullname = 1; +my $include_mail = 1; +our $custom_string; +my $use_custom_string = 0; our @names; @@ -39,10 +43,16 @@ my $version = join (' ', (split (' ', $ID))[1..3]); $version =~ s/,v\b//; $version =~ s/(\S+)$/($1)/; +our $maildomain_path = '/etc/mailname'; +our $maildomain = &get_maildomain; + # Parse options, sanity checks unless ( GetOptions ( "quiet|q" => sub { $verbose = 0 }, + "fullname|n" => \$include_fullname, + "mail|m" => \$include_mail, + "custom" => \$use_custom_string, "ignore-badname" => \$ignore_badname, "help|h" => sub { &usage(); exit 0 }, "version|v" => sub { &version(); exit 0 }, @@ -60,10 +70,21 @@ while (defined(my $arg = shift(@ARGV))) { # TODO: Rewrite to batch-resolve userinfo for all users before using any while (my $username = shift @names) { + my $string; + my ($fullname, @addresses) = &getuserinfo($username); - my $localaddress = "$username\@users.kaospilot.no"; - print "$fullname\n"; + if (defined($custom_string)) { + die "Use of custom string not yet implemented!"; + } else { + my @output; + push (@output, $fullname) if (defined($include_fullname)); + push (@output, "$username\@$maildomain") if (defined($include_mail)); + $string = join(' ', @output); + } + + + print "$string\n"; } sub getuserinfo($) { @@ -80,10 +101,22 @@ sub getuserinfo($) { return ($fullname, @addresshints); } +sub get_maildomain { + open (MAILDOMAINFILE, "<" . $maildomain_path) || die "can’t open $maildomain_path: $!"; + my $string = readline(MAILDOMAINFILE) || die "can’t read $maildomain_path: $!"; + close (MAILDOMAINFILE); + + chomp($string); + + # FIXME: Do some sanity check of the string - ensure a single word, FQDN syntax etc. + + return $string; +} + sub version { printf ("localuserinfo version %s\n\n", $version); print <<'EOF'; -List fullname for each user. +List fullname and/or other info for each user. Copyright (C) 2003-2007 Jonas Smedegaard <dr@jones.dk> @@ -104,12 +137,14 @@ EOF sub usage { printf <<"EOF"; localuserinfo USER [USER...] - List fullname for each user + List fullname and/or other info for each user general options: --quiet | -q don't give process information to stdout --ingore-badname ignore non-existing usernames instead of failing --help | -h usage message + --fullname | -n include fullname (enabled by default) + --mail | -m include email address --version | -v version number and copyright EOF } |