source: fedkit/rc.fedaccounts @ 5ae9d94

compt_changes
Last change on this file since 5ae9d94 was 5ae9d94, checked in by Ted Faber <faber@…>, 13 years ago

Get remote mounting working on linux

  • Property mode set to 100755
File size: 2.7 KB
Line 
1#!/usr/bin/perl -w
2#
3use English;
4use Getopt::Std;
5use strict;
6
7use IO::File;
8
9# Drag in path stuff so we can find emulab stuff.
10BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
11
12# Only root.
13if ($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#
22my $PASSDB   = "$VARDIR/db/passdb";
23my $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#
29use libsetup;
30use liblocsetup;
31use libtmcc;
32use 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
40my $old_accts = "/usr/local/federation/etc/old_accts";
41my $accts = "/usr/local/federation/etc/userconf";
42
43fatal("Need both $old_accts and $accts") unless -e $old_accts && -e $accts;
44
45my $old = new IO::File $old_accts;
46my $n = new IO::File $accts;
47
48fatal("Cannot open $old_accts for reading") unless $old;
49fatal("Cannot open $accts for reading") unless $n;
50
51my @delgroups;
52my @delusers;
53
54while (<$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
67foreach my $u (@delusers) {
68    # Can't delete a user who's logged in.  Log 'em out.
69    system('/usr/bin/pkill', '-u', $u) if (-x '/usr/bin/pkill');
70    print "Deleting user $u\n";
71    os_userdel($u);
72}
73
74foreach my $g (@delgroups) {
75    print "Deleting group $g\n";
76    os_groupdel($g);
77}
78
79while (<$n>) {
80    /^ADDGROUP NAME=([-\w]+)\s+GID=(\d+)/ && do {
81        my ($group, $gid) = ($1, $2);
82        print "Adding group $group($gid)\n";
83        os_groupadd($group, $gid);
84    };
85    /^ADDUSER\s+/ && do { 
86        my $login;
87        my $pswd;
88        my $uid;
89        my $gid;
90        my $root;
91        my $name;
92        my $hdir;
93        my $glist;
94        my $serial;
95        my $email;
96        my $shell;
97
98        /LOGIN=([\S]+)/ && do { $login = $1; }; 
99        /PSWD=(\S+)/ && do { $pswd=$1; } ;
100        /UID=(\d+)/ && do { $uid = $1; };
101        /GID=(\d+)/ && do { $gid = $1; };
102        /ROOT=(\d)/ && do { $root = $1; }; 
103        /NAME="([^"]*)"/ && do { $name = $1; };
104        /HOMEDIR=(\S+)/ && do { $hdir = $1; };
105        /GLIST="([^"]*)"/ && do { $glist = $1; }; 
106        /SERIAL=(\d+)/ && do { $serial = $1; };
107        /EMAIL="([^"]*)"/ && do { $email=$1; };
108        /SHELL=(\S+)/ && do { $shell = $1; };
109
110        print "Adding $login $uid $gid\n";
111        os_useradd($login, $uid, $gid, $pswd, "$glist", $hdir, $name, 
112            $root, $shell);
113        os_mkdir($hdir, "0755") unless -e $hdir;
114        next;
115    };
116}
117$n->close();
118
Note: See TracBrowser for help on using the repository browser.