* Deactivate some color code from Pico (as standalone editor) until
[alpine.git] / contrib / utils / pwd2pine
blob49b3de6517ada08b25da1d7f65dca6aac1932389
1 #!/usr/local/bin/perl
3 # passwd2pine - translate passwd to pine addressbook
5 # Author: Paul J Murphy <pjm@dcs.ed.ac.uk>
7 # The fullname field will end up falling into one of the following cases:
9 # Last, First - A person
10 # }group: fullname - A non-person (determined by group or uid/gid < 1024)
11 # ~user: fullname - A non-person (determined by username or fullname)
13 # This allows the output to be sorted by fullname, with administrative
14 # accounts left to last (ie the real people come first).
16 # The comment field will contain the groupname of the user, followed by
17 # anything from the gecos field which seems to be a comment and not part
18 # of the name.
20 ### Start of configurable stuff
22 $domain = "dcs.ed.ac.uk";
24 # Regular expression for groups which don't contain people
25 # Case is significant.
26 # The expression must match the entire groupname string.
27 $non_people_groups = "local|misc|aliens|cs_dept|\\d*";
29 # Regular expression for users which are not people
30 # Case is significant.
31 # The expression must match the entire username string.
32 $non_people_users = ".*\\d.*";
34 # Regular expression for words within a fullname which signify a non-person
35 # Case is not significant.
36 # The expression must match an entire word within the gecos fullname.
37 $non_people_names = "account|admin|user|system|crew|test|dummy|\
38 unit|department|student|project|.*\\d.*";
40 ### End of configurable stuff
42 while(<>) {
43 chop;
44 ($user, $passwd, $uid, $gid, $gecos, $homedir, $shell) = split(/:/, $_, 7);
45 unless ($gr_name = getgrgid($gid)) {
46 $gr_name = $gid;
49 $nickname = $user;
51 $fullname = $gecos;
52 $fullname =~ s/,.*//g; # Reduce gecos to fullname
53 $fullname =~ s/[._]/ /g; # Translate alternate name separators to space
54 if ($uid < 1024 ||
55 $gid < 1024 ||
56 $gr_name =~ /^($non_people_groups)$/o) {
57 $fullname = "}$gr_name: $fullname";
58 } elsif ($user =~ /^($non_people_users)$/o ||
59 $fullname =~ /\b($non_people_names)\b/io) {
60 $fullname = "~$user: $fullname";
61 } elsif (($firstname, $lastname, $gecos_comment) =
62 ($fullname =~ /^(.*)[._ ]([^._ \d(][^._ \d]+)( *\(.*)?$/)) {
63 $fullname = "$lastname, $firstname";
66 $address = "$user\@$domain";
68 # $fcc = "";
70 $comment = "$gr_name$gecos_comment";
72 print "$nickname\t$fullname\t$address\t$fcc\t$comment\n";