File: patchem.pl

package info (click to toggle)
adbbs 3.0-1
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 272 kB
  • ctags: 39
  • sloc: perl: 1,280; makefile: 47; sh: 28
file content (45 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/perl -w

use strict;
use Data::Dumper;
$Data::Dumper::Useqq=1;

my @replace = (
	[ "\Q/usr/local/bin/\E",	'/usr/bin/' ],
	[ "\Q/usr/local/etc/adbbs/\E",	'/usr/local/etc/' ], # trick
	[ "\Q/usr/local/etc/crunch.db\E",	'/var/lib/adbbs/crunch.db' ],
	[ "\Q/usr/local/etc/fildb.db\E",	'/var/lib/adbbs/fildb.db' ],
	[ "\Q/usr/local/etc\E",	'/etc/adbbs' ],
	[ "\Q/usr/multi/bbs/bin\E",	'/usr/bin' ],
	[ "\Q/usr/multi/bbs/users\E",	'/home' ],
	[ "\Q/usr/multi/bbs\E",	'/var/lib/adbbs' ],
	[ "\Q/usr/multi/ftp\E",	'/home/ftp' ],
);

#my @perlscripts = `find . -type f | xargs file | grep perl | cut -d: -f1`;
my @perlscripts = `find . -type f`;
chomp @perlscripts;
#print Data::Dumper::Dumper(\@perlscripts);

foreach my $i (@perlscripts) {
	next if $i =~ /patchem/;
	next if $i =~ /patched$/;
	next if $i =~ /REA/;
	open S, "< $i" or die "$! $i";
	undef $/;
	my $script = <S>;
	my $org = $script;
	close S;
	foreach my $j (@replace) {
		my ($pat, $rep) = @$j;
		$script =~ s/$pat/$rep/sg;
	}
	if ($org ne $script) {
		print "Patching $i\n";
		open S, "> $i.patched" or die "$!";
		print S $script;
		close S;
		system("cat $i.patched > $i");
		unlink "$i.patched";
	}
}