root/1.8.3/tags/p6/utils/customize.pl

Revision 335, 4.0 KB (checked in by pennmush, 2 years ago)

PennMUSH 1.7.5p0 Archival

  • Property svn:executable set to *
Line 
1#!/usr/local/bin/perl
2#
3# If this script doesn't work for you, try changing the first line
4# to point to the location of Perl on your system. That shouldn't
5# be necessary if you're running it via 'make customize'
6#
7# customize.pl - Alan Schwartz <dunemush@pennmush.org>
8#
9# This script asks the user for a mush name and makes a copy of the
10# game/ directory called <mush>/. It also rewrites the restart script
11# to <mush>.restart and mush.cnf (which it calls <mush>.cnf) to
12# make it easier to keep track of multiple MUSHes.
13#
14# $Id: customize.pl 1.2 Tue, 09 Jan 2001 17:56:37 -0600 dunemush $
15#
16
17$tar1="(cd game; tar cf - .) | (cd ";
18$tar2="; tar xfBp -)";
19
20@dontwrite = ("src","hdrs","hints","game");
21
22
23# Interact with the user
24print <<END;
25Welcome. This script creates a game directory for a MUSH and 
26customizes the files in order to make running multiple MUSHes
27easier. This is still experimental, but should not affect
28any of your files in standard MUSH directories (game, src, hdrs, etc.)
29
30When choosing the name for your directory, use a short version of
31the MUSH name. For example, if you MUSH was called Fallen Angels MUSH,
32you might choose 'fallen' or 'fa'. Use only upper- or lower-case
33letters and numbers in directory names.
34
35END
36
37print "Please enter the name for your directory: ";
38chop($targetdir = <STDIN>);
39
40# Verify that the target directory isn't an unwritable one, or
41# a tricky one.
42
43$targetdir =~ s/ +//g;
44die "Invalid directory: contains a bad character.\n"
45     if ($targetdir =~ /[^A-Za-z0-9_]/);
46foreach (@dontwrite) {
47  die "Invalid directory: already in use\n" if ($targetdir eq $_);
48}
49
50# Does the directory already exist?
51if (-d $targetdir) {
52  print "That directory already exists. Overwrite it? [n] ";
53  $yn = <STDIN>;
54  unless ($yn =~ /^[yY]/) {
55    exit 0;
56  }
57}
58
59# Ok, go ahead and create it. We probably should trap signals so
60# we can clean up, too.
61
62print "Making $targetdir...";
63mkdir($targetdir,0755) unless (-d $targetdir);
64die "Failed!\n" unless (-d $targetdir);
65print "done.\n";
66
67print "Using tar to copy from game/ to $targetdir/...";
68$tar = $tar1 . $targetdir . $tar2;
69if (system($tar)) {
70    die "Failed!\n";
71}
72print "done.\n";
73
74print "Replacing standard files in $targetdir/txt/hlp with\nlinks to files in game/txt/hlp...";
75chop($curdir = `pwd`);
76foreach $file (<$targetdir/txt/hlp/penn*.hlp>) {
77  unlink($file) || die "Failed!\n";
78  ($newfile) = $file =~ /(penn.*\.hlp)/;
79  symlink("$curdir/game/txt/hlp/$newfile","$targetdir/txt/hlp/$newfile") || die "Failed!\n";
80}
81print "done.\n";
82
83# Enter the directory, and, produce some files
84chdir($targetdir);
85chop($fullpath = `pwd`);
86
87print "Modifying mush.cnf (to $targetdir.cnf)...";
88unless (open(IN,"mush.cnf") && open(OUT,">$targetdir.cnf")) {
89    die "Failed!\n";
90}
91
92while (<IN>) {
93  if (/^mud_name/) {
94    print OUT "mud_name $targetdir\n";
95  } elsif (/^input_database/) {
96    print OUT "input_database data/indb.$targetdir\n";
97  } elsif (/^output_database/) {
98    print OUT "output_database data/outdb.$targetdir\n";
99  } elsif (/^mail_database/) {
100    print OUT "mail_database data/maildb.$targetdir\n";
101  } elsif (/^chat_database/) {
102    print OUT "chat_database data/chatdb.$targetdir\n";
103  } else {
104    print OUT $_;
105  }
106}
107close(IN); close(OUT);
108print "done\n";
109
110
111print "Modifying restart (to $targetdir.restart)...";
112unless (open(IN,"restart") && open(OUT,">$targetdir.restart")) {
113    die "Failed!\n";
114}
115while (<IN>) {
116  if (/^GAMEDIR/) {
117    print OUT "GAMEDIR=$fullpath\n";
118  } elsif (/^CONF_FILE/) {
119    print OUT "CONF_FILE=$targetdir.cnf\n";
120  } elsif (/^LOG/) {
121    print OUT "LOG=log/$targetdir.log\n";
122  } else {
123    print OUT $_;
124  }
125}
126close(IN); close(OUT);
127chmod(0744,"$targetdir.restart");
128print "done\n";
129
130print "Renaming data/minimal.db.Z to data/indb.$targetdir.Z...";
131rename("data/minimal.db.Z","data/indb.$targetdir.Z");
132print "done.\n";
133
134print "Removing old mush.cnf and restart script...";
135unlink("mush.cnf");
136unlink("restart");
137print "done\n";
138
139print "Fixing links...";
140symlink("../src/netmud","netmush");
141symlink("../src/info_slave","info_slave");
142print "done\n";
143
144chdir("..");
145
146print "Customization complete for $targetdir/\n";
147
148exit 0;
Note: See TracBrowser for help on using the browser.