[adcbdaf] | 1 | #!/usr/bin/perl -w |
---|
| 2 | # |
---|
| 3 | use English; |
---|
| 4 | use Getopt::Std; |
---|
| 5 | use strict; |
---|
| 6 | |
---|
| 7 | use IO::File; |
---|
| 8 | |
---|
| 9 | # Drag in path stuff so we can find emulab stuff. |
---|
| 10 | BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; } |
---|
| 11 | |
---|
| 12 | # Only root. |
---|
| 13 | if ($EUID != 0) { |
---|
| 14 | die("*** $0:\n". |
---|
| 15 | " Must be root to run this script!\n"); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | # Script specific goo. |
---|
| 19 | # |
---|
| 20 | # These go in /var/emulab. Good for all environments! |
---|
| 21 | # |
---|
| 22 | my $PASSDB = "$VARDIR/db/passdb"; |
---|
| 23 | my $GROUPDB = "$VARDIR/db/groupdb"; |
---|
| 24 | |
---|
| 25 | # |
---|
| 26 | # Load the OS independent support library. It will load the OS dependent |
---|
| 27 | # library and initialize itself. |
---|
| 28 | # |
---|
| 29 | use libsetup; |
---|
| 30 | use liblocsetup; |
---|
| 31 | use libtmcc; |
---|
| 32 | use librc; |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | # The old accounts output will be in /usr/local/federation/etc/old_accts and |
---|
| 36 | # the new stuff in /usr/local/federation/etc/accts this is exactly the output |
---|
| 37 | # of tmcc accounts under the local (old) and federated (new) testbed. We |
---|
| 38 | # delete all the stuff from the old and add all the stuff from the new. |
---|
| 39 | |
---|
| 40 | my $old_accts = "/usr/local/federation/etc/old_accts"; |
---|
[c0a8738] | 41 | my $accts = "/usr/local/federation/etc/userconf"; |
---|
[adcbdaf] | 42 | |
---|
| 43 | fatal("Need both $old_accts and $accts") unless -e $old_accts && -e $accts; |
---|
| 44 | |
---|
| 45 | my $old = new IO::File $old_accts; |
---|
| 46 | my $n = new IO::File $accts; |
---|
| 47 | |
---|
| 48 | fatal("Cannot open $old_accts for reading") unless $old; |
---|
| 49 | fatal("Cannot open $accts for reading") unless $n; |
---|
| 50 | |
---|
| 51 | my @delgroups; |
---|
| 52 | my @delusers; |
---|
| 53 | |
---|
| 54 | while (<$old>) { |
---|
| 55 | /^ADDGROUP NAME=([-\w]+)\s+GID=(\d+)/ && do { |
---|
| 56 | push(@delgroups, $1); |
---|
| 57 | next; |
---|
| 58 | }; |
---|
| 59 | /^ADDUSER LOGIN=([-\w]+)/ && do { |
---|
| 60 | push(@delusers, $1); |
---|
| 61 | }; |
---|
| 62 | } |
---|
| 63 | $old->close(); |
---|
| 64 | |
---|
| 65 | # Now take 'em out |
---|
| 66 | |
---|
| 67 | foreach my $u (@delusers) { |
---|
| 68 | print "Deleting user $u\n"; |
---|
| 69 | os_userdel($u); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | foreach my $g (@delgroups) { |
---|
| 73 | print "Deleting group $g\n"; |
---|
| 74 | os_groupdel($g); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | while (<$n>) { |
---|
| 78 | /^ADDGROUP NAME=([-\w]+)\s+GID=(\d+)/ && do { |
---|
| 79 | my ($group, $gid) = ($1, $2); |
---|
| 80 | print "Adding group $group($gid)\n"; |
---|
| 81 | os_groupadd($group, $gid); |
---|
| 82 | }; |
---|
[c0a8738] | 83 | /^ADDUSER\s+/ && do { |
---|
| 84 | my $login; |
---|
| 85 | my $pswd; |
---|
| 86 | my $uid; |
---|
| 87 | my $gid; |
---|
| 88 | my $root; |
---|
| 89 | my $name; |
---|
| 90 | my $hdir; |
---|
| 91 | my $glist; |
---|
| 92 | my $serial; |
---|
| 93 | my $email; |
---|
| 94 | my $shell; |
---|
| 95 | |
---|
| 96 | /LOGIN=([\S]+)/ && do { $login = $1; }; |
---|
| 97 | /PSWD=(\S+)/ && do { $pswd=$1; } ; |
---|
| 98 | /UID=(\d+)/ && do { $uid = $1; }; |
---|
| 99 | /GID=(\d+)/ && do { $gid = $1; }; |
---|
| 100 | /ROOT=(\d)/ && do { $root = $1; }; |
---|
| 101 | /NAME="([^"]*)"/ && do { $name = $1; }; |
---|
| 102 | /HOMEDIR=(\S+)/ && do { $hdir = $1; }; |
---|
| 103 | /GLIST="([^"]*)"/ && do { $glist = $1; }; |
---|
| 104 | /SERIAL=(\d+)/ && do { $serial = $1; }; |
---|
| 105 | /EMAIL="([^"]*)"/ && do { $email=$1; }; |
---|
| 106 | /SHELL=(\S+)/ && do { $shell = $1; }; |
---|
| 107 | |
---|
| 108 | print "Adding $login $uid $gid\n"; |
---|
| 109 | os_useradd($login, $uid, $gid, $pswd, "$glist", $hdir, $name, |
---|
| 110 | $root, $shell); |
---|
| 111 | os_mkdir($hdir, "0755") unless -e $hdir; |
---|
| 112 | next; |
---|
[adcbdaf] | 113 | }; |
---|
| 114 | } |
---|
| 115 | $n->close(); |
---|
| 116 | |
---|