| 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 |
|---|
| 24 | print <<END; |
|---|
| 25 | Welcome. This script creates a game directory for a MUSH and |
|---|
| 26 | customizes the files in order to make running multiple MUSHes |
|---|
| 27 | easier. This is still experimental, but should not affect |
|---|
| 28 | any of your files in standard MUSH directories (game, src, hdrs, etc.) |
|---|
| 29 | |
|---|
| 30 | When choosing the name for your directory, use a short version of |
|---|
| 31 | the MUSH name. For example, if you MUSH was called Fallen Angels MUSH, |
|---|
| 32 | you might choose 'fallen' or 'fa'. Use only upper- or lower-case |
|---|
| 33 | letters and numbers in directory names. |
|---|
| 34 | |
|---|
| 35 | END |
|---|
| 36 | |
|---|
| 37 | print "Please enter the name for your directory: "; |
|---|
| 38 | chop($targetdir = <STDIN>); |
|---|
| 39 | |
|---|
| 40 | # Verify that the target directory isn't an unwritable one, or |
|---|
| 41 | # a tricky one. |
|---|
| 42 | |
|---|
| 43 | $targetdir =~ s/ +//g; |
|---|
| 44 | die "Invalid directory: contains a bad character.\n" |
|---|
| 45 | if ($targetdir =~ /[^A-Za-z0-9_]/); |
|---|
| 46 | foreach (@dontwrite) { |
|---|
| 47 | die "Invalid directory: already in use\n" if ($targetdir eq $_); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | # Does the directory already exist? |
|---|
| 51 | if (-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 | |
|---|
| 62 | print "Making $targetdir..."; |
|---|
| 63 | mkdir($targetdir,0755) unless (-d $targetdir); |
|---|
| 64 | die "Failed!\n" unless (-d $targetdir); |
|---|
| 65 | print "done.\n"; |
|---|
| 66 | |
|---|
| 67 | print "Using tar to copy from game/ to $targetdir/..."; |
|---|
| 68 | $tar = $tar1 . $targetdir . $tar2; |
|---|
| 69 | if (system($tar)) { |
|---|
| 70 | die "Failed!\n"; |
|---|
| 71 | } |
|---|
| 72 | print "done.\n"; |
|---|
| 73 | |
|---|
| 74 | print "Replacing standard files in $targetdir/txt/hlp with\nlinks to files in game/txt/hlp..."; |
|---|
| 75 | chop($curdir = `pwd`); |
|---|
| 76 | foreach $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 | } |
|---|
| 81 | print "done.\n"; |
|---|
| 82 | |
|---|
| 83 | # Enter the directory, and, produce some files |
|---|
| 84 | chdir($targetdir); |
|---|
| 85 | chop($fullpath = `pwd`); |
|---|
| 86 | |
|---|
| 87 | print "Modifying mush.cnf (to $targetdir.cnf)..."; |
|---|
| 88 | unless (open(IN,"mush.cnf") && open(OUT,">$targetdir.cnf")) { |
|---|
| 89 | die "Failed!\n"; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | while (<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 | } |
|---|
| 107 | close(IN); close(OUT); |
|---|
| 108 | print "done\n"; |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | print "Modifying restart (to $targetdir.restart)..."; |
|---|
| 112 | unless (open(IN,"restart") && open(OUT,">$targetdir.restart")) { |
|---|
| 113 | die "Failed!\n"; |
|---|
| 114 | } |
|---|
| 115 | while (<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 | } |
|---|
| 126 | close(IN); close(OUT); |
|---|
| 127 | chmod(0744,"$targetdir.restart"); |
|---|
| 128 | print "done\n"; |
|---|
| 129 | |
|---|
| 130 | print "Renaming data/minimal.db.Z to data/indb.$targetdir.Z..."; |
|---|
| 131 | rename("data/minimal.db.Z","data/indb.$targetdir.Z"); |
|---|
| 132 | print "done.\n"; |
|---|
| 133 | |
|---|
| 134 | print "Removing old mush.cnf and restart script..."; |
|---|
| 135 | unlink("mush.cnf"); |
|---|
| 136 | unlink("restart"); |
|---|
| 137 | print "done\n"; |
|---|
| 138 | |
|---|
| 139 | print "Fixing links..."; |
|---|
| 140 | symlink("../src/netmud","netmush"); |
|---|
| 141 | symlink("../src/info_slave","info_slave"); |
|---|
| 142 | print "done\n"; |
|---|
| 143 | |
|---|
| 144 | chdir(".."); |
|---|
| 145 | |
|---|
| 146 | print "Customization complete for $targetdir/\n"; |
|---|
| 147 | |
|---|
| 148 | exit 0; |
|---|