12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- use strict;
- sub verify_setup {
- if (not -f 'oldrc.log') {
- die "Run this script in your data directory.\n"
- . "The oldrc.log file should be in the same directory.\n";
- }
- if (not -d 'temp') {
- die "Run this script in your data directory.\n"
- . "The temp directory should be in the same directory.\n";
- }
- }
- sub request_lock {
- if (-d 'temp/lockmain') {
- die "The wiki is currently locked.\n"
- . "Rerun this script later.\n";
- }
- mkdir('temp/lockmain') or die "Could not create 'temp/lockmain'.\n"
- . "You probably don't have the file permissions necessary.\n";
- }
- sub release_lock {
- rmdir('temp/lockmain') or die "Could not remove 'temp/lockmain'.\n"
- }
- sub anonymize {
- open(F, 'oldrc.log') or die "Could not open 'oldrc.log' for reading.\n";
- open(B, '>oldrc.log~') or die "Could not open 'oldrc.log~' for writing.\n"
- . "I will not continue without having a backup available.\n";
- my $FS = "\x1e";
- my @lines = ();
- while (my $line = <F>) {
- next if $line eq "\n";
- my ($ts, $id, $minor, $summary, $host, @rest) = split(/$FS/o, $line);
- if ($id eq '[[rollback]]') {
-
- push(@lines, $line);
- } else {
-
- push(@lines, join($FS, $ts, $id, $minor, $summary, 'Anonymous', @rest));
- }
- print B $line;
- }
- close(F);
- open(F, '>', 'oldrc.log') or die "Could not open 'oldrc.log' for writing.\n";
- for my $line (@lines) {
- print F $line;
- }
- close(F);
- print "Wrote anonymized 'oldrc.log'.\n";
- print "Saved a backup as 'oldrc.log~'\n";
- }
- sub main {
- verify_setup();
- request_lock();
- anonymize();
- release_lock();
- }
- main();
|