#!/opt/bin/perl ############################################################################### # # # Program to update user accounts based on template dir and passwd fragment # # # ############################################################################### # # # Version 1.2 - Written 06.02.96 by Steffen Beyer # # # ############################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ############################################################################### $version = 'version 1.2'; $self = $0; $self =~ s!^.*/!!; if (@ARGV != 2) { warn "\n"; warn "$self $version\n"; warn "\n"; warn "Usage: $self \n"; die "\n"; } $template = shift; $passwd = shift; unless (-d $template) { die "$self: can't find template directory '$template'!\n"; } unless ((-r $template) && (-w _) && (-x _)) { die "$self: can't read/write/exec template directory '$template'!\n"; } unless (-f $passwd) { die "$self: can't find passwd file '$passwd'!\n"; } unless (open(PASSWD, "<$passwd")) { die "$self: can't read passwd file '$passwd': $!\n"; } while () { ($user,$passwd,$uid,$gid,$name,$dir,$shell) = split(/:/); unless (-d $dir) { warn "$self: can't find home directory '$dir' of user '$user'!\n"; next; } $target = "$dir/.bashrc"; $skip = 0; if (-e $target) { $skip = 1; } $rc = (system("/g/sysadm/sun/bin/distrib -r $template $dir") >> 8); if ($rc) { warn "$self: error encountered while updating user '$user': $rc\n"; } $target = "$dir/.forward"; unless (-e $target) { if (open(TARGET, ">$target")) { print TARGET qq#"|IFS=' ' && exec /opt/bin/procmail user=$user"\n#; close(TARGET); chown($uid,$gid,$target); print "written '$target'\n"; } else { warn "$self: can't write file '$target': $!\n"; } } $source = "$template/.bashrc"; $target = "$dir/.bashrc"; next if $skip; unless (($group) = getgrgid($gid)) { warn "$self: can't resolve GID '$gid'!\n"; next; } unless (open(SOURCE, "<$source")) { warn "$self: can't read file '$source': $!\n"; next; } unless (open(TARGET, ">$target")) { warn "$self: can't write file '$target': $!\n"; next; } while () { s!^proj="template"!proj="$group"!; print TARGET; } close(SOURCE); close(TARGET); chown($uid,$gid,$target); print "updated '$target'\n"; } close(PASSWD); __END__