summaryrefslogtreecommitdiff
path: root/ikiwiki-update-wikilist
blob: 0f3f0bcc6497f2b6f6b73cf6821f01847bb6925c (plain)
  1. #!/usr/bin/perl -t
  2. # Add a user to the system wide wikilist.
  3. # This script can safely be made suid.
  4. use warnings;
  5. use strict;
  6. use English;
  7. my $username=getpwuid($REAL_USER_ID);
  8. if (! defined $username || ! length $username) {
  9. die "unable to determine user name for UID $REAL_USER_ID\n";
  10. }
  11. my $wikilist="/etc/ikiwiki/wikilist";
  12. if (! -e $wikilist) {
  13. die "$wikilist does not exist\n";
  14. }
  15. my $removed=0;
  16. my @lines;
  17. open (my $list, "<$wikilist") || die "read $wikilist: $!";
  18. while (<$list>) {
  19. chomp;
  20. if (/^\s*([^\s]+)\s*$/) {
  21. my $user=$1;
  22. if ($user eq $username) {
  23. $removed=1;
  24. }
  25. else {
  26. push @lines, $_;
  27. }
  28. }
  29. else {
  30. push @lines, $_;
  31. }
  32. }
  33. close $list || die "error reading $list: $!";
  34. open ($list, ">$wikilist") || die "write $wikilist: $!";
  35. foreach (@lines) {
  36. print $list "$_\n";
  37. }
  38. if ($removed) {
  39. print "removed user $username from $wikilist\n";
  40. }
  41. else {
  42. print $list "$username\n";
  43. print "added user $username to $wikilist\n";
  44. }
  45. close $list || die "error writing $list: $!";