#!/usr/bin/perl
#converts /etc/passwd to EDUML  (c) 1999 Bruno Vernier GPL

BEGIN {}

chomp($hostname = `hostname -f`);

print qq@
<eduml> 
 <school school_id="$ARGV[0]" 
         school_url="http://$hostname"
	 school_icon="rec.gif"
	 school_org="$hostname school"
	 >  
  <people>\n@;
open(FILE,"/etc/passwd");
open(SHAD,"/etc/shadow");
open(GROUP,"/etc/group");

while (<SHAD>) { 
  ($login,$pw,$other) = split (":");

  $shadow{$login} = $pw;
}

while (<GROUP>) { 
  ($gid,$pw,$members) = split (":");

  $members{$gid} = $members;
}

while (<FILE>) {
  ($login,$pw,$uid,$gid,$fullname,$path) = split (":");
  ($name,$grade,$other) = split("\,",$fullname);
  $namegrade{$login} = $grade;
  $gid{$login} = $gid;
  $other{$login} = $other;
  $name =~ /^(.*)\s?(.*)?\s(.*)$/;
  ($given,$middle,$family) = ($1,$2,$3);
  $given=qq@middle="$middle"@ if $middle ;
  print qq'   <person login="$login" given="$given" $middle family="$family" password="$shadow{$login}">\n'  if $uid >999;
  print qq'    <status type="student" />\n' if $gid >1995 and $uid > 999;
  print qq'    <status type="teacher" />\n' if $gid == 50 and $uid > 999;
  print qq'    <contact>\n' if $uid >999;
  print qq'     <email email="$login\@$hostname" />\n' if $uid >999;
  print qq'     <url url="http://$hostname/~$login" />\n' if $uid >999;
  print qq'    </contact>\n' if $uid >999;
  print qq'   </person>\n' if $uid >999;
}

print       "  </people>\n";

END { 
  foreach $key (keys %namegrade) {
    print qq'  <course login="$key" course="$namegrade{$key}" />\n' if $namegrade{$key} ;
  };
  print   qq'  <groups>\n';  
  foreach $key (keys %gid) {
    print qq'   <group member="$key" gid="$gid{$key}" />\n' if $gid{$key} ;
  };
  print   qq'  </groups>\n';  
  print     " </school>
</eduml>\n";

}
