Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 444 lines (397 sloc) 14.463 kB
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
1 #!/usr/bin/perl -w
2 # This code is a part of Slash, and is released under the GPL.
c0e7999 @pudge Update 2005, OSTG, etc.
pudge authored
3 # Copyright 1997-2005 by Open Source Technology Group. See README
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
4 # and COPYING for more information, or see http://slashcode.com/.
5 # $Id$
6
7 # By Jamie McCarthy, jamie@slashdot.org
8 # Based on template-tool, by Cliff Wood, Patrick Galbraith, Brian Aker
7ce51fb @jamiemccarthy Note in comment that this is experimental still.
jamiemccarthy authored
9 #
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
10 # STILL UNDER TESTING -- handles plugins now -- for now,
7ce51fb @jamiemccarthy Note in comment that this is experimental still.
jamiemccarthy authored
11 # be sure to use -T on any production site just in case this
12 # screws something up!!!
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
13
14 use strict;
15 use File::Basename;
16 use File::Path;
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
17 use File::Spec::Functions qw( :DEFAULT splitpath splitdir);
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
18 use Slash;
19 use Slash::Utility;
20 use Slash::DB;
21 use Slash::Install;
89cddc7 @scc now process globs as templates
authored
22 use Template;
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
23 use Getopt::Std;
2bd788c @jamiemccarthy Work better with later versions of JavaScript::Minifier
jamiemccarthy authored
24 use JavaScript::Minifier 0.02;
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
25
26 (my $VERSION) = ' $Revision$ ' =~ /\$Revision:\s+([^\s]+)/;
27 my $PROGNAME = basename($0);
28 my %opts;
29
30 my $symlink_exists = eval { symlink("",""); 1 };
31 if (!$symlink_exists) {
32 print STDERR "Sorry - symlink() not implemented on your system,\n";
33 print STDERR "so (duh!) symlink-tool cannot run.\n";
34 exit 1;
35 }
36
37 # Remember to doublecheck these match usage()!
38 usage('Options used incorrectly')
19719a3 @jamiemccarthy Rename the testing option "-t" for compatibility with template-tool
jamiemccarthy authored
39 unless getopts('hvu:TtUV', \%opts);
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
40 usage() if $opts{h} || !keys %opts;
41 version() if $opts{v};
42 usage('Right now only -U does anything') if !$opts{U};
19719a3 @jamiemccarthy Rename the testing option "-t" for compatibility with template-tool
jamiemccarthy authored
43 my $testing = $opts{T} ? 1 : ($opts{t} ? 1 : 0);
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
44 my $verbose = $opts{V} ? 1 : 0;
45
46 my $virtuser = $opts{u} || 'slash';
47 createEnvironment($virtuser);
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
48 my @dotfiles = ( );
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
49 my $slashdb = getCurrentDB();
50 my $constants = getCurrentStatic();
51 my $install = Slash::Install->new($virtuser);
52
53 # This will read all the themes and all the plugins available for this
54 # installation.
f3aa469 @jamiemccarthy New dboff regime: there are multiple "dboff_foo" files, and they all
jamiemccarthy authored
55 my $get_theme = $install->get("theme");
56 die "cannot get theme, DB probably unreachable" if !$get_theme;
57 my $site_theme = $get_theme->{value};
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
58 my $site_plugins = $install->get("plugin");
59 my @site_plugins = sort
60 map { $site_plugins->{$_}{value} }
61 keys %$site_plugins;
62
63 # What one theme, and what subset of the available plugins, is this
64 # site using?
65 my $theme_hr = $install->_getList(
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
66 $constants->{slashdir}, "themes", "THEME", 1
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
67 )->{$site_theme};
68 my $plugin_list = $install->_getList(
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
69 $constants->{slashdir}, "plugins", "PLUGIN", 1
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
70 );
71
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
72 ############################################################
f346e95 @scc enable optional CSSTidy in symlink-tool for .css globs
authored
73 # Handle globbing and minifying/tidying, do this first so results can be linked
311f308 @scc globbing must work for plugins as well as the theme
authored
74 for my $theme_or_plugin ($theme_hr, values %$plugin_list) {
b7ba256 @pudge fix thingys
pudge authored
75 for my $glob (keys %{$theme_or_plugin->{'glob'}}) {
76 my $destpath = canonpath(
77 catfile($theme_or_plugin->{dir},
8ac7ed7 @jamiemccarthy Whitespace fix
jamiemccarthy authored
78 $theme_or_plugin->{'glob'}{$glob})
b7ba256 @pudge fix thingys
pudge authored
79 );
89cddc7 @scc now process globs as templates
authored
80 my @filelist = ( );
b7ba256 @pudge fix thingys
pudge authored
81 for my $file (@{$theme_or_plugin->{$glob}}) {
89cddc7 @scc now process globs as templates
authored
82 push @filelist, canonpath(catfile($theme_or_plugin->{dir}, $file));
b7ba256 @pudge fix thingys
pudge authored
83 }
f346e95 @scc enable optional CSSTidy in symlink-tool for .css globs
authored
84
89cddc7 @scc now process globs as templates
authored
85 my $glob_template = Template->new({
86 INCLUDE_PATH => $theme_or_plugin->{dir},
87 PROCESS => \@filelist,
88 OUTPUT => \$destpath,
89 ABSOLUTE => 1,
90 RELATIVE => 1,
91 INTERPOLATE => 0,
92 }) || die "$Template::ERROR\n";
93
94 $glob_template->process($filelist[0], $constants, $destpath) || die $glob_template->error(), "\n";
95
96 # system("cat $filelist > $destpath");
b7ba256 @pudge fix thingys
pudge authored
97 my($name, $path, $suffix) = fileparse($destpath, qr/\.[^.]*/);
f346e95 @scc enable optional CSSTidy in symlink-tool for .css globs
authored
98
fc033df @pudge Misc. thingys
pudge authored
99 # you can glob any kinds of files you like, even mixing them...
100 # ...but if the globbed destination claims to be JavaScript, I'll also make a `minified' version
101 # (JavaScript::Minifier is a requirement in the Slash bundle)
b7ba256 @pudge fix thingys
pudge authored
102 if ($suffix eq '.js') {
103 my($min_src, $min_dest);
104 open $min_src, '<', $destpath;
105 open $min_dest, '>', "${path}${name}-minified.js";
2bd788c @jamiemccarthy Work better with later versions of JavaScript::Minifier
jamiemccarthy authored
106 if (JavaScript::Minifier->can('jsmin')) {
107 JavaScript::Minifier::jsmin($min_src, $min_dest);
108 } elsif (JavaScript::Minifier->can('minify')) {
6a7b89f @pudge fix!
pudge authored
109 &JavaScript::Minifier::minify(
e0c4aca @pudge lame!
pudge authored
110 input => $min_src, outfile => $min_dest
6a7b89f @pudge fix!
pudge authored
111 );
2bd788c @jamiemccarthy Work better with later versions of JavaScript::Minifier
jamiemccarthy authored
112 } else {
113 die "I give up, how does JavaScript::Minifier $JavaScript::Minifier::VERSION do its thing?";
114 }
b7ba256 @pudge fix thingys
pudge authored
115 }
f346e95 @scc enable optional CSSTidy in symlink-tool for .css globs
authored
116
fc033df @pudge Misc. thingys
pudge authored
117 # ...similarly for CSS, I'll also make a `csstidied' version
118 # (CSSTidy is _not_ a requirement in the Slash bundle, so we have to check)
f346e95 @scc enable optional CSSTidy in symlink-tool for .css globs
authored
119 elsif ($suffix eq '.css') {
120 my $tidiedpath = "${path}${name}-tidied.css";
121 # create a `tidied' version of css globs if csstidy is available,
122 # else the tidied version is just a link to the original concatenation
123 # consider: allow custom install dir for csstidy? a la sbindir, datadir, hc_fontpath, et al
0543066 @scc Fix parameter to csstidy: needed --silent=true, not just --silent
authored
124 if ( system("csstidy $destpath --silent=true --template=high $tidiedpath") != 0 ) {
f346e95 @scc enable optional CSSTidy in symlink-tool for .css globs
authored
125 link("$destpath", "$tidiedpath");
126 }
127 }
b7ba256 @pudge fix thingys
pudge authored
128 }
4b9c4aa @scc handling for new 'glob' mechanism, and minifying for js
authored
129 }
130
131
132 ############################################################
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
133 # Set up the %theme_subdir_files and %plugin_subdir_files hashes,
134 # to have a list of all the files that our theme references.
135 my %theme_subdir_files = ( );
136 my %plugin_subdir_files = ( );
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
137 my %theme_css_translate = ();
138 my %plugin_css_translate = ();
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
139 # First, pull in the files referenced by the theme.
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
140 my @theme_htdocs_keys = grep /^(htdoc|image|topic|css)/, keys %$theme_hr;
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
141 for my $key (@theme_htdocs_keys) {
1066683 @jamiemccarthy Allow more custom install types (htdoc_foo etc.) to be processed without
jamiemccarthy authored
142 next unless $key && $theme_hr->{$key};
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
143 if ($key eq "css" and $constants->{css_use_imagedir}) {
144 if (ref($theme_hr->{$key}) && ref($theme_hr->{$key}) eq "ARRAY") {
145 $theme_css_translate{$_} = 1 foreach @{$theme_hr->{$key}};
146 } else {
147 $theme_css_translate{$theme_hr->{$key}} = 1;
148 }
149 }
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
150 push @{$theme_subdir_files{htdocs}},
1066683 @jamiemccarthy Allow more custom install types (htdoc_foo etc.) to be processed without
jamiemccarthy authored
151 ref($theme_hr->{$key}) && ref($theme_hr->{$key}) eq 'ARRAY'
152 ? @{$theme_hr->{$key}}
153 : $theme_hr->{$key};
154 }
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
155
1066683 @jamiemccarthy Allow more custom install types (htdoc_foo etc.) to be processed without
jamiemccarthy authored
156 for my $key (qw( tasks misc )) {
157 my $src_key = $key;
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
158 $src_key =~ s/s$//; # theme "task" becomes theme_subdir_files "tasks"
4001f47 @jamiemccarthy Don't check bogus theme data types.
jamiemccarthy authored
159 next unless $theme_hr->{$src_key};
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
160 @{$theme_subdir_files{$key}} =
1066683 @jamiemccarthy Allow more custom install types (htdoc_foo etc.) to be processed without
jamiemccarthy authored
161 ref($theme_hr->{$src_key}) && ref($theme_hr->{$src_key}) eq 'ARRAY'
162 ? @{$theme_hr->{$src_key}}
163 : $theme_hr->{$src_key};
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
164 }
165
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
166 # Then, pull in the files referenced by each plugin used.
167 my %plugin_htdocs_keys = ( );
168 my @plugin_htdocs_keys = ( );
169 for my $plugin (keys %$plugin_list) {
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
170 for my $key (grep /^(htdoc|image|topic|css)/, keys %{$plugin_list->{$plugin}}) {
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
171 $plugin_htdocs_keys{$key} = 1;
172 }
173 }
174 @plugin_htdocs_keys = sort keys %plugin_htdocs_keys;
175 for my $plugin (keys %$plugin_list) {
176 my $plugin_hr = $plugin_list->{$plugin};
177 for my $key (@plugin_htdocs_keys) {
178 next unless $key && $plugin_hr->{$key};
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
179 if ($key eq "css" and $constants->{css_use_imagedir}) {
180 if (ref($plugin_hr->{$key}) && ref($plugin_hr->{$key}) eq "ARRAY") {
181 $plugin_css_translate{$plugin}{$_} = 1 foreach @{$plugin_hr->{$key}};
182 } else {
183 $plugin_css_translate{$plugin}{$_} = $plugin_hr->{$key};
184 }
185 }
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
186 push @{$plugin_subdir_files{$plugin}{htdocs}},
187 ref($plugin_hr->{$key}) && ref($plugin_hr->{$key}) eq 'ARRAY'
188 ? @{$plugin_hr->{$key}}
189 : $plugin_hr->{$key};
190 }
191 for my $key (qw( tasks misc )) {
192 my $src_key = $key;
193 $src_key =~ s/s$//; # plugin "task" becomes "tasks"
194 next unless $plugin_hr->{$src_key};
195 @{$plugin_subdir_files{$plugin}{$key}} =
196 ref($plugin_hr->{$src_key}) && ref($plugin_hr->{$src_key}) eq 'ARRAY'
197 ? @{$plugin_hr->{$src_key}}
198 : $plugin_hr->{$src_key};
199 }
200 }
201 #use Data::Dumper;
202 #print "theme_hr: " . Dumper($theme_hr);
203 #print "plugin_list: " . Dumper($plugin_list);
204 #print "theme_subdir_files: " . Dumper(\%theme_subdir_files);
205 #print "plugin_subdir_files: " . Dumper(\%plugin_subdir_files);
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
206 #print "theme css translate: " . Dumper(\%theme_css_translate);
207 #print "plugin css translate: " . Dumper(\%plugin_css_translate);
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
208
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
209 my $theme_dir = $theme_hr->{dir};
210 my $site_dir = $constants->{datadir};
211
212 if (!$testing && !-w $site_dir) {
213 print STDERR "No write access to '$site_dir'\n";
214 print STDERR "for EUID $>, cannot write any files\n";
215 exit 1;
216 }
217
c6365a3 @jamiemccarthy Don't process files twice (this prevents plugins from overriding themes
jamiemccarthy authored
218 my %processed = ( );
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
219 my $num_changes = 0;
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
220 for my $subdir (sort keys %theme_subdir_files) {
221 my @files = sort @{$theme_subdir_files{$subdir}};
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
222 for my $target_file (@files) {
223 # Strip off "../slashcode/" from front to find
224 # where the symlink was installed in the
225 # "site/foo" tree.
226 my $theme_file_abs = canonpath(catfile($theme_dir, $target_file));
4350dbe @jamiemccarthy Better canonicalization of filenames that symlinks point to: instead of
jamiemccarthy authored
227 1 while $theme_file_abs =~ s{/[^/]+/\.\.}{};
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
228 my $site_rel_file = $target_file;
229 1 while $site_rel_file =~ s{^\.\.\/[^/]+/}{};
230 my $site_file_abs = canonpath(catfile($site_dir, $site_rel_file));
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
231
232 $site_file_abs = css_translate($site_file_abs) if ($theme_css_translate{$target_file});
233
c6365a3 @jamiemccarthy Don't process files twice (this prevents plugins from overriding themes
jamiemccarthy authored
234 if ($processed{$site_file_abs}) {
235 if ($verbose) {
236 print "Skipping file in theme, already processed: '$site_file_abs'\n";
237 }
238 next;
239 }
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
240 my $site_file_abs_dot = dotfile($site_file_abs);
241 my $site_file_abs_dot_short = dotfile($site_rel_file);
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
242 # At this point, $site_file_abs is e.g.
243 # '/usr/local/slash/site/mysite/tasks/spamarmor.pl'
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
244 # $site_file_abs_dot is e.g.
245 # '/usr/local/slash/site/mysite/tasks/.spamarmor.pl'
246 # $theme_file_abs is e.g.
247 # '/usr/local/slash/theme/slashcode/tasks/spamarmor.pl'
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
248
249
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
250 $num_changes += handle_file($site_file_abs, $theme_file_abs,
251 $site_file_abs_dot, $site_file_abs_dot_short);
c6365a3 @jamiemccarthy Don't process files twice (this prevents plugins from overriding themes
jamiemccarthy authored
252 $processed{$site_file_abs} = 1;
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
253 }
254 }
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
255 for my $plugin (sort keys %plugin_subdir_files) {
256 my $plugin_hr = $plugin_subdir_files{$plugin};
257 my $plugin_dir = $plugin_list->{$plugin}{dir};
258 for my $subdir (sort keys %$plugin_hr) {
259 my @files = sort @{$plugin_hr->{$subdir}};
260 #print "plugin '$plugin' subdir '$subdir' files '@files'\n";
261 for my $target_file (@files) {
262 my $plugin_file_abs = canonpath(catfile($plugin_dir, $target_file));
263 1 while $plugin_file_abs =~ s{/[^/]+/\.\.}{};
264 my $site_rel_file = $target_file;
265 1 while $site_rel_file =~ s{^\.\.\/[^/]+/}{};
266 # Plugins don't get the type prepended so we need to
267 # do that here.
268 $site_rel_file =~ s{^(?:$subdir/)?}{$subdir/};
269 my $site_file_abs = canonpath(catfile($site_dir, $site_rel_file));
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
270
271 $site_file_abs = css_translate($site_file_abs) if ($plugin_css_translate{$plugin}{$target_file});
272
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
273 #print "plugin '$plugin' subdir '$subdir' site_rel_file '$site_rel_file' site_file_abs '$site_file_abs'\n";
c6365a3 @jamiemccarthy Don't process files twice (this prevents plugins from overriding themes
jamiemccarthy authored
274 if ($processed{$site_file_abs}) {
275 if ($verbose) {
276 print "Skipping file in '$plugin' plugin, already processed: '$site_file_abs'\n";
277 }
278 next;
279 }
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
280 my $site_file_abs_dot = dotfile($site_file_abs);
281 my $site_file_abs_dot_short = dotfile($site_rel_file);
282 # At this point, $site_file_abs is e.g.
283 # '/usr/local/slash/site/mysite/tasks/adminmail.pl'
284 # $site_file_abs_dot is e.g.
285 # '/usr/local/slash/site/mysite/tasks/.adminmail.pl
286 # $plugin_file_abs is e.g.
287 # '/usr/local/slash/plugin/Stats/adminmail.pl'
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
288
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
289 $num_changes += handle_file($site_file_abs, $plugin_file_abs,
290 $site_file_abs_dot, $site_file_abs_dot_short);
c6365a3 @jamiemccarthy Don't process files twice (this prevents plugins from overriding themes
jamiemccarthy authored
291 $processed{$site_file_abs} = 1;
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
292 }
293 }
294 }
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
295 if ($num_changes == 0) {
296 print "symlink-tool -U: no symlink changes necessary\n";
297 }
298
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
299 if (@dotfiles) {
300 print "symlink-tool: found dotfiles: @dotfiles\n";
301 }
302
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
303 ###############################################
304 sub handle_file {
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
305 my($symlink_file, $target_file, $symlink_file_dot, $symlink_file_dot_short) = @_;
10db7d0 @pudge Warn if local file doesn't exist
pudge authored
306
307 if (!-e $target_file) {
308 print "Target file '$target_file' missing, can't create symlink\n";
309 return 1;
310 }
311
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
312 if (!-e $symlink_file && -e $symlink_file_dot) {
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
313 # The symlink file is missing and in its place is a
3f0f385 @jamiemccarthy Numerous INSTALL improvements, including stressing importance of
jamiemccarthy authored
314 # dotfile. The site admin must have disabled that file,
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
315 # perhaps temporarily. Make sure it's correct; do
316 # what we were doing to do on the real file, on the
317 # dotfile instead.
318 $symlink_file = $symlink_file_dot;
319 push @dotfiles, $symlink_file_dot_short;
320 if ($verbose) {
321 print "Checking dotfile replacement at '$symlink_file'\n";
322 }
323 }
10db7d0 @pudge Warn if local file doesn't exist
pudge authored
324
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
325 if (-e $symlink_file && !-l $symlink_file) {
326 # The file in place is not a symlink; compare it to
327 # what it should be and only replace it with a symlink
328 # if the two are identical.
329 my $diff;
330 if ($verbose) {
3f0f385 @jamiemccarthy Numerous INSTALL improvements, including stressing importance of
jamiemccarthy authored
331 $diff = system("diff $target_file $symlink_file");
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
332 } else {
3f0f385 @jamiemccarthy Numerous INSTALL improvements, including stressing importance of
jamiemccarthy authored
333 $diff = system("diff $target_file $symlink_file > /dev/null");
f6e57db @jamiemccarthy Updates for symlink-tool including small extension to an Install.pm m…
jamiemccarthy authored
334 }
335 if ($diff) {
336 print "File should be symlink, but is not, and differs from intended target: '$symlink_file' '$target_file'; difference needs to be resolved or symlink-tool will not touch it\n";
337 return 1;
338 } else {
339 print "File at '$symlink_file' is not a symlink, but is identical to what it should be; ";
340 if ($testing) {
341 print "file would be unlinked and allowed to be recreated.\n";
342 return 1;
343 } else {
344 print "unlinking; will be created next.\n";
345 unlink $symlink_file;
346 }
347 }
348 }
10db7d0 @pudge Warn if local file doesn't exist
pudge authored
349
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
350 lstat($symlink_file);
351 if (!-e _) {
352 print "Symlink at '$symlink_file' missing, ";
353 if ($testing) {
354 print "would create: '$target_file'\n";
355 return 1;
356 }
357 my $success = symlink($target_file, $symlink_file);
358 if (!$success) {
359 print "attempt to create FAILED: $!\n";
360 return 1;
361 }
362 print "successfully added link to '$target_file'\n";
363 return 1;
364 }
365 my $cur_target_file = readlink($symlink_file);
366 if ($cur_target_file eq $target_file) {
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
367 if ($verbose) {
368 print "Correct: $symlink_file -> $target_file\n";
369 }
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
370 return 0;
371 }
372 print "Symlink at '$symlink_file' mispointed at '$cur_target_file', ";
373 if ($testing) {
374 print "would repoint to '$target_file'\n";
375 return 1;
376 }
377 my $success = unlink $symlink_file;
378 if (!$success) {
379 print "attempt to unlink FAILED: $!\n";
380 return 1;
381 }
382 $success = symlink($target_file, $symlink_file);
383 if (!$success) {
384 print "original unlinked, attempt to link properly FAILED: $!\n";
385 return 1;
386 }
387 print "successfully relinked to '$target_file'\n";
388 return 1;
389 }
390
391 ###############################################
f77edda @tvroom Update to symlink-tool to allow for css= syntax and .css symlink target
tvroom authored
392 sub css_translate {
393 my ($file_abs) = @_;
394 my $seen_htdocs = 0;
395 my ($volume, $dirs, $file) = splitpath($file_abs);
396 my @dirs = splitdir($dirs);
397 push @dirs, "images";
398 return catfile(@dirs, $file);
399
400 }
401 ###############################################
241d137 @jamiemccarthy Recognize files that have been disabled by prepending a "." to their
jamiemccarthy authored
402 sub dotfile {
403 my($file_abs) = @_;
404 my($volume, $dirs, $file) = splitpath($file_abs);
405 return "$dirs.$file";
406 }
407
408 ###############################################
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
409 sub usage {
410 print "*** $_[0] \n" if $_[0];
411 print <<EOT;
412
413 Usage: $PROGNAME [OPTIONS] <template templateN>
414
415 Main options:
416 -h Help (this message)
417 -v Version
418 -u Virtual user (default is "slash")
19719a3 @jamiemccarthy Rename the testing option "-t" for compatibility with template-tool
jamiemccarthy authored
419 -t Test run, report but don't do anything
420 -T Synonym for -t
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
421 -U Upgrade your symlinks to the latest for your theme and plugins
422
423 Debugging options:
424 -V Increases verbosity.
425
426 EOT
427 exit 0;
428 }
429
430 ###############################################
431 sub version {
432 print <<EOT;
433
434 $PROGNAME $VERSION
435
436 This code is a part of Slash, and is released under the GPL.
c0e7999 @pudge Update 2005, OSTG, etc.
pudge authored
437 Copyright 1997-2005 by Open Source Technology Group. See README
c978fd4 @jamiemccarthy Tool to make sure symlinks for a site are correctly installed.
jamiemccarthy authored
438 and COPYING for more information, or see http://slashcode.com/.
439
440 EOT
441 exit 0;
442 }
443
Something went wrong with that request. Please try again.