-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate_groups.pl
More file actions
40 lines (35 loc) · 1.07 KB
/
populate_groups.pl
File metadata and controls
40 lines (35 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl
#
use warnings;
use strict;
use LinWin::Schema;
my $schema = LinWin::Schema->connect('dbi:SQLite:db/example.db');
while (<>) {
chomp;
# The following is for my groups file:
my ( $groupname, $gpassword, $gid, $members ) = split( /:/, $_ );
$schema->resultset('Group')->create(
{
GROUP_NAME => $groupname,
GID => $gid,
GROUP_DESC => $members
}
);
print "\n Group $groupname has the following members:" if ($members);
my @members = split( /,/, $members );
foreach (@members) {
#Just trying to debug what goes where
print $_ . " ";
# First, let's go and get the UID that we need to put in here:
my $user_rs = $schema->resultset('User')->search( { ENGID => $_ } );
my $user = $user_rs->first;
my $uid = $user->UID;
# Now we have to go and get the GID from
$schema->resultset('GroupMembership')->create(
{
USER_ID => $uid,
GROUP_ID => $gid
}
);
}
}