/
template-check
110 lines (83 loc) · 2.67 KB
/
template-check
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
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2003 by Open Source Development Network. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id$
use strict;
use File::Basename;
use File::Spec::Functions;
use Getopt::Std;
use Slash::DB;
(my $VERSION) = ' $Revision$ ' =~ /\$Revision:\s+([^\s]+)/;
my $PROGNAME = basename($0);
my %opts;
# Remember to doublecheck these match usage()!
usage('Options used incorrectly') unless getopts('hvb:t:u:', \%opts);
usage() if $opts{'h'};
version() if $opts{'v'};
my $dir = shift || curdir();
my $diff = q{diff -Bu};
my $grep = q{grep -v '^Only in '};
my $less = q{less};
# main program logic (in braces to offset nicely)
{
usage() if !$opts{'u'} && !($opts{'b'} && $opts{'t'});
my($basedir, $theme, $plugindir);
if ($opts{'u'}) {
my $slashdb = Slash::DB->new($opts{'u'});
my $siteinfo = $slashdb->getDescriptions('site_info');
$basedir = $slashdb->getVar('slashdir', 'value');
$theme = $siteinfo->{theme};
}
$basedir = $opts{'b'} if $opts{'b'};
$theme = $opts{'t'} if $opts{'t'};
die "No basedir" unless $basedir;
die "No theme" unless $theme;
$theme = catdir($basedir, 'themes', $theme, 'templates');
$plugindir = catdir($basedir, 'plugins');
opendir my $dh, $plugindir or die "Can't open $plugindir: $!";
my @plugins = grep !/^(?:CVS|\.{1,2}|Makefile)$/, readdir($dh);
closedir $dh;
mydiff($theme);
for (@plugins) {
mydiff(catdir($plugindir, $_, 'templates'));
}
}
sub mydiff {
my $diffdir = $_[0];
print "Diffing $diffdir\n";
system("$diff $dir $diffdir | $grep | $less");
}
sub usage {
print "*** $_[0]\n" if $_[0];
# Remember to doublecheck these match getopts()!
print <<EOT;
Usage: $PROGNAME [DIRECTORY]
This program will show the differences between installed
templates (after they have been dumped to DIRECTORY),
and templates in the installation directory (usually
in /usr/local/slash/themes/ and /usr/local/slash/plugins/).
If -u is not specified, -b and -t must be specified.
Dump your templates out using template-tool, then
run this program on that directory.
Main options:
Directory to diff against (default is current dir)
-h Help (this message)
-v Version
-u Virtual user
-b Specify the basedir to compare against
-t Specify the theme to use
EOT
exit;
}
sub version {
print <<EOT;
$PROGNAME $VERSION
This code is a part of Slash, and is released under the GPL.
Copyright 1997-2003 by Open Source Development Network. See README
and COPYING for more information, or see http://slashcode.com/.
EOT
exit;
}
__END__
diff -Bu ./ /usr/local/slash/themes/slashcode/templates | grep -v '^Only in ' | less