1 rizwank 1.1 #!/usr/bin/perl -w
2
3 # Support functionality for the TWiki Collaboration Platform, http://TWiki.org/
4 #
5 # A script to help people upgrade an existing TWiki to a new version
6 # (don't laugh - we're expecting applause, not laughter!)
7 #
8 # Jul 2004 - written by Martin Gregory, martin@gregories.net
9
10 =begin twiki
11
12 ---+ UpgradeTwiki
13
14 Create an upgraded twiki installation from an existing one
15 and a new distribution.
16
17 This script expects '.' to be the root of a TWiki distribution when it is called.
18 =cut
19
20 BEGIN {
21 (-d "lib" and -d "data") or
22 rizwank 1.1 die "I was expecting to see a ./lib and ./data directories: you need to run $0 in the directory where you extracted the new TWiki distribution!\n";
23 unshift @INC, "./lib"; # have to find Text::Diff, UpdateTopics, TWikiCfg which are bundled with TWiki.
24 }
25
26 use strict;
27
28 use TWiki::Upgrade::TWikiCfg;
29 use TWiki::Upgrade::UpdateTopics;
30 use File::Copy;
31 use Text::Diff;
32 use File::Find;
33
34 print "Checklist:
35 \t- This script should be run in the directory where you unpacked the new distribtion
36 \t- The argument to this script is the target directory where it will create a whole new installation
37 \t (_not_ the same as where you unpacked the new distribution, nor where your existing twiki installation is)
38 \t- You need enough disk space to copy your existing twiki installation to the target directory.
39 \t- The target directory does not have to be web-accessible.
40 ";
41
42 my $targetDir = shift or die "Usage: $0 <target directory to build merged new wiki...>\n";
43 rizwank 1.1
44 # not sure if a relative path will be safe... better safe than sorry...
45 $targetDir =~ m|^[/~]| or die "Usage: $0 <full path to target directory for new wiki build>\n";
46
47 $targetDir =~ s|/$||; # avoid ugly double slashes.
48
49 print "
50 That means that there should be all the normal TWiki directories here: bin, lib, pub, templates etc. right here.
51
52 Here's what's about to happen:
53
54 1) I'm going to create a new TWiki in $targetDir based on this new distribution
55 2) I'm going to update the TWiki.cfg in $targetDir/lib to match the existing one in your current TWiki
56 3) I'm going to merge the new TWiki data files from the release with all your existing information
57 4) I'm going to tell you what you need to do next!
58
59 First, you need to tell me where I can get config info about your existing TWiki.
60
61 Please tell me a path to either the setlib.cfg (preferred) or the TWiki.cfg...
62 ";
63
64 rizwank 1.1 my ($configPath, $setlibPath, $libPath);
65
66 do
67 {
68 chomp ($configPath = <STDIN>) ;
69 }
70 until ((-f "$configPath/setlib.cfg" || -f "$configPath/TWiki.cfg") ? 1 :
71 (print("Hmmm - I can't see setlib.cfg or Twiki.cfg at $configPath ... please check and try again\n"), 0)
72 );
73
74 if (-f "$configPath/TWiki.cfg")
75 {
76 $libPath = $configPath;
77
78 print "OK - found TWiki.cfg. Now I need you to tell me where the existing TWiki bin directory is:\n";
79
80 # this will only be used to find .htaccess at this point.
81 # should also be used to fix up bin scripts with $scriptSuffix: TBD!
82 do
83 {
84 chomp ($setlibPath = <STDIN>) ;
85 rizwank 1.1 }
86 until ((-d $setlibPath) ? 1 :
87 (print("Hmmm - $setlibPath doesn't even look like a directory!... please check and try again\n"), 0)
88 );
89 }
90 else
91 {
92 $libPath = "";
93 $setlibPath = $configPath;
94 }
95
96 # Now, should have finished asking the user questions...
97
98 print "First, creating $targetDir structures...\n";
99
100 opendir(HERE , ".");
101
102 mkdir $targetDir or die "Couldn't create the target directory ($targetDir): $!\n";
103
104 my $file;
105
106 rizwank 1.1 foreach $file (readdir(HERE))
107 {
108 next if ($file eq '.');
109 next if ($file eq '..');
110 next if ($file =~ /.zip$/);
111 next if ($file =~ /^data$/); # UpgradeTopics will copy the data as appropriate.
112
113 print "$file\n";
114 system("cp -R $file $targetDir");
115 }
116
117 print "Preparing to write a new format configuration file for you...\n\n";
118
119 TWikiCfg::UpgradeTWikiConfig($configPath, $targetDir); # dies on error, without doing damage
120
121 print "\n\nMerging your existing twiki data ($TWikiCfg::dataDir) with new release twiki data...\n";
122
123 my $baseDir = `pwd`;
124 chomp ($baseDir);
125
126 UpdateTopics::UpdateTopics($TWikiCfg::dataDir, "$baseDir/data", "$targetDir/data"); # dies on error, without doing damage
127 rizwank 1.1
128 #make sure we're in the right place still
129 chdir($baseDir);
130
131 print "OK - the merge process completed successfully...\n";
132
133 # fix up permissions ... get them to a working state, if not ideal seurity-wise!
134 # (we tell the user to check the permissions later anyhow)
135
136 print "Now I'm giving write access to pub & data in the newly set up TWiki, so your web server can access them...\n";
137
138 find( sub {chmod 0777, $File::Find::name;} , "$targetDir/pub", "$targetDir/data");
139
140 # set up .htaccess, if appropriate
141
142 if (-f "$setlibPath/.htaccess")
143 {
144 if (copy("$setlibPath/.htaccess", "$targetDir/bin/.htaccess"))
145 {
146 print "
147 I copied in your existing .htaccess into $targetDir/bin.
148 rizwank 1.1
149 \tThe significant differences between the new template for .htacess and your previous one are:
150
151 ";
152 print join "\n", grep( /^[+-][^#]/ , split( /\n/, diff("$targetDir/bin/.htaccess", "./bin/.htaccess.txt")));
153
154 print "
155 You may need to apply some of these differences to the new .htaccess that I created... that's up to you.
156 (I'm not gonna mess with security settings at all!)
157
158 ";
159
160 }
161 else
162 {
163 warn "
164 I couldn't copy in your existing .htaccess file from $setlibPath to $targetDir/bin: $!\n";
165 }
166 }
167 else
168 {
169 rizwank 1.1 warn "
170 Couldn't see a .htaccess in $setlibPath ... so I didn't try to help in that respect\n";
171 }
172
173 # now let's try to get their scriptSuffix right for them
174 # (Is this a good idea, I wonder? Can't see why not...)
175
176 if ($TWikiCfg::scriptSuffix)
177 {
178 print "
179 Applying your '\$scriptSuffix' ($TWikiCfg::scriptSuffix) to the scripts in $targetDir/bin...
180 ";
181
182 opendir(BINDIR, "$targetDir/bin") or
183 warn "Ooops - couldn't open $targetDir/bin for reading... that's certainly strange! ($!)\n";
184
185 foreach my $f (readdir BINDIR)
186 {
187 next if ($f =~ m|\.|); # scripts should not have dots, other things should!
188
189 print "$f ";
190 rizwank 1.1 rename "$targetDir/bin/$f", "$targetDir/bin/$f$TWikiCfg::scriptSuffix"
191 or warn "Oops, couldn't rename $setlibPath/$f to $setlibPath/$f$TWikiCfg::scriptSuffix : $!\n";
192 }
193 print "\ndone\n";
194 }
195
196 # Also, for Cairo, we have to do the pattern skin additions
197 # (etc, as mentioned in the UpgradeGuide, manual upgrade section)
198
199 print "Putting in default WebLeftBar and WebAdvancedSearch...\n";
200
201 if (-f "data/TWiki/WebLeftBarExample.txt")
202 {
203 if (opendir(DATADIR, "$targetDir/data"))
204 {
205 foreach my $web (readdir DATADIR)
206 {
207 next if ($web =~ m|^\.|); # don't hit '.' , '..' . Any other diretories starting with '.' are suss also.
208 next if (!-d "$targetDir/data/$web");
209
210 print "$web\n";
211 rizwank 1.1
212 if (!-f "$targetDir/data/$web/WebLeftBar.txt")
213 {
214 copy("data/TWiki/WebLeftBarExample.txt", "$targetDir/data/$web/WebLeftBar.txt")
215 or warn "Couldn't put the default WebLeftBar.txt (from data/TWiki/WebLeftBarExample.txt) into $targetDir/data/$web/WebLeftBar.txt: $!\n";
216 }
217 else
218 {
219 print "(already has one)\n";
220 }
221
222 if (!-f "$targetDir/data/$web/WebSearchAdvanced.txt")
223 {
224 open(WSA, ">$targetDir/data/$web/WebSearchAdvanced.txt");
225 print WSA '%INCLUDE{"%TWIKIWEB%.WebSearchAdvanced"}%'."\n";
226 close WSA;
227 }
228 }
229 }
230 else
231 {
232 rizwank 1.1 warn "Hmmm - was going to add default WebLeftBar topics for you, but couldn't open $targetDir/data: $! !\n";
233 }
234 }
235 else
236 {
237 warn "Hmmm - I was going to give all your webs a default WebLeftBar topic, but TWiki.WebLeftBarExample doesn't seem to be present in your distribution folders. Your new twiki will still work, but check the 'UpgradeGuide' topic at twiki.org for information that might help explain this problem.\n"
238 }
239
240 # At last!
241
242 print "
243 Congratulations... you made it this far!
244
245 ";
246
247 print "
248
249 Now: you need to
250
251 - Check the files listed above (if any) who's patches were rejected.
252
253 rizwank 1.1 For these files, you'll want to check the .rej file (in the same directory as the file)
254 and see whether there are changes in there that you need to make manually.
255
256 - Check the files list above that have 'no common versions' - in those cases, your
257 new install will still work, but you need to be aware the topic file that is in
258 place is your old one... no changes from the new release have been included.
259
260 - Check if you modified your old version of setlib.cfg: if you did,
261 then you need to do the same to the new one (which you will find in ./bin).
262
263 (There are only two reasons I can think of why you might have done that:
264 1) You wanted to workaround the Apache2 hang bug or
265 2) You needed to point to a local perl library for some reason. )
266
267 - Setup authentication for the new TWiki
268
269 If you are using htaccess, then check the diffs above make sense.
270 If you are using some other method, you'll need to figure out what you need to do (sorry!)
271
272 - Set the permissions appropriately for the new TWiki.
273
274 rizwank 1.1 I have given pub and data global read and write access, so your new TWiki
275 will work, but you might want tighter controls.
276
277 - If you are one of the few people who modified \@storeSettings, then you need to
278 look in TWiki.cfg and see if you need to make changes (I installed new the default ones)
279
280 If you don't know what this means, it probably doesn't apply to you.
281
282 - Re-install plugins you were using
283
284 - Copy over custom templates you put in the original templates directory
285
286 - anything else I haven't thought of
287
288 - Archive your old installation
289
290 - Move the newly created twiki directory ($targetDir) to the place where your previous version was.
291
292 - Rearrange sub-directories the way you like them, if needed.
293 (some sites have bin in a very different place to the rest, for example)
294
295 rizwank 1.1 - Use your browser to check the whole thing: visit the 'testenv' script, which I am guessing is at:
296
297 $TWikiCfg::defaultUrlHost$TWikiCfg::scriptUrlPath/testenv$TWikiCfg::scriptSuffix
298
299 make sure there are no unwarranted warnings, and press the 'relockrcs' button if advised to do so,
300
301 and finally: visit TWikiPreferences, which I'm guessing is at:
302
303 $TWikiCfg::defaultUrlHost$TWikiCfg::scriptUrlPath/view$TWikiCfg::scriptSuffix/TWiki/TWikiPreferences
304
305 ... it should be working, and you can edit the new WIKIWEBMASTER setting!
306
307 Goodluck... :-)
308 ";
|