File: moin-update-wikilist

package info (click to toggle)
moin 1.9.9-1+deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 76,024 kB
  • sloc: python: 143,896; java: 10,704; php: 2,385; perl: 1,574; xml: 371; makefile: 214; sh: 81; sed: 5
file content (48 lines) | stat: -rwxr-xr-x 999 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl -t
# Add a user to the system wide wikilist.
# This script can safely be made suid.
use warnings;
use strict;
use English;

my $username=getpwuid($REAL_USER_ID);
if (! defined $username || ! length $username) {
	die "unable to determine user name for UID $REAL_USER_ID\n";
}

my $wikilist="/etc/moin/wikilist";
if (! -e $wikilist) {
	die "$wikilist does not exist\n";
}

my $removed=0;
my @lines;
open (my $list, "<$wikilist") || die "read $wikilist: $!";
while (<$list>) {
	chomp;
	if (/^\s*([^\s]+)\s*$/) {
		my $user=$1;
		if ($user eq $username) {
			$removed=1;		
		}
		else {
			push @lines, $_;
		}
	}
	else {
		push @lines, $_;
	}
}
close $list || die "error reading $list: $!";
open ($list, ">$wikilist") || die "write $wikilist: $!";
foreach (@lines) {
	print $list "$_\n";
}
if ($removed) {
	print "removed user $username from $wikilist\n";
}
else {
	print $list "$username\n";
	print "added user $username to $wikilist\n";
}
close $list || die "error writing $list: $!";