forked from backuppc/backuppc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makePatch
executable file
·97 lines (85 loc) · 2.7 KB
/
makePatch
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env perl
#
# Script that generates a patch file for BackupPC.
#
use strict;
use File::Find;
use File::Path;
my $BaseVersion = "4.0.0alpha3";
my $PatchLevel = "pl0";
my $PatchVersion = "$BaseVersion$PatchLevel";
my $Base = "/usr/local/BackupPC/dist/BackupPC-$BaseVersion";
my $TmpDir = "patch.tmp";
my $OutFile = "BackupPC-$PatchVersion.diff";
find({wanted => \&CopyFile, no_chdir => 1}, $Base);
unlink($OutFile);
open(OUT, ">", $OutFile) || die("can't open OutFile\n");
my $now = localtime;
print OUT <<EOF;
#
# $OutFile: BackupPC patch file generated
# on $now.
#
# This patch file should be applied to a cleanly unpacked BackupPC
# version $BaseVersion. Do not apply any old patch files; each
# patch file accumulates all previous changes.
#
# Example:
#
# # fetch BackupPC-$BaseVersion.tar.gz
# # fetch $OutFile
# tar zxvf BackupPC-$BaseVersion.tar.gz
# cd BackupPC-$BaseVersion
# patch -p0 < ../$OutFile
# perl configure.pl
#
# ChangeLog:
#
# ADD CHANGELOG HERE
#
EOF
mkdir($TmpDir) if ( !-d $TmpDir );
foreach my $dir ( qw(bin lib cgi-bin) ) {
open(DIFF, "diff -ur -I '^# Version .*, released ' -I '#.*/bin/perl' $Base/$dir $TmpDir/$dir|")
|| die("can't run diff\n");
while ( <DIFF> ) {
next if ( /^Only/ || /^diff / );
s/^--- \Q$Base\//--- /;
s/^\+\+\+ \Q$TmpDir\//+++ /;
print OUT;
}
}
rmtree($TmpDir, 0);
sub CopyFile
{
(my $file = $File::Find::name) =~ s{\Q$Base}{};
(my $dir = $file) =~ s{(.*)/.*}{$1};
$file =~ s{^/}{};
#print("Got dir = $TmpDir/$dir, file = $file\n");
return if ( !-f $file );
mkpath("$TmpDir/$dir", 0, 0755) if ( !-d "$TmpDir/$dir" );
open(IN, "<", $file)
|| die("Can't open $file for input\n");
open(OUT, ">", "$TmpDir/$file")
|| die("Can't open $TmpDir/$file for output\n");
while ( <IN> ) {
if ( /^use lib ".*BackupPC[\d.]*\/lib";/
|| /^use lib "\/home\/pcbackup\/install\/lib";/ ) {
print OUT "use lib \"__INSTALLDIR__/lib\";\n";
} elsif ( $file =~ /Lib.pm/ && /(.*TopDir *=> .*)'.*',/ ) {
print OUT "$1'__TOPDIR__',\n";
} elsif ( $file =~ /Lib.pm/ && /(.*BinDir *=> .*)'.*',/ ) {
print OUT "$1'__INSTALLDIR__',\n";
} elsif ( $file =~ /Lib.pm/ && /(.*LibDir *=> .*)'.*',/ ) {
print OUT "$1'__INSTALLDIR__',\n";
} elsif ( $file =~ /Lib.pm/ && /(.*Version *=> .*)'.*',/ ) {
print OUT "$1'$PatchVersion',\n";
} elsif ( $file =~ /BackupPC_Admin/ && /(my *\$installDir *= *)'.*'/ ) {
print OUT "$1'__INSTALLDIR__/lib';\n";
} else {
print(OUT);
}
}
close(IN);
close(OUT);
}