Skip to content

Commit c1a2fcc

Browse files
committed
add script
1 parent 4beda18 commit c1a2fcc

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,8 @@ repos:
6565
entry: ./test/assert-no-die-exit.bash
6666
language: system
6767
files: \.php$
68-
exclude: resources/lib/UnitySite\.php$
68+
exclude: |
69+
(?x)^(
70+
resources/lib/UnitySite\.php$|
71+
workers/.*|
72+
)$
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
require_once __DIR__ . "/../resources/autoload.php";
4+
use UnityWebPortal\lib\UnityUser;
5+
use UnityWebPortal\lib\UnityGroup;
6+
7+
// builtin die() makes a return code of 0, we want nonzero
8+
function _die($msg) {
9+
print($msg);
10+
exit(1);
11+
}
12+
13+
if (sizeof($argv) != 3 or in_array($argv, array("-h", "--help"))) {
14+
die("Usage: $argv[0] group_name filename_of_users_to_remove\n");
15+
}
16+
17+
$gid = $argv[1];
18+
$filename = $argv[2];
19+
$group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
20+
if (!$group->exists()) {
21+
_die("No such group '$gid'\n");
22+
}
23+
$handle = fopen($filename, "r") or _die("Can't open '$filename'\n");
24+
while (($line = fgets($handle)) !== false) {
25+
$uid = trim($line);
26+
$user = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
27+
if (!$group->userExists($user)) {
28+
print("Skipping '$uid' who doesn't appear to be in '$gid'\n");
29+
continue;
30+
}
31+
$group->removeUser($user);
32+
}
33+
fclose($handle);

0 commit comments

Comments
 (0)