summaryrefslogtreecommitdiff
path: root/localuserinfo
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2007-02-07 11:33:53 +0000
committerJonas Smedegaard <dr@jones.dk>2007-02-07 11:33:53 +0000
commit86a8562dab77fa08d2ea0413775ab7212beca001 (patch)
tree62e3fc9b67c93965f8426caac40740e8bf3a7b67 /localuserinfo
parenta73a1ebdb681a1815bd3cc87953626c9c590fdc3 (diff)
Adopts stuff from adduser script: Use getopts, add copyright info, add usage info. Add version info extracted from CVS id.
Diffstat (limited to 'localuserinfo')
-rwxr-xr-xlocaluserinfo93
1 files changed, 85 insertions, 8 deletions
diff --git a/localuserinfo b/localuserinfo
index 52d3a53..8f01e0f 100755
--- a/localuserinfo
+++ b/localuserinfo
@@ -1,20 +1,71 @@
#!/usr/bin/perl -wT
+our $ID = q$Id: localuserinfo,v 1.3 2007-02-07 11:33:53 jonas Exp $;
#
-# /usr/local/bin/localuserinfo
+# localuserinfo -- List fullname for each user
+#
+# Written by Jonas Smedegaard <dr@jones.dk>
# Copyright 2003-2007 Jonas Smedegaard <dr@jones.dk>
#
-# $Id: localuserinfo,v 1.2 2007-02-07 10:23:08 jonas Exp $
+# 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; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# Print real name and/or other info for user
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
-# TODO: Options to print other info than realname
+# TODO: Options to print other info than fullname
#
use strict;
+use Getopt::Long;
use User::pwent;
use User::grent;
+our $verbose = 1; # should we be verbose?
+my $ignore_badname = 0; # should we ignore bad names?
+
+our @names;
+
+# Resolve version number from CVS id
+our $version = join (' ', (split (' ', $ID))[1..3]);
+$version =~ s/,v\b//;
+$version =~ s/(\S+)$/($1)/;
+
+# Parse options, sanity checks
+unless (
+ GetOptions (
+ "quiet|q" => sub { $verbose = 0 },
+ "ignore-badname" => \$ignore_badname,
+ "help|h" => sub { &usage(); exit 0 },
+ "version|v" => sub { &version(); exit 0 },
+ "debug" => sub { $verbose = 2 }
+ )
+) {
+ &usage();
+ exit 1;
+}
+
+while (defined(my $arg = shift(@ARGV))) {
+ push (@names, $arg);
+}
+
+# TODO: Rewrite to batch-resolve userinfo for all users before using any
+while (my $username = shift @names) {
+
+ my ($fullname, @addresses) = &getuserinfo($username);
+ my $localaddress = "$username\@users.kaospilot.no";
+
+ print "$fullname\n";
+}
+
sub getuserinfo($) {
my $username = shift;
@@ -29,10 +80,36 @@ sub getuserinfo($) {
return ($fullname, @addresshints);
}
-while (my $username = shift @ARGV) {
+sub version {
+ printf ("localuserinfo version %s\n\n", $version);
+ print <<'EOF';
+List fullname for each user.
- my ($fullname, @addresses) = getuserinfo($username);
- my $localaddress = "$username\@users.kaospilot.no";
+Copyright (C) 2003-2007 Jonas Smedegaard <dr@jones.dk>
- print "$fullname\n";
+EOF
+ print <<'EOF';
+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; either version 2 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License, /usr/share/common-licenses/GPL, for more details.
+EOF
+}
+
+sub usage {
+ printf <<"EOF";
+localuserinfo USER [USER...]
+ List fullname 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
+ --version | -v version number and copyright
+EOF
}