You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ikiwiki-mass-rebuild 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. my $etcfile="/etc/ikiwiki/wikilist";
  5. sub root {
  6. $> == 0;
  7. }
  8. sub username {
  9. (getpwuid($>))[0];
  10. }
  11. sub processline {
  12. my $setup=shift;
  13. if (! -f "$setup") {
  14. print STDERR "warning: $setup does not exist, skipping\n";
  15. return;
  16. }
  17. print "Processing $setup as user ".username()." ...\n";
  18. my $ret=system("ikiwiki", "-setup", $setup, @ARGV);
  19. if ($ret != 0) {
  20. print STDERR "warning: processing $setup failed with code $ret\n";
  21. }
  22. }
  23. my %users;
  24. sub processuser {
  25. my $user=shift;
  26. next if $user=~/^-/ || $users{$user};
  27. $users{$user}=1;
  28. my $ret=system("su", $user, "-s", "/bin/sh", "-c", "--", "$0 --nonglobal @ARGV");
  29. if ($ret != 0) {
  30. print STDERR "warning: processing for $user failed with code $ret\n";
  31. }
  32. }
  33. sub processlist {
  34. my $file=shift;
  35. return unless -e $file;
  36. my $list;
  37. open ($list, "<$file") || die "$file: $!";
  38. while (<$list>) {
  39. chomp;
  40. s/^\s+//;
  41. s/\s+$//;
  42. next if /^#/ || ! length;
  43. if (/^([-\w]+)\s+([^\s]+)$/) {
  44. my $user=$1;
  45. my $setup=$2;
  46. if (root()) {
  47. processuser($user);
  48. }
  49. else {
  50. if (username() eq $user) {
  51. processline($setup);
  52. }
  53. }
  54. }
  55. elsif (/^([-\w]+)$/) {
  56. my $user=$1;
  57. if (root()) {
  58. processuser($user);
  59. }
  60. else {
  61. my $home=(getpwnam($user))[7];
  62. if (defined $home && -d $home) {
  63. my $dotfile="$home/.ikiwiki/wikilist";
  64. processlist($dotfile);
  65. }
  66. }
  67. }
  68. }
  69. close $list;
  70. }
  71. if (@ARGV && $ARGV[0] eq "--nonglobal") {
  72. shift;
  73. # avoid recursively processing if the wikilist file has a root
  74. # user in it
  75. if (root()) {
  76. exit 1;
  77. }
  78. }
  79. processlist($etcfile);