-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddgroup
executable file
·66 lines (49 loc) · 1.28 KB
/
addgroup
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl
#
# addgroup - utility to create users
#
# Copyright (c) Timo Kokkonen <[email protected]> 2000,2002.
#
require 5;
use Getopt::Long;
use Sauron::DB;
use Sauron::Util;
use Sauron::Sauron;
load_config();
GetOptions("help|h","name=s","group=s");
if ($opt_help || $opt_help > 0) {
print "syntax: $0 [--help] [--group=name] [--name=\"<groupname>\"]\n";
exit(0);
}
db_connect();
unless ($opt_group) {
print "Enter group name: ";
chomp ($opt_group = lc(<STDIN>));
$i=1;
}
fatal("Invalid groupname '$opt_group'!")
unless ($opt_group =~ /^[a-z0-9_\-]+$/);
undef @q;
db_query("SELECT id FROM user_groups WHERE name='$opt_group'",\@q);
fatal("Group allready exists!") if ($q[0][0] > 0);
unless ($opt_name) {
print "Enter group description: ";
chomp ($opt_name = <STDIN>);
$i=1;
}
if ($i) { # ask confirmation only in interactive session...
print "\t Groupname: $opt_group\n",
"\t Description: $opt_name\n",
"Add this group [y/n]?";
chomp ($t = <STDIN>);
unless ($t eq 'y' || $t eq 'Y') {
print "Group not added!\n";
exit(1);
}
}
$res=db_exec("INSERT INTO user_groups " .
"(name,comment) VALUES('$opt_group','$opt_name');");
fatal("Cannot add group: " . db_errormsg()) if ($res < 0);
print "Group $opt_group added succesfully.\n";
exit;
# eof :-)